Skip to content

Commit ccdc4b0

Browse files
gabrieldemarmiesseWindQAQ
authored andcommitted
Removing unused imports, cells and __future__ from the notebooks. (#908)
* Edit the template notebook. * Cleaned up other notebooks. * Removed empty cell. * Clean up of the notebooks. * Moved imports.
1 parent 11b8427 commit ccdc4b0

10 files changed

+16
-196
lines changed

docs/tutorials/_template.ipynb

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
" <a target=\"_blank\" href=\"https://www.tensorflow.org/addons/tutorials/image_ops\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
5757
" </td>\n",
5858
" <td>\n",
59-
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
59+
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/_template.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
6060
" </td>\n",
6161
" <td>\n",
62-
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
62+
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/_template.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
6363
" </td>\n",
6464
" <td>\n",
6565
" <a href=\"https://storage.googleapis.com/tensorflow_docs/docs/docs/tutorials/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" />Download notebook</a>\n",
@@ -109,19 +109,6 @@
109109
"[Put all your imports and installs up into a setup section.]"
110110
]
111111
},
112-
{
113-
"cell_type": "code",
114-
"execution_count": 1,
115-
"metadata": {
116-
"colab": {},
117-
"colab_type": "code",
118-
"id": "8n8UUkG9rx68"
119-
},
120-
"outputs": [],
121-
"source": [
122-
"from __future__ import absolute_import, division, print_function, unicode_literals"
123-
]
124-
},
125112
{
126113
"cell_type": "code",
127114
"execution_count": 2,
@@ -154,7 +141,7 @@
154141
}
155142
],
156143
"source": [
157-
"!pip install --no-deps tensorflow-addons~=0.6"
144+
"!pip install --no-deps tensorflow-addons~=0.7"
158145
]
159146
},
160147
{
@@ -195,9 +182,8 @@
195182
"* Include the button-bar immediately after the `H1`.\n",
196183
"* Include an overview section before any code.\n",
197184
"* Put all your installs and imports in a setup section.\n",
198-
"* Always include the `__future__` imports.\n",
199-
"* Write Python 3 compatible code.\n",
200-
"* Keep code and text cells as brief as posssible.\n",
185+
"* Write Python 3 compatible code. You don't have to worry about Python 2 compatibility.\n",
186+
"* Keep code and text cells as brief as possible.\n",
201187
"* Avoid leaving an empty cell at the end of the notebook."
202188
]
203189
},
@@ -252,6 +238,8 @@
252238
},
253239
"outputs": [],
254240
"source": [
241+
"import numpy as np\n",
242+
"\n",
255243
"result = model(tf.constant(np.random.randn(10,5), dtype = tf.float32)).numpy()\n",
256244
"\n",
257245
"print(\"min:\", result.min())\n",

docs/tutorials/image_ops.ipynb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,6 @@
123123
"# Setup"
124124
]
125125
},
126-
{
127-
"cell_type": "code",
128-
"metadata": {
129-
"colab_type": "code",
130-
"id": "ou0vRZKPWh4X",
131-
"colab": {}
132-
},
133-
"source": [
134-
"from __future__ import absolute_import, division, print_function, unicode_literals"
135-
],
136-
"execution_count": 0,
137-
"outputs": []
138-
},
139126
{
140127
"cell_type": "code",
141128
"metadata": {

docs/tutorials/layers_normalizations.ipynb

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,6 @@
122122
"### Install Tensorflow 2.0 and Tensorflow-Addons"
123123
]
124124
},
125-
{
126-
"cell_type": "code",
127-
"execution_count": null,
128-
"metadata": {
129-
"colab": {},
130-
"colab_type": "code",
131-
"id": "AOExuXLZSZNE"
132-
},
133-
"outputs": [],
134-
"source": [
135-
"from __future__ import absolute_import, division, print_function"
136-
]
137-
},
138125
{
139126
"cell_type": "code",
140127
"execution_count": null,
@@ -301,10 +288,10 @@
301288
" tf.keras.layers.Conv2D(filters=10, kernel_size=(3,3),data_format=\"channels_last\"),\n",
302289
" # LayerNorm Layer\n",
303290
" tfa.layers.InstanceNormalization(axis=3, \n",
304-
" center=True, \n",
305-
" scale=True,\n",
306-
" beta_initializer=\"random_uniform\",\n",
307-
" gamma_initializer=\"random_uniform\"),\n",
291+
" center=True, \n",
292+
" scale=True,\n",
293+
" beta_initializer=\"random_uniform\",\n",
294+
" gamma_initializer=\"random_uniform\"),\n",
308295
" tf.keras.layers.Flatten(),\n",
309296
" tf.keras.layers.Dense(128, activation='relu'),\n",
310297
" tf.keras.layers.Dropout(0.2),\n",

docs/tutorials/layers_weightnormalization.ipynb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,6 @@
102102
"## Setup"
103103
]
104104
},
105-
{
106-
"cell_type": "code",
107-
"execution_count": null,
108-
"metadata": {
109-
"colab": {},
110-
"colab_type": "code",
111-
"id": "IqR2PQG4ZaZ0"
112-
},
113-
"outputs": [],
114-
"source": [
115-
"from __future__ import absolute_import, division, print_function, unicode_literals"
116-
]
117-
},
118105
{
119106
"cell_type": "code",
120107
"execution_count": null,

docs/tutorials/losses_triplet.ipynb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,6 @@
144144
"## Setup"
145145
]
146146
},
147-
{
148-
"cell_type": "code",
149-
"metadata": {
150-
"colab_type": "code",
151-
"id": "Bv-CVfbzYblP",
152-
"colab": {}
153-
},
154-
"source": [
155-
"from __future__ import absolute_import, division, print_function, unicode_literals"
156-
],
157-
"execution_count": 0,
158-
"outputs": []
159-
},
160147
{
161148
"cell_type": "code",
162149
"metadata": {
@@ -212,8 +199,7 @@
212199
},
213200
"source": [
214201
"import tensorflow_addons as tfa\n",
215-
"import tensorflow_datasets as tfds\n",
216-
"from matplotlib import pyplot as plt"
202+
"import tensorflow_datasets as tfds",
217203
],
218204
"execution_count": 0,
219205
"outputs": []
@@ -401,19 +387,6 @@
401387
"You can see the results of our embedded test data when visualized with UMAP:\n",
402388
"![embedding](https://user-images.githubusercontent.com/18154355/61600295-e6470380-abfd-11e9-8a00-2b25e7e6916f.png)\n"
403389
]
404-
},
405-
{
406-
"cell_type": "code",
407-
"metadata": {
408-
"colab_type": "code",
409-
"id": "MuaB5oD5t1YV",
410-
"colab": {}
411-
},
412-
"source": [
413-
""
414-
],
415-
"execution_count": 0,
416-
"outputs": []
417390
}
418391
]
419392
}

docs/tutorials/networks_seq2seq_nmt.ipynb

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,6 @@
108108
"# **Setup**"
109109
]
110110
},
111-
{
112-
"cell_type": "code",
113-
"metadata": {
114-
"colab_type": "code",
115-
"id": "1bUHYPhlF-Ql",
116-
"colab": {}
117-
},
118-
"source": [
119-
"from __future__ import absolute_import, division, print_function, unicode_literals"
120-
],
121-
"execution_count": 0,
122-
"outputs": []
123-
},
124111
{
125112
"cell_type": "code",
126113
"metadata": {
@@ -134,9 +121,7 @@
134121
"except:\n",
135122
" pass\n",
136123
"!pip install -q --no-deps tensorflow-addons~=0.7\n",
137-
"!pip install nltk\n",
138-
"import tensorflow as tf\n",
139-
"import tensorflow_addons as tfa"
124+
"!pip install nltk"
140125
],
141126
"execution_count": 0,
142127
"outputs": []
@@ -186,13 +171,10 @@
186171
"colab": {}
187172
},
188173
"source": [
189-
"import csv\n",
190174
"import string\n",
191175
"import re\n",
192-
"from pickle import dump\n",
176+
"from pickle import load\n",
193177
"from unicodedata import normalize\n",
194-
"from numpy import array\n",
195-
"from pickle import load\n",
196178
"from tensorflow.keras.preprocessing.text import Tokenizer\n",
197179
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
198180
"from tensorflow.keras.utils import to_categorical\n",
@@ -203,9 +185,9 @@
203185
"from tensorflow.keras.layers import RepeatVector\n",
204186
"from tensorflow.keras.layers import TimeDistributed\n",
205187
"from tensorflow.keras.callbacks import ModelCheckpoint\n",
206-
"from pickle import load\n",
207188
"from numpy import array\n",
208189
"from numpy import argmax\n",
190+
"from numpy.random import shuffle\n",
209191
"from nltk.translate.bleu_score import corpus_bleu"
210192
],
211193
"execution_count": 0,
@@ -329,11 +311,6 @@
329311
"colab": {}
330312
},
331313
"source": [
332-
"from pickle import load\n",
333-
"from pickle import dump\n",
334-
"from numpy.random import rand\n",
335-
"from numpy.random import shuffle\n",
336-
" \n",
337314
"# load a clean dataset\n",
338315
"def load_clean_sentences(filename):\n",
339316
"\treturn load(open(filename, 'rb'))\n",
@@ -592,19 +569,6 @@
592569
"execution_count": 0,
593570
"outputs": []
594571
},
595-
{
596-
"cell_type": "code",
597-
"metadata": {
598-
"colab_type": "code",
599-
"id": "sp3trjITtq95",
600-
"colab": {}
601-
},
602-
"source": [
603-
""
604-
],
605-
"execution_count": 0,
606-
"outputs": []
607-
},
608572
{
609573
"cell_type": "markdown",
610574
"metadata": {

docs/tutorials/optimizers_conditionalgradient.ipynb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,6 @@
107107
"## Setup"
108108
]
109109
},
110-
{
111-
"cell_type": "code",
112-
"metadata": {
113-
"id": "Pc8HQET2O5KK",
114-
"colab_type": "code",
115-
"colab": {}
116-
},
117-
"source": [
118-
"from __future__ import absolute_import, division, print_function, unicode_literals"
119-
],
120-
"execution_count": 0,
121-
"outputs": []
122-
},
123110
{
124111
"cell_type": "code",
125112
"metadata": {
@@ -184,8 +171,6 @@
184171
},
185172
"source": [
186173
"import tensorflow_addons as tfa\n",
187-
"import tensorflow_datasets as tfds\n",
188-
"import numpy as np\n",
189174
"from matplotlib import pyplot as plt"
190175
],
191176
"execution_count": 0,

docs/tutorials/optimizers_lazyadam.ipynb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,6 @@
103103
"## Setup"
104104
]
105105
},
106-
{
107-
"cell_type": "code",
108-
"execution_count": null,
109-
"metadata": {
110-
"colab": {},
111-
"colab_type": "code",
112-
"id": "fqySbdXSZdyW"
113-
},
114-
"outputs": [],
115-
"source": [
116-
"from __future__ import absolute_import, division, print_function, unicode_literals"
117-
]
118-
},
119106
{
120107
"cell_type": "code",
121108
"execution_count": null,
@@ -165,10 +152,7 @@
165152
},
166153
"outputs": [],
167154
"source": [
168-
"import tensorflow_addons as tfa\n",
169-
"import tensorflow_datasets as tfds\n",
170-
"import numpy as np\n",
171-
"from matplotlib import pyplot as plt"
155+
"import tensorflow_addons as tfa",
172156
]
173157
},
174158
{
@@ -306,17 +290,6 @@
306290
"results = model.evaluate(x_test, y_test, batch_size=128, verbose = 2)\n",
307291
"print('Test loss = {0}, Test acc: {1}'.format(results[0], results[1]))"
308292
]
309-
},
310-
{
311-
"cell_type": "code",
312-
"execution_count": null,
313-
"metadata": {
314-
"colab": {},
315-
"colab_type": "code",
316-
"id": "2GxntWdAbJUv"
317-
},
318-
"outputs": [],
319-
"source": []
320293
}
321294
],
322295
"metadata": {

docs/tutorials/time_stopping.ipynb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@
9696
"metadata": {},
9797
"outputs": [],
9898
"source": [
99-
"import tensorflow as tf\n",
10099
"import tensorflow_addons as tfa\n",
101100
"\n",
102-
"import tensorflow.keras as keras\n",
103101
"from tensorflow.keras.datasets import mnist\n",
104102
"from tensorflow.keras.models import Sequential\n",
105103
"from tensorflow.keras.layers import Dense, Dropout, Flatten"
@@ -203,13 +201,6 @@
203201
" callbacks=[time_stopping_callback],\n",
204202
" validation_data=(x_test, y_test))"
205203
]
206-
},
207-
{
208-
"cell_type": "code",
209-
"execution_count": null,
210-
"metadata": {},
211-
"outputs": [],
212-
"source": []
213204
}
214205
],
215206
"metadata": {

0 commit comments

Comments
 (0)