Skip to content

Commit bcb3634

Browse files
Merge pull request #11 from joaogui1:tutorial-gpu
PiperOrigin-RevId: 268124504
2 parents 49ac3eb + af9f30f commit bcb3634

File tree

3 files changed

+88
-46
lines changed

3 files changed

+88
-46
lines changed

g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@
5151
"id": "wfqlePz0g6o5"
5252
},
5353
"source": [
54-
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
55-
" \u003ctd\u003e\n",
56-
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/adversarial_keras_cnn_mnist\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
57-
" \u003c/td\u003e\n",
58-
" \u003ctd\u003e\n",
59-
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
60-
" \u003c/td\u003e\n",
61-
" \u003ctd\u003e\n",
62-
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
63-
" \u003c/td\u003e\n",
64-
"\u003c/table\u003e"
54+
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
55+
" <td>\n",
56+
" <a target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/adversarial_keras_cnn_mnist\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
57+
" </td>\n",
58+
" <td>\n",
59+
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
60+
" </td>\n",
61+
" <td>\n",
62+
" <a target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/adversarial_keras_cnn_mnist.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
63+
" </td>\n",
64+
"</table>"
6565
]
6666
},
6767
{
@@ -129,7 +129,7 @@
129129
},
130130
"outputs": [],
131131
"source": [
132-
"!pip install tensorflow==2.0.0-rc0"
132+
"!pip install tensorflow-gpu==2.0.0-rc0"
133133
]
134134
},
135135
{
@@ -376,7 +376,7 @@
376376
" x = tf.keras.layers.Conv2D(\n",
377377
" num_filters, hparams.kernel_size, activation='relu')(\n",
378378
" x)\n",
379-
" if i \u003c len(hparams.conv_filters) - 1:\n",
379+
" if i < len(hparams.conv_filters) - 1:\n",
380380
" # max pooling between convolutional layers\n",
381381
" x = tf.keras.layers.MaxPooling2D(hparams.pool_size)(x)\n",
382382
" x = tf.keras.layers.Flatten()(x)\n",
@@ -785,6 +785,7 @@
785785
}
786786
],
787787
"metadata": {
788+
"accelerator": "GPU",
788789
"colab": {
789790
"collapsed_sections": [],
790791
"last_runtime": {
@@ -804,7 +805,20 @@
804805
},
805806
"kernelspec": {
806807
"display_name": "Python 3",
808+
"language": "python",
807809
"name": "python3"
810+
},
811+
"language_info": {
812+
"codemirror_mode": {
813+
"name": "ipython",
814+
"version": 3
815+
},
816+
"file_extension": ".py",
817+
"mimetype": "text/x-python",
818+
"name": "python",
819+
"nbconvert_exporter": "python",
820+
"pygments_lexer": "ipython3",
821+
"version": "3.7.3"
808822
}
809823
},
810824
"nbformat": 4,

g3doc/tutorials/graph_keras_lstm_imdb.ipynb

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
"source": [
4444
"# Graph regularization for sentiment classification using synthesized graphs\n",
4545
"\n",
46-
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
47-
" \u003ctd\u003e\n",
48-
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_lstm_imdb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
49-
" \u003c/td\u003e\n",
50-
" \u003ctd\u003e\n",
51-
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_lstm_imdb.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
52-
" \u003c/td\u003e\n",
53-
" \u003ctd\u003e\n",
54-
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_lstm_imdb.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
55-
" \u003c/td\u003e\n",
56-
"\u003c/table\u003e"
46+
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
47+
" <td>\n",
48+
" <a target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_lstm_imdb\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
49+
" </td>\n",
50+
" <td>\n",
51+
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_lstm_imdb.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
52+
" </td>\n",
53+
" <td>\n",
54+
" <a target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_lstm_imdb.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
55+
" </td>\n",
56+
"</table>"
5757
]
5858
},
5959
{
@@ -129,7 +129,7 @@
129129
},
130130
"outputs": [],
131131
"source": [
132-
"!pip install --quiet tensorflow==2.0.0-rc0\n",
132+
"!pip install --quiet tensorflow-gpu==2.0.0-rc0\n",
133133
"!pip install --quiet neural-structured-learning\n",
134134
"!pip install --quiet tensorflow-hub"
135135
]
@@ -344,10 +344,10 @@
344344
"\n",
345345
" # The first indices are reserved\n",
346346
" word_index = {k: (v + 3) for k, v in word_index.items()}\n",
347-
" word_index['\u003cPAD\u003e'] = 0\n",
348-
" word_index['\u003cSTART\u003e'] = 1\n",
349-
" word_index['\u003cUNK\u003e'] = 2 # unknown\n",
350-
" word_index['\u003cUNUSED\u003e'] = 3\n",
347+
" word_index['<PAD>'] = 0\n",
348+
" word_index['<START>'] = 1\n",
349+
" word_index['<UNK>'] = 2 # unknown\n",
350+
" word_index['<UNUSED>'] = 3\n",
351351
" return dict((value, key) for (key, value) in word_index.items())\n",
352352
"\n",
353353
"reverse_word_index = build_reverse_word_index()\n",
@@ -774,11 +774,11 @@
774774
"source": [
775775
"### Prepare the data\n",
776776
"\n",
777-
"The reviews—the arrays of integers—must be converted to tensors before being fed\n",
777+
"The reviews\u2014the arrays of integers\u2014must be converted to tensors before being fed\n",
778778
"into the neural network. This conversion can be done a couple of ways:\n",
779779
"\n",
780780
"* Convert the arrays into vectors of `0`s and `1`s indicating word occurrence,\n",
781-
" similar to a one-hot encoding. For example, the sequence `[3, 5]` would become a `10000`-dimensional vector that is all zeros except for indices `3` and `5`, which are ones. Then, make this the first layer in our network—a `Dense` layer—that can handle floating point vector data. This approach is memory intensive, though, requiring a `num_words * num_reviews` size matrix.\n",
781+
" similar to a one-hot encoding. For example, the sequence `[3, 5]` would become a `10000`-dimensional vector that is all zeros except for indices `3` and `5`, which are ones. Then, make this the first layer in our network\u2014a `Dense` layer\u2014that can handle floating point vector data. This approach is memory intensive, though, requiring a `num_words * num_reviews` size matrix.\n",
782782
"\n",
783783
"* Alternatively, we can pad the arrays so they all have the same length, then\n",
784784
" create an integer tensor of shape `max_length * num_reviews`. We can use an\n",
@@ -885,7 +885,7 @@
885885
"source": [
886886
"### Build the model\n",
887887
"\n",
888-
"A neural network is created by stacking layers—this requires two main architectural decisions:\n",
888+
"A neural network is created by stacking layers\u2014this requires two main architectural decisions:\n",
889889
"\n",
890890
"* How many layers to use in the model?\n",
891891
"* How many *hidden units* to use for each layer?\n",
@@ -982,7 +982,7 @@
982982
"If a model has more hidden units (a higher-dimensional representation space),\n",
983983
"and/or more layers, then the network can learn more complex representations.\n",
984984
"However, it makes the network more computationally expensive and may lead to\n",
985-
"learning unwanted patterns—patterns that improve performance on training data\n",
985+
"learning unwanted patterns\u2014patterns that improve performance on training data\n",
986986
"but not on the test data. This is called *overfitting*."
987987
]
988988
},
@@ -1204,7 +1204,7 @@
12041204
"source": [
12051205
"Notice the training loss *decreases* with each epoch and the training accuracy\n",
12061206
"*increases* with each epoch. This is expected when using a gradient descent\n",
1207-
"optimization—it should minimize the desired quantity on every iteration."
1207+
"optimization\u2014it should minimize the desired quantity on every iteration."
12081208
]
12091209
},
12101210
{
@@ -1533,6 +1533,7 @@
15331533
}
15341534
],
15351535
"metadata": {
1536+
"accelerator": "GPU",
15361537
"colab": {
15371538
"collapsed_sections": [
15381539
"24gYiJcWNlpA"
@@ -1554,7 +1555,20 @@
15541555
},
15551556
"kernelspec": {
15561557
"display_name": "Python 3",
1558+
"language": "python",
15571559
"name": "python3"
1560+
},
1561+
"language_info": {
1562+
"codemirror_mode": {
1563+
"name": "ipython",
1564+
"version": 3
1565+
},
1566+
"file_extension": ".py",
1567+
"mimetype": "text/x-python",
1568+
"name": "python",
1569+
"nbconvert_exporter": "python",
1570+
"pygments_lexer": "ipython3",
1571+
"version": "3.7.3"
15581572
}
15591573
},
15601574
"nbformat": 4,

g3doc/tutorials/graph_keras_mlp_cora.ipynb

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@
5151
"id": "pL9fF9FWI-Q1"
5252
},
5353
"source": [
54-
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
55-
" \u003ctd\u003e\n",
56-
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_mlp_cora\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
57-
" \u003c/td\u003e\n",
58-
" \u003ctd\u003e\n",
59-
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_mlp_cora.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
60-
" \u003c/td\u003e\n",
61-
" \u003ctd\u003e\n",
62-
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_mlp_cora.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
63-
" \u003c/td\u003e\n",
64-
"\u003c/table\u003e"
54+
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
55+
" <td>\n",
56+
" <a target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_mlp_cora\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
57+
" </td>\n",
58+
" <td>\n",
59+
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_mlp_cora.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
60+
" </td>\n",
61+
" <td>\n",
62+
" <a target=\"_blank\" href=\"https://github.com/tensorflow/neural-structured-learning/blob/master/g3doc/tutorials/graph_keras_mlp_cora.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
63+
" </td>\n",
64+
"</table>"
6565
]
6666
},
6767
{
@@ -130,7 +130,7 @@
130130
},
131131
"outputs": [],
132132
"source": [
133-
"!pip install --quiet tensorflow==2.0.0-rc0\n",
133+
"!pip install --quiet tensorflow-gpu==2.0.0-rc0\n",
134134
"!pip install --quiet neural-structured-learning"
135135
]
136136
},
@@ -925,6 +925,7 @@
925925
}
926926
],
927927
"metadata": {
928+
"accelerator": "GPU",
928929
"colab": {
929930
"collapsed_sections": [],
930931
"last_runtime": {
@@ -960,7 +961,20 @@
960961
},
961962
"kernelspec": {
962963
"display_name": "Python 3",
964+
"language": "python",
963965
"name": "python3"
966+
},
967+
"language_info": {
968+
"codemirror_mode": {
969+
"name": "ipython",
970+
"version": 3
971+
},
972+
"file_extension": ".py",
973+
"mimetype": "text/x-python",
974+
"name": "python",
975+
"nbconvert_exporter": "python",
976+
"pygments_lexer": "ipython3",
977+
"version": "3.7.3"
964978
}
965979
},
966980
"nbformat": 4,

0 commit comments

Comments
 (0)