Skip to content

Commit

Permalink
Fix notebooks.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 305891180
  • Loading branch information
TensorFlow Hub Authors authored and vbardiovskyg committed Apr 14, 2020
1 parent b0f3c52 commit e540ee6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 36 deletions.
1 change: 0 additions & 1 deletion examples/colab/biggan_generation_with_tf_hub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
"import numpy as np\n",
"import PIL.Image\n",
"from scipy.stats import truncnorm\n",
"import tensorflow as tf\n",
"import tensorflow_hub as hub"
]
},
Expand Down
22 changes: 10 additions & 12 deletions examples/colab/cord_19_embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ORy-KvWXGXBo"
"id": "9VusdTAH0isl"
},
"source": [
"The CORD-19 Swivel text embedding module from TF-Hub (https://tfhub.dev/tensorflow/cord-19/swivel-128d/1)\n",
Expand All @@ -88,11 +88,11 @@
"- Train a classifier on the SciCite dataset using the CORD-19 embeddings\n"
]
},
{
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ORy-KvWXGXBo"
"id": "L69VQv2Z0isl"
},
"source": [
"## Setup\n"
Expand Down Expand Up @@ -122,8 +122,7 @@
"import tensorflow_datasets as tfds\n",
"import tensorflow_hub as hub\n",
"\n",
"from tqdm import trange\n",
"from google.colab import data_table"
"from tqdm import"
]
},
{
Expand Down Expand Up @@ -511,13 +510,12 @@
"outputs": [],
"source": [
"first_10_predictions = list(itertools.islice(predictions, 10))\n",
"data_table.DataTable(\n",
" pd.DataFrame({\n",
" TEXT_FEATURE_NAME: [pred['features'].decode('utf8') for pred in first_10_predictions],\n",
" LABEL_NAME: [THE_DATASET.class_names()[pred['labels']] for pred in first_10_predictions],\n",
" 'prediction': [THE_DATASET.class_names()[pred['predictions']] for pred in first_10_predictions]\n",
" }),\n",
" include_index=False)"
"\n",
"pd.DataFrame({\n",
" TEXT_FEATURE_NAME: [pred['features'].decode('utf8') for pred in first_10_predictions],\n",
" LABEL_NAME: [THE_DATASET.class_names()[pred['labels']] for pred in first_10_predictions],\n",
" 'prediction': [THE_DATASET.class_names()[pred['predictions']] for pred in first_10_predictions]\n",
"})"
]
},
{
Expand Down
35 changes: 15 additions & 20 deletions examples/colab/cord_19_embeddings_keras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ORy-KvWXGXBo"
"id": "yI6Mh3-P0_Pk"
},
"source": [
"The CORD-19 Swivel text embedding module from TF-Hub (https://tfhub.dev/tensorflow/cord-19/swivel-128d/2)\n",
Expand All @@ -92,7 +92,7 @@
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ORy-KvWXGXBo"
"id": "gVWOrccw0_Pl"
},
"source": [
"## Setup\n"
Expand Down Expand Up @@ -120,8 +120,7 @@
"import tensorflow_datasets as tfds\n",
"import tensorflow_hub as hub\n",
"\n",
"from tqdm import trange\n",
"from google.colab import data_table"
"from tqdm import trange"
]
},
{
Expand Down Expand Up @@ -232,12 +231,11 @@
"\n",
"data = next(iter(train_data.batch(NUM_EXAMPLES)))\n",
"\n",
"data_table.DataTable(\n",
" pd.DataFrame({\n",
" TEXT_FEATURE_NAME: [ex.numpy().decode('utf8') for ex in data[0]],\n",
" LABEL_NAME: [label2str(x) for x in data[1]]\n",
" }),\n",
" include_index=False)"
"\n",
"pd.DataFrame({\n",
" TEXT_FEATURE_NAME: [ex.numpy().decode('utf8') for ex in data[0]],\n",
" LABEL_NAME: [label2str(x) for x in data[1]]\n",
"})"
]
},
{
Expand Down Expand Up @@ -405,13 +403,12 @@
"\n",
"predictions = [label2str(x) for x in model.predict_classes(prediction_texts)]\n",
"\n",
"data_table.DataTable(\n",
" pd.DataFrame({\n",
" TEXT_FEATURE_NAME: prediction_texts,\n",
" LABEL_NAME: prediction_labels,\n",
" 'prediction': predictions\n",
" }),\n",
" include_index=False)"
"\n",
"pd.DataFrame({\n",
" TEXT_FEATURE_NAME: prediction_texts,\n",
" LABEL_NAME: prediction_labels,\n",
" 'prediction': predictions\n",
"})"
]
},
{
Expand Down Expand Up @@ -444,9 +441,7 @@
],
"metadata": {
"colab": {
"collapsed_sections": [
"5wFF5JFyD2Ki"
],
"collapsed_sections": [],
"name": "Exploring the TF-Hub CORD-19 Swivel Embeddings",
"private_outputs": true,
"provenance": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
"outputs": [],
"source": [
"#@title Download and extract SQuAD data\n",
"%%time\n",
"squad_url = 'https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json' #@param [\"https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v2.0.json\", \"https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v2.0.json\", \"https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v1.1.json\", \"https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json\"]\n",
"\n",
"squad_json = download_squad(squad_url)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@
"#@title Load the Universal Sentence Encoder's TF Hub module\n",
"from absl import logging\n",
"\n",
"import tensorflow.compat.v1 as tf\n",
"tf.disable_v2_behavior()\n",
"import tensorflow as tf\n",
"\n",
"import tensorflow_hub as hub\n",
"import matplotlib.pyplot as plt\n",
Expand Down

0 comments on commit e540ee6

Please sign in to comment.