liveBook · Manning

Variable

As explained in Deep Learning with R, Third Edition

A TensorFlow variable is a mutable tensor-like object that stores modifiable model state and can be updated by assignment.

A TensorFlow variable is a mutable tensor-like object for storing model state that changes during computation. Unlike a regular tensor, it supports assignment and in-place-style updates. section 3.3.1 section 3.2

Create and update a variable

Create a variable from a zero-filled tensor, replace its contents, then add to every element:\n\n```r\nv <- tf$Variable(initial_value = tf$zeros(shape = shape(3, 1)))\nv$assign(tf$ones(shape(3, 1)))\nv$assign_add(tf$ones(shape(3, 1)))\n```\n\nAssignment changes the stored value, whereas direct item assignment on an ordinary tensor is unsupported. section 3.3.1

Variables also participate naturally in automatic differentiation: GradientTape tracks operations involving them and can compute gradients with respect to their values. section 3.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines creation, full and indexed assignment, additive updates, and gradient tracking, but does not develop optimizer internals.
Examples
Uses zero- and one-filled matrices, indexed updates, additive updates, and a squared variable inside GradientTape.
What it assumes
Assumes basic tensors and tensor operations, while distinguishing mutable variables from ordinary tensors and constants.
What you can do after
Operate/configure it through tf$Variable, assign(), indexed assignment, assign_add(), and GradientTape.
How it connects
Connects variables to tensors, tensor operations, automatic differentiation, backpropagation, and neural-network training.

Also explained in

Compare how 2 books explain variable →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.