Skip to content

Commit

Permalink
Standardize tensorflow.org buttons.
Browse files Browse the repository at this point in the history
Use "Setup" H2 for imports and installs.
Remove explicit tensorflow installs.
remove "activation=sigmoid|softmax"
replace `tensorflow_version 1.x` with `tf.compat.v1`

PiperOrigin-RevId: 305692573
  • Loading branch information
TensorFlow Hub Authors authored and kempy committed Apr 10, 2020
1 parent e52f77d commit d52ebe4
Show file tree
Hide file tree
Showing 24 changed files with 896 additions and 573 deletions.
42 changes: 28 additions & 14 deletions docs/tutorials/text_classification_with_tf_hub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,30 @@
"id": "ok9PfyoQ2rH_"
},
"source": [
"# How to build a simple text classifier with TF-Hub\n",
"\n",
"\u003ctable align=\"left\"\u003e\u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/hub/blob/master/docs/tutorials/text_classification_with_tf_hub.ipynb\"\u003e\n",
" \u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\n",
" \u003c/a\u003e\n",
"\u003c/td\u003e\u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/hub/blob/master/docs/tutorials/text_classification_with_tf_hub.ipynb\"\u003e\n",
" \u003cimg width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
"\u003c/td\u003e\u003c/table\u003e\n"
"# How to build a simple text classifier with TF-Hub\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "MfBg1C5NB3X0"
},
"source": [
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/hub/tutorials/text_classification_with_tf_hub\"\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/hub/blob/master/docs/tutorials/text_classification_with_tf_hub.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/hub/blob/master/docs/tutorials/text_classification_with_tf_hub.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/hub/docs/tutorials/text_classification_with_tf_hub.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 @@ -96,7 +110,7 @@
"id": "xOATihhH1IxS"
},
"source": [
"## Preparing the environment"
"## Setup"
]
},
{
Expand All @@ -111,8 +125,6 @@
"outputs": [],
"source": [
"# Install TF-Hub.\n",
"!pip install tensorflow==2.1.0\n",
"!pip install tensorflow-hub\n",
"!pip install seaborn"
]
},
Expand Down Expand Up @@ -557,7 +569,9 @@
"N6ZDpd9XzFeN"
],
"name": "Text classification with TF-Hub",
"provenance": []
"private_outputs": true,
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
Expand Down
54 changes: 32 additions & 22 deletions examples/colab/action_recognition_with_tf_hub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,30 @@
"id": "cDq0CIKc1vO_"
},
"source": [
"# TF-Hub Action Recognition Model\n",
"\n",
"\u003ctable align=\"left\"\u003e\u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/hub/blob/master/examples/colab/action_recognition_with_tf_hub.ipynb\"\u003e\n",
" \u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\n",
" \u003c/a\u003e\n",
"\u003c/td\u003e\u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/hub/blob/master/examples/colab/action_recognition_with_tf_hub.ipynb\"\u003e\n",
" \u003cimg width=32px src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
"\u003c/td\u003e\u003c/table\u003e"
"# TF-Hub Action Recognition Model\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "MfBg1C5NB3X0"
},
"source": [
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/hub/tutorials/action_recognition_with_tf_hub\"\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/hub/blob/master/examples/colab/action_recognition_with_tf_hub.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/hub/blob/master/examples/colab/action_recognition_with_tf_hub.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/hub/examples/colab/action_recognition_with_tf_hub.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 @@ -94,7 +108,7 @@
"id": "R_0xc2jyNGRp"
},
"source": [
"# Setting up the environment"
"## Setup"
]
},
{
Expand All @@ -107,7 +121,8 @@
},
"outputs": [],
"source": [
"!pip install -q imageio"
"!pip install -q imageio\n",
"!pip install python-opencv"
]
},
{
Expand All @@ -123,15 +138,9 @@
"source": [
"#@title Import the necessary modules\n",
"# TensorFlow and TF-Hub modules.\n",
"try:\n",
" # %tensorflow_version only exists in Colab.\n",
" %tensorflow_version 1.x\n",
"except Exception:\n",
" pass\n",
"\n",
"from absl import logging\n",
"\n",
"import tensorflow as tf\n",
"import tensorflow.compat.v1 as tf\n",
"import tensorflow_hub as hub\n",
"\n",
"logging.set_verbosity(logging.ERROR)\n",
Expand Down Expand Up @@ -330,11 +339,12 @@
"accelerator": "GPU",
"colab": {
"collapsed_sections": [
"x8Q7Un821X1A",
"R_0xc2jyNGRp"
"x8Q7Un821X1A"
],
"name": "Action Recognition on the UCF101 Dataset",
"provenance": []
"private_outputs": true,
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
Expand Down
44 changes: 28 additions & 16 deletions examples/colab/bangla_article_classifier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,45 @@
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "GhN2WtIrBQ4y"
"id": "MfBg1C5NB3X0"
},
"source": [
"This colab is a demonstration of using [Tensorflow Hub](https://www.tensorflow.org/hub/) for text classification in non-English/local languages. Here we choose [Bangla](https://en.wikipedia.org/wiki/Bengali_language) as the local language and use pretrained word embeddings to solve a multiclass classification task where we classify Bangla news articles in 5 categories. The pretrained embeddings for Bangla comes from [fastText](https://fasttext.cc/docs/en/crawl-vectors.html) which is a library by Facebook with released pretrained word vectors for 157 languages. \n",
"\n",
"We'll use TF-Hub's pretrained embedding exporter for converting the word embeddings to a text embedding module first and then use the module to train a classifier with [tf.keras](https://www.tensorflow.org/api_docs/python/tf/keras), Tensorflow's high level user friendly API to build deep learning models. Even if we are using fastText embeddings here, it's possible to export any other embeddings pretrained from other tasks and quickly get results with Tensorflow hub. "
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/hub/tutorials/bangla_article_classifier\"\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/hub/blob/master/examples/colab/bangla_article_classifier.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/hub/blob/master/examples/colab/bangla_article_classifier.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/hub/examples/colab/bangla_article_classifier.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"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Q4DN769E2O_R"
"id": "GhN2WtIrBQ4y"
},
"source": [
"# Prepare Environment"
"This colab is a demonstration of using [Tensorflow Hub](https://www.tensorflow.org/hub/) for text classification in non-English/local languages. Here we choose [Bangla](https://en.wikipedia.org/wiki/Bengali_language) as the local language and use pretrained word embeddings to solve a multiclass classification task where we classify Bangla news articles in 5 categories. The pretrained embeddings for Bangla comes from [fastText](https://fasttext.cc/docs/en/crawl-vectors.html) which is a library by Facebook with released pretrained word vectors for 157 languages. \n",
"\n",
"We'll use TF-Hub's pretrained embedding exporter for converting the word embeddings to a text embedding module first and then use the module to train a classifier with [tf.keras](https://www.tensorflow.org/api_docs/python/tf/keras), Tensorflow's high level user friendly API to build deep learning models. Even if we are using fastText embeddings here, it's possible to export any other embeddings pretrained from other tasks and quickly get results with Tensorflow hub. "
]
},
{
"cell_type": "code",
"execution_count": 0,
"cell_type": "markdown",
"metadata": {
"colab": {},
"colab_type": "code",
"id": "zA07b51AGF5l"
"colab_type": "text",
"id": "Q4DN769E2O_R"
},
"outputs": [],
"source": [
"!pip install -q tensorflow-gpu==2.0.0-beta1"
"## Setup"
]
},
{
Expand Down Expand Up @@ -426,8 +436,9 @@
" model.add(embedding_layer)\n",
" model.add(tf.keras.layers.Dense(64, activation=\"relu\"))\n",
" model.add(tf.keras.layers.Dense(16, activation=\"relu\"))\n",
" model.add(tf.keras.layers.Dense(5, activation=\"softmax\"))\n",
" model.compile(loss=\"categorical_crossentropy\", optimizer=\"adam\", metrics=['accuracy'])\n",
" model.add(tf.keras.layers.Dense(5))\n",
" model.compile(loss=tf.losses.CategoricalCrossentropy(from_logits=True),\n",
" optimizer=\"adam\", metrics=['accuracy'])\n",
" return model"
]
},
Expand Down Expand Up @@ -663,8 +674,9 @@
"colab": {
"collapsed_sections": [],
"name": "Bangla article classifier.ipynb",
"private_outputs": true,
"provenance": [],
"version": "0.3.2"
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
Expand Down
53 changes: 39 additions & 14 deletions examples/colab/bigbigan_with_tf_hub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,39 @@
"id": "-1NTVIH6ABK-"
},
"source": [
"# BigBiGAN Demo\n",
"\n",
"# BigBiGAN Demo\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "MfBg1C5NB3X0"
},
"source": [
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/hub/tutorials/bigbigan_with_tf_hub\"\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/hub/blob/master/examples/colab/bigbigan_with_tf_hub.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/hub/blob/master/examples/colab/bigbigan_with_tf_hub.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/hub/examples/colab/bigbigan_with_tf_hub.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"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "AVvOoEhswyZg"
},
"source": [
"This notebook is a demo for the *BigBiGAN* models available on [TF Hub](https://tfhub.dev/s?publisher=deepmind\u0026q=bigbigan).\n",
"\n",
"BigBiGAN extends standard (Big)GANs by adding an *encoder* module which can be used for unsupervised representation learning. Roughly speaking, the encoder inverts the generator by predicting latents `z` given real data `x`. See the [BigBiGAN paper on arXiv](https://arxiv.org/abs/1907.02544) [1] for more information about these models.\n",
Expand Down Expand Up @@ -94,7 +125,7 @@
"id": "Lr01cszC_vcC"
},
"source": [
"# Setup"
"## Setup"
]
},
{
Expand All @@ -107,19 +138,16 @@
},
"outputs": [],
"source": [
"try:\n",
" # %tensorflow_version only exists in Colab.\n",
" %tensorflow_version 1.x\n",
"except Exception:\n",
" pass\n",
"\n",
"import io\n",
"import IPython.display\n",
"import PIL.Image\n",
"from pprint import pformat\n",
"\n",
"import numpy as np\n",
"import tensorflow as tf\n",
"\n",
"import tensorflow.compat.v1 as tf\n",
"tf.disable_v2_behavior()\n",
"\n",
"import tensorflow_hub as hub"
]
},
Expand Down Expand Up @@ -716,11 +744,8 @@
"collapsed_sections": [
"9v58CTfl8jTc"
],
"last_runtime": {
"build_target": "",
"kind": "local"
},
"name": "BigBiGAN TF Hub Demo",
"private_outputs": true,
"provenance": [],
"toc_visible": true
},
Expand Down
Loading

0 comments on commit d52ebe4

Please sign in to comment.