tools/templates/notebook.ipynb
#@title Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Update button links]
See model on TFHub is only required if the notebook uses a model from tfhub.dev
[Include a paragraph or two explaining what this example demonstrates, who should be interested in it, and what you need to know before you get started.]
[Put all your imports and installs up into a setup section.]
import tensorflow as tf
import numpy as np
H1 header for the title.H1.H4 and below are not visible in the navigation
bar of tensorflow.org.#@title as the first line.# Build the model
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='relu', input_shape=(None, 5)),
tf.keras.layers.Dense(3)
])
Run the model on a single batch of data, and inspect the output:
result = model(tf.constant(np.random.randn(10,5), dtype = tf.float32)).numpy()
print("min:", result.min())
print("max:", result.max())
print("mean:", result.mean())
print("shape:", result.shape)
Compile the model for training:
model.compile(optimizer=tf.keras.optimizers.Adam(),
loss=tf.keras.losses.categorical_crossentropy)
keras.Sequential > keras functional api > keras model subclassing > ...model.fit > model.train_step > manual GradientTapes.tensorflow_datasets and tf.data where possible.compat.v1.