|
45 | 45 | "\n", |
46 | 46 | "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n", |
47 | 47 | " \u003ctd\u003e\n", |
48 | | - " \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_lstm_imdb.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\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 | 49 | " \u003c/td\u003e\n", |
50 | 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", |
| 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 | 52 | " \u003c/td\u003e\n", |
53 | 53 | " \u003ctd\u003e\n", |
54 | 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", |
|
114 | 114 | "source": [ |
115 | 115 | "## Requirements\n", |
116 | 116 | "\n", |
117 | | - "1. Install the Neural Structured Learning package.\n", |
118 | | - "2. Install tensorflow-hub" |
| 117 | + "1. Install TensorFlow 2.x to create an interactive developing environment with eager execution.\n", |
| 118 | + "2. Install the Neural Structured Learning package.\n", |
| 119 | + "3. Install tensorflow-hub." |
119 | 120 | ] |
120 | 121 | }, |
121 | 122 | { |
|
128 | 129 | }, |
129 | 130 | "outputs": [], |
130 | 131 | "source": [ |
| 132 | + "!pip install --quiet tensorflow==2.0.0-rc0\n", |
131 | 133 | "!pip install --quiet neural-structured-learning\n", |
132 | | - "!pip install --quit tensorflow-hub" |
| 134 | + "!pip install --quiet tensorflow-hub" |
133 | 135 | ] |
134 | 136 | }, |
135 | 137 | { |
|
162 | 164 | "\n", |
163 | 165 | "import neural_structured_learning as nsl\n", |
164 | 166 | "\n", |
165 | | - "### Enable Tensorflow v2 behavior.\n", |
166 | 167 | "import tensorflow as tf\n", |
167 | 168 | "tf.compat.v1.enable_v2_behavior()\n", |
168 | | - "tf.keras.backend.clear_session() # Resets notebook state\n", |
169 | 169 | "\n", |
170 | 170 | "import tensorflow_hub as hub\n", |
171 | 171 | "\n", |
172 | | - "print(tf.__version__)" |
| 172 | + "# Resets notebook state\n", |
| 173 | + "tf.keras.backend.clear_session()\n", |
| 174 | + "\n", |
| 175 | + "print(\"Version: \", tf.__version__)\n", |
| 176 | + "print(\"Eager mode: \", tf.executing_eagerly())\n", |
| 177 | + "print(\"Hub version: \", hub.__version__)\n", |
| 178 | + "print(\"GPU is\", \"available\" if tf.test.is_gpu_available() else \"NOT AVAILABLE\")" |
173 | 179 | ] |
174 | 180 | }, |
175 | 181 | { |
|
436 | 442 | }, |
437 | 443 | "outputs": [], |
438 | 444 | "source": [ |
| 445 | + "# This is necessary because hub.KerasLayer assumes tensor hashability, which\n", |
| 446 | + "# is not supported in eager mode.\n", |
| 447 | + "tf.compat.v1.disable_tensor_equality()\n", |
| 448 | + "\n", |
439 | 449 | "pretrained_embedding = 'https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1'\n", |
440 | 450 | "\n", |
441 | 451 | "hub_layer = hub.KerasLayer(\n", |
|
730 | 740 | " self.num_classes = 2\n", |
731 | 741 | " self.max_seq_length = 256\n", |
732 | 742 | " self.vocab_size = 10000\n", |
733 | | - " ### Neural Graph Learning parameters\n", |
| 743 | + " ### neural graph learning parameters\n", |
734 | 744 | " self.distance_type = nsl.configs.DistanceType.L2\n", |
735 | 745 | " self.graph_regularization_multiplier = 0.1\n", |
736 | 746 | " self.num_neighbors = 1\n", |
|
1030 | 1040 | "validation_fraction = 0.9\n", |
1031 | 1041 | "validation_size = int(validation_fraction *\n", |
1032 | 1042 | " int(training_samples_count / HPARAMS.batch_size))\n", |
| 1043 | + "print(validation_size)\n", |
1033 | 1044 | "validation_dataset = train_dataset.take(validation_size)\n", |
1034 | 1045 | "train_dataset = train_dataset.skip(validation_size)" |
1035 | 1046 | ] |
|
0 commit comments