Tensor and Variable: Value calculation and status update

Tensor represents the value calculated once, and Variable indicates a state that can be updated on a permanent basis.

Thematic shorts • IntroductionCollate in 2 self-measured2 First-hand sources
Start Body
Learning objectives and first steps2 objectives 2 first fixes

Try to do it after reading

  • Distinguishing Non-changeable Thresholds from Updateable Status
  • Track whether the assigned value is in the differential path

Suggested first

  • Python Basic Syntax:
  • Counting and training closed

It's also written in two. The characters may be different

Tensor represents the value calculated once, and Variable indicates a state that can be updated on a permanent basis. Training weights need to be retained and changed between optimization steps, and therefore variables are used; The intermediate activation is usually merely a matter of weight. A stretch object cannot change an existing value by modifying an element, and the variable can be updated by operation in a state such as assign.

Set the variable w initially at 2, read and calculate a = 3 w, get 6; Then assign(5), again calculated b = 3 w, obtained 15. a will not go back to 15. It recorded the results of the calculations made at the time. Understanding a variable as a spreadsheet cell that will automatically update all old expressions will misread the instant execution behaviour.

For microcalculations, variables can be read as part of an input path, but state-allocation values are not the usual arithmetic edge connecting all historical training steps. If the new value assign is returned at every step, the default training will not retain an infinite length of "optimist update history" for meta-learning reverses. If you want to study the high-level guides of the steps through the update, you should update the mathematical process of the expression with a visible stretch and verify the path.

Shapes and persistence are also state pacts

Variables usually have a clear shape and data type. The batch has been changed from 32 to 16 and should not create a weight of shapes to change in the batch at each time. The weight shape is determined by the characteristic dimensions, and the batch is only a calculation of the input. If a new variable is created at tf. function every call, it will often trigger a constraint on the creation of the variable; Creates first at the layer build stage and then repeats it more clearly during the call.

For example, linear layer input [batch, ], weight [3,2], bias [2]. The batch was changed from 4 to 7, the output was changed from [4,2] to [7,2], and the weights remained at only 6 matrix elements and 2 deviations. The storage of each sample as a variable would couple model status with data size and would not be conducive to preservation and deployment.

When you are mistaken, you can print separately the object type, shape, and whether the variable appears in the model 's trainable weights list. Values appear to change and do not represent that the optimiser has updated the intended object: re-strapped a normal load to the name Python, which may have been separated from the original variable in the layer.

This section is explained by TensorFlow2 variable semantics and does not use TF1 Session or placeholder. 6. The matrix shapes are direct hand-counting and the frame example is not executed on-board.

When the variable is changed from 2 to 5, will the a = 3 w automatically change?

No, I won't. a was calculated at that time as result 6, unless a new result was produced by a re-execution of the multiplier.

Enter batch extension. Why does the linear weight not increase?

The same group of weights is shared among all samples. The batch axis on the left side of the matrix only controls how many lines are calculated in parallel, and the weight describes the map of characteristics from output to output.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. TensorFlow — Introduction to gradients and automatic differentiation
  2. TensorFlow — Introduction to Variables

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.