Skip to content

Commit 2b1eff3

Browse files
authored
Update binder config (#129)
* Fixing requirements for binder build * Remove (hopefully) unnecessary dependency * Add big packages back in * Add BERT download to image prep * Remove unnecessary dependencies from conda config * Add missing import * Update instructions for setting up credentials on binder/colab/watson studio * Adjust kernel settings and rerun
1 parent e525997 commit 2b1eff3

11 files changed

+313
-277
lines changed

binder/download_bert.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# download_bert.py
3+
#
4+
# Post-build script to download and cache a BERT model so that
5+
# Model_Training_with_BERT.ipynb won't run of disk space.
6+
7+
import transformers
8+
9+
bert_model_name = "dslim/bert-base-NER"
10+
bert = transformers.BertModel.from_pretrained(bert_model_name)
11+

binder/postBuild

+18
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,27 @@
33
# Log commands
44
set -ex
55

6+
# Not sure why we need this here.
7+
pip install -r requirements.txt
8+
69
# Install additional packages beyond those in requirements.txt so that the
710
# JupyterLab instance will be able to run all of the NLP library integrations.
811
pip install -r config/dev_reqs.txt
912
pip install -r config/jupyter_reqs.txt
1013

14+
# Install large packages during image build for now.
15+
# Later we may want to have the notebooks install these on demand if they
16+
# detect they are running in a Binder environment.
17+
# Note that transformers will start up in a bad state if it detects no PyTorch
18+
# and will stay in that state until Python is restarted.
19+
pip install -r config/big_reqs.txt
20+
21+
# Download the language model needed by Integrate_NLP_Libraries.ipynb
22+
# We can't download this package from within the notebook unless the user
23+
# restarts the kernel after the download.
24+
python -m spacy download en_core_web_sm
25+
26+
# Also download the BERT model used by Model_Training_with_BERT.ipynb so that
27+
# the production environment won't run out of disk space.
28+
python ./binder/download_bert.py
1129

config/big_reqs.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# big_reqs.txt
2+
# Large packages that are required by a small fraction of our demo
3+
# material.
4+
scikit-learn
5+
torch
6+

config/dev_env.yml

-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,5 @@
33
channels:
44
- defaults
55
dependencies:
6-
- tensorflow
7-
- pandas
8-
- regex
9-
- matplotlib
10-
- cython
11-
- grpcio-tools
12-
- pytorch
13-
- black
14-
- scikit-learn
156

167

config/dev_reqs.txt

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pyyaml
88
transformers>=3.0.0
99
# SpaCy models aren't stable across point releases
1010
spacy==2.3.2
11-
fastparquet
1211
sphinx
1312
sphinxcontrib-apidoc
1413
ipywidgets

config/jupyter_reqs.txt

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ jupyterlab
55
nodejs
66
xeus-python
77
ipywidgets
8-
scikit-learn
9-
torch
108
matplotlib
119

env.sh

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ pip install -r config/dev_reqs.txt
8080
# Additional layer of pip-installed stuff for running notebooks
8181
pip install -r config/jupyter_reqs.txt
8282

83+
# Additional large packages needed by only some of the demos
84+
pip install -r config/big_reqs.txt
85+
8386
################################################################################
8487
# Least-preferred install method: Custom
8588

notebooks/Analyze_Text.ipynb

+8-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
" jupyter lab\n",
9797
"```\n",
9898
"\n",
99-
"Alternately, you can modify the code below to set the variables `api_key` and `service_url` directly.\n",
99+
"Alternately, you can uncomment the first two lines of code below to set the `IBM_API_KEY` and `IBM_SERVICE_URL` environment variables directly.\n",
100100
"**Be careful not to store your API key in any publicly-accessible location!**"
101101
]
102102
},
@@ -106,6 +106,11 @@
106106
"metadata": {},
107107
"outputs": [],
108108
"source": [
109+
"# If you need to embed your credentials inline, uncomment the following two lines and\n",
110+
"# paste your credentials in the indicated locations.\n",
111+
"# os.environ[\"IBM_API_KEY\"] = \"<API key goes here>\"\n",
112+
"# os.environ[\"IBM_SERVICE_URL\"] = \"<Service URL goes here>\"\n",
113+
"\n",
109114
"# Retrieve the API key for your Watson NLU service instance\n",
110115
"if \"IBM_API_KEY\" not in os.environ:\n",
111116
" raise ValueError(\"Expected Watson NLU api key in the environment variable 'IBM_API_KEY'\")\n",
@@ -138,7 +143,7 @@
138143
{
139144
"data": {
140145
"text/plain": [
141-
"<ibm_watson.natural_language_understanding_v1.NaturalLanguageUnderstandingV1 at 0x7fc092cc1e90>"
146+
"<ibm_watson.natural_language_understanding_v1.NaturalLanguageUnderstandingV1 at 0x7ffa4f50ed10>"
142147
]
143148
},
144149
"execution_count": 3,
@@ -2857,7 +2862,7 @@
28572862
"name": "python",
28582863
"nbconvert_exporter": "python",
28592864
"pygments_lexer": "ipython3",
2860-
"version": "3.7.7"
2865+
"version": "3.7.9"
28612866
}
28622867
},
28632868
"nbformat": 4,

notebooks/Integrate_NLP_Libraries.ipynb

+69-63
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)