Skip to content

Commit fae990c

Browse files
Neural-Link Teamtensorflow-copybara
authored andcommitted
Updates the links and TF version in graph regularization colab.
PiperOrigin-RevId: 266203589
1 parent acefbeb commit fae990c

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

g3doc/tutorials/graph_keras_mlp_cora.ipynb

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"source": [
5454
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
5555
" \u003ctd\u003e\n",
56-
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_mlp_cora.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\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",
5757
" \u003c/td\u003e\n",
5858
" \u003ctd\u003e\n",
5959
" \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",
@@ -106,7 +106,40 @@
106106
},
107107
"source": [
108108
"## Setup\n",
109-
"\n",
109+
"\n"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"metadata": {
115+
"colab_type": "text",
116+
"id": "v_39VWm4yIgt"
117+
},
118+
"source": [
119+
"Install Tensorflow 2.0 to create an interactive developing environment with\n",
120+
"eager execution."
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": 0,
126+
"metadata": {
127+
"colab": {},
128+
"colab_type": "code",
129+
"id": "2m7Sp74HyFVS"
130+
},
131+
"outputs": [],
132+
"source": [
133+
"!pip install --quiet tensorflow==2.0.0-rc0"
134+
]
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"metadata": {
139+
"colab_type": "text",
140+
"id": "hgSLDi0SyBuO"
141+
},
142+
"source": [
110143
"Install the Neural Structured Learning package."
111144
]
112145
},
@@ -147,9 +180,7 @@
147180
"\n",
148181
"import neural_structured_learning as nsl\n",
149182
"\n",
150-
"# Enable TensorFlow v2 behavior\n",
151183
"import tensorflow as tf\n",
152-
"tf.compat.v1.enable_v2_behavior()\n",
153184
"\n",
154185
"# Resets notebook state\n",
155186
"tf.keras.backend.clear_session()"
@@ -244,7 +275,7 @@
244275
},
245276
"outputs": [],
246277
"source": [
247-
"!wget https://github.com/tensorflow/neural-structured-learning/blob/master/examples/preprocess/cora/preprocess_cora_dataset.py\n",
278+
"!wget https://raw.githubusercontent.com/tensorflow/neural-structured-learning/master/neural_structured_learning/examples/preprocess/cora/preprocess_cora_dataset.py\n",
248279
"\n",
249280
"!python preprocess_cora_dataset.py \\\n",
250281
"--input_cora_content=/tmp/cora/cora.content \\\n",

neural_structured_learning/examples/preprocess/cora/preprocess_cora_dataset.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
"""Input file for Cora content that contains ID, words and labels.""")
7777
flags.DEFINE_string('input_cora_graph', '/tmp/cora/cora.cites',
7878
"""Input file for Cora citation graph in TSV format.""")
79+
flags.DEFINE_integer(
80+
'max_nbrs', None,
81+
'The maximum number of neighbors to merge into each labeled Example.')
7982
flags.DEFINE_float(
8083
'train_percentage', 0.8,
8184
"""The percentage of examples to be created as training data. The rest
@@ -158,8 +161,11 @@ def main(unused_argv):
158161
# neighbors for transductive learning purpose. In other words, the labels of
159162
# test_examples are not used.
160163
with tf.io.TFRecordWriter(FLAGS.output_train_data) as writer:
161-
for merged_example in pack_nbrs.join_examples(train_examples, test_examples,
162-
graph, FLAGS.max_nbrs):
164+
# Here we call a private function in pack_nbrs to join the examples. This is
165+
# one-off for demonstration purpose only. Later on we will refactor that
166+
# function to a public API.
167+
for merged_example in pack_nbrs._join_examples( # pylint: disable=protected-access
168+
train_examples, test_examples, graph, FLAGS.max_nbrs):
163169
writer.write(merged_example.SerializeToString())
164170

165171
logging.info('Output training data written to TFRecord file: %s.',

0 commit comments

Comments
 (0)