November 2019
Intermediate to advanced
296 pages
7h 52m
English
Fundamentally, a tensor is an immutable data structure. Even if we use TensorBuffer, we just create another tensor with new data and a new shape. The design of a tensor can't help us fit the parameters of machine learning models through the training process. tf.variable is an API that we can use to generate a mutable container for the tensor:
const x = tf.variable(tf.tensor([[1, 2], [3, 4]]));// Assign a new value to the variablex.assign(tf.tensor([[4, 5], [6, 7]]));x.print();// Tensor// [[4, 5],// [6, 7]]
The merit of using a variable is that we can use it to validate the data type and shape of the tensor. It ensures the initial data type and shapes are correct, even after the new value has been assigned. Hence, the ...
Read now
Unlock full access