Tensorflow Tutorial: Benedict Diederich
Tensorflow Tutorial: Benedict Diederich
Benedict Diederich
What is TensorFlow?
What is a „Tensor“?
- multilinear maps from vector spaces to the real numbers
- examples: Scalar, Vector, Matrix
TensorFlow vs. Numpy
Numpy Tensorflow
TensorFlow requires explicit evaluation!
Tensorflow Computation Graph
• “TensorFlow programs are usually structured into a construction phase, that assembles a graph,
and an execution phase that uses a session to execute ops in the graph.” - TensorFlow docs
never changes its value(s)
Graph creation
- builds graph sequentially
- adds nodes
Graph computation
Graph evaluation (gives result)
Tensorflow Computation Graph
input 1 = tf.constant(3.0)
input 2 = tf.constant(2.0)
input 3 = tf.constant(5.0)
intermed = tf.add(input2, input 3)
mul = tf.multiply(intermed, input1)
result = mul.eval()
Mathematical operations:
computations that will act on tensors
• MatMul: Multiply two matrix values
• Add: Add elementwise (with broadcasting)
• ReLU: Activate with elementwise rectified linear function
• etc.
TensorFlow Variables
“When you train a model you use variables to hold and update
parameters. Variables are in-memory buffers containing tensors” -
Was previously a constant
TensorFlow variables
must be initialized
- nodes which output their current value before they have
- State is retained across multiple executions values!
of a graph
- e.g. parameters, gradient stores, eligibility
traces, …
- value(s) can be updated
Tensorflow Placeholders and FeedDictionairies
tf.placeholder variables
- dummy nodes that provide entry points for data to
computational graph
- value is fed in at execution time
- inputs, variable learning rates, …
feed_dict
- python dictionary mapping from tf.placeholder vars to
data (numpy arrays, lists, etc.)
Tensorflow Placeholders and FeedDictionairies
Google Example: Graph Creation
Google Example: Graph Evalution
Example: Linear Regression in TensorFlow
Example: Linear Regression in TensorFlow
Example: Linear Regression in TensorFlow
Example: Linear Regression in TensorFlow
Example: Linear Regression in TensorFlow
Example: Linear Regression in TensorFlow
Concept: Auto-Differentiation
1. Build a graph
§ Graph contains:
- parameter specifications
- model architecture
- optimization process, …
2. Initialize a session
3. Fetch and feed data with Session.run
Compilation
Optimization
Auto-Differentiation etc.
Sources