Skip to content

Commit

Permalink
Internal
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 257288230
  • Loading branch information
yashk2810 authored and copybara-github committed Jul 9, 2019
1 parent 536c847 commit 201e0b7
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 74 deletions.
6 changes: 3 additions & 3 deletions site/en/r2/guide/keras/rnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
" View source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://storage.googleapis.com/tensorflow_docs/site/en/r2/guide/keras/rnn.ipynb\"\u003e\n",
" \u003ca target=\"_blank\" href=\"https://storage.googleapis.com/tensorflow_docs/docs/site/en/r2/guide/keras/rnn.ipynb\"\u003e\n",
" \u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003e\n",
" Download notebook\u003c/a\u003e\n",
" \u003c/td\u003e\n",
Expand Down Expand Up @@ -247,10 +247,10 @@
"encoder_state = [state_h, state_c]\n",
"\n",
"decoder_input = layers.Input(shape=(None, ))\n",
"decoder_embeded = layers.Embedding(input_dim=decoder_vocab, output_dim=64)(decoder_input)\n",
"decoder_embedded = layers.Embedding(input_dim=decoder_vocab, output_dim=64)(decoder_input)\n",
"\n",
"decoder_output = layers.LSTM(\n",
" 64, name='decoder')(decoder_embeded, initial_state=encoder_state)\n",
" 64, name='decoder')(decoder_embedded, initial_state=encoder_state)\n",
"output = layers.Dense(10, activation='softmax')(decoder_output)\n",
"\n",
"model = tf.keras.Model([encoder_input, decoder_input], output)\n",
Expand Down
2 changes: 1 addition & 1 deletion site/en/r2/tutorials/estimators/boosted_trees.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/r2/tutorials/estimators/boosted_trees.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/tree/master/site/en/r2/tutorials/estimators/boosted_trees.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\"\u003eView source on GitHub\u003c/a\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/en/r2/tutorials/estimators/boosted_trees.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\"\u003eView source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
"\u003c/table\u003e"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/r2/tutorials/estimators/boosted_trees_model_understanding.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/tree/master/site/en/r2/tutorials/estimators/boosted_trees_model_understanding.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/en/r2/tutorials/estimators/boosted_trees_model_understanding.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
"\u003c/table\u003e"
]
Expand Down
2 changes: 1 addition & 1 deletion site/en/r2/tutorials/estimators/premade_estimators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/r2/tutorials/estimators/premade_estimators.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/tree/master/site/en/r2/tutorials/estimators/premade_estimators.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/en/r2/tutorials/estimators/premade_estimators.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca href=\"https://storage.googleapis.com/tensorflow_docs/docs/site/en/r2/tutorials/estimators/premade_estimators.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003eDownload notebook\u003c/a\u003e\n",
Expand Down
2 changes: 1 addition & 1 deletion site/en/r2/tutorials/text/word_embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"source": [
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/beta/tutorials/text/word_embeddings.ipynb\"\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/beta/tutorials/text/word_embeddings\"\u003e\n",
" \u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003e\n",
" View on TensorFlow.org\u003c/a\u003e\n",
" \u003c/td\u003e\n",
Expand Down
2 changes: 1 addition & 1 deletion site/en/tutorials/estimators/boosted_trees.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/estimators/boosted_trees.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/tree/master/site/en/tutorials/estimators/boosted_trees.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\"\u003eView source on GitHub\u003c/a\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/site/en/tutorials/estimators/boosted_trees.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\"\u003eView source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
"\u003c/table\u003e"
]
Expand Down
135 changes: 69 additions & 66 deletions tools/templates/notebook.ipynb
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "notebook.ipynb",
"version": "0.3.2",
"provenance": [],
"private_outputs": true,
"collapsed_sections": [
"Tce3stUlHN0L"
],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"cells": [
{
"cell_type": "markdown",
Expand All @@ -30,12 +12,14 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab_type": "code",
"id": "tuOe1ymfHZPu",
"cellView": "form",
"colab": {}
"colab": {},
"colab_type": "code",
"id": "tuOe1ymfHZPu"
},
"outputs": [],
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
Expand All @@ -48,15 +32,13 @@
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qFdPvlXBOdUN",
"colab_type": "text"
"colab_type": "text",
"id": "qFdPvlXBOdUN"
},
"source": [
"# Title"
Expand All @@ -69,17 +51,20 @@
"id": "MfBg1C5NB3X0"
},
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://www.tensorflow.org/not_a_real_link\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/tools/templates/notebook.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/tools/templates/notebook.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/not_a_real_link\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/docs/blob/master/tools/templates/notebook.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/docs/blob/master/tools/templates/notebook.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca href=\"https://storage.googleapis.com/tensorflow_docs/docs/tools/templates/notebook.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003eDownload notebook\u003c/a\u003e\n",
" \u003c/td\u003e\n",
"\u003c/table\u003e"
]
},
{
Expand Down Expand Up @@ -126,21 +111,21 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "IqR2PQG4ZaZ0",
"colab": {}
"id": "IqR2PQG4ZaZ0"
},
"outputs": [],
"source": [
"from __future__ import absolute_import, division, print_function, unicode_literals\n",
"\n",
"import tensorflow.compat.v2 as tf\n",
"tf.enable_v2_behavior()\n",
"\n",
"import numpy as np"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -196,72 +181,72 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "KtylpxOmceaC",
"colab": {}
"id": "KtylpxOmceaC"
},
"outputs": [],
"source": [
"# Build the model\n",
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Dense(10, activation='relu', input_shape=(None, 5)),\n",
" tf.keras.layers.Dense(3)\n",
"])"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pwdM2pl3RSPb",
"colab_type": "text"
"colab_type": "text",
"id": "pwdM2pl3RSPb"
},
"source": [
"Run the model on a single batch of data, and inspect the output:"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "mMOeXVmbdilM",
"colab": {}
"id": "mMOeXVmbdilM"
},
"outputs": [],
"source": [
"result = model(tf.constant(np.random.randn(10,5), dtype = tf.float32)).numpy()\n",
"\n",
"print(\"min:\", result.min())\n",
"print(\"max:\", result.max())\n",
"print(\"mean:\", result.mean())\n",
"print(\"shape:\", result.shape)"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "uabQmjMtRtzs",
"colab_type": "text"
"colab_type": "text",
"id": "uabQmjMtRtzs"
},
"source": [
"Compile the model for training:"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "U82B_tH2d294",
"colab": {}
"id": "U82B_tH2d294"
},
"outputs": [],
"source": [
"model.compile(optimizer=tf.keras.optimizers.Adam(),\n",
" loss=tf.keras.losses.categorical_crossentropy)"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
Expand All @@ -273,8 +258,8 @@
"### Code content\n",
"\n",
"* Use the highest level API that gets the job done (unless the goal is to demonstrate the low level API).\n",
"* Use `keras.Sequential` > keras functional api > keras model subclassing > ...\n",
"* Use `model.fit` > `model.train_on_batch` > manual `GradientTapes`.\n",
"* Use `keras.Sequential` \u003e keras functional api \u003e keras model subclassing \u003e ...\n",
"* Use `model.fit` \u003e `model.train_on_batch` \u003e manual `GradientTapes`.\n",
"* Use eager-style code.\n",
"* Use `tensorflow_datasets` and `tf.data` where possible.\n",
"* Avoid `compat.v1`."
Expand Down Expand Up @@ -308,9 +293,27 @@
"* This notebook has the \"Omit code cell output when saving this notebook\" option set. GitHub refuses to diff notebooks with large diffs (inline images).\n",
"* [ReviewNB.com](http://reviewnb.com) can help with diffs. This is linked in a comment on a notebook pull request.\n",
"* Use the [Open in Colab](https://chrome.google.com/webstore/detail/open-in-colab/iogfkhleblhcpcekbiedikdehleodpjo) extension to open a GitHub notebook in Colab.\n",
"* The easiest way to edit a notebook in GitHub is to open it with Colab from the branch you want to edit. Then use File --> Save a copy in GitHub, which will save it back to the branch you opened it from.\n",
"* The easiest way to edit a notebook in GitHub is to open it with Colab from the branch you want to edit. Then use File --\u003e Save a copy in GitHub, which will save it back to the branch you opened it from.\n",
"* For PRs it's helpful to post a direct Colab link to the PR head: https://colab.research.google.com/github/{USER}/{REPO}/blob/{BRANCH}/{PATH}.ipynb"
]
}
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [
"Tce3stUlHN0L"
],
"name": "notebook.ipynb",
"private_outputs": true,
"provenance": [],
"toc_visible": true,
"version": "0.3.2"
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 201e0b7

Please sign in to comment.