In [0]:
# 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
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

Prework: Hello World

Learning Objective: Run a TensorFlow program in the browser.

The code block below is a "Hello World" TensorFlow program.

It consists of initialization code (importing tensorflow module and enabling "eager execution", which will be covered in more detail in subsequent exercises) and printing a "Hello, world!" string constant.

In [0]:
from __future__ import print_function

import tensorflow as tf
except ValueError:
  pass  # enable_eager_execution errors after its first call

tensor = tf.constant('Hello, world!')
tensor_value = tensor.numpy()

To Run This Program

  1. Click anywhere in the code block (for example, on the word import).

  2. Click the right-facing-triangle icon in the upper-left corner of the code block, or hit ⌘/Ctrl-Enter.

    The program will take a few seconds to run. If all goes well, the program will write the phrase Hello, world! just below the code block

This entire program consists of a single code block. However, most exercises consist of multiple code blocks, in which case you should run the code blocks individually in sequence, from top to bottom.

Running the code blocks out of sequence typically causes errors.

Useful Keyboard Shortcuts

  • ⌘/Ctrl+m,b: creates an empty code cell below the cell that's currently selected
  • ⌘/Ctrl+m,i: interrupts a running cell
  • ⌘/Ctrl+m,h: shows a list of all keyboard shortcuts
  • For documentation on any TensorFlow API method, place the cursor right after its opening parenthesis and hit Tab: