Better example code for the subsection "1. Replaced a variable with a…#2422
Open
HsienChing wants to merge 1 commit intotensorflow:masterfrom
Open
Better example code for the subsection "1. Replaced a variable with a…#2422HsienChing wants to merge 1 commit intotensorflow:masterfrom
HsienChing wants to merge 1 commit intotensorflow:masterfrom
Conversation
… tensor" # Better example code for the subsection "1. Replaced a variable with a tensor" **Position:** "1. Replaced a variable with a tensor" subsection **Link:** https://www.tensorflow.org/guide/autodiff#1_replaced_a_variable_with_a_tensor **Condition:** The original example is very concise. However, it took me a considerable amount of time to modify the code and test it to understand the example fully. I think there are two points that confused me. Point 1: The derivative of `y = x + 1` is a constant scalar `1`. This will cause no value change as the number of epoch increases. We can't obviously see the change in the value. Point 2: The comment directly gives the correct code `# This should be x.assign_add(1)` without the reason. **Suggestion:** I have modified the example code as shown below. 1. The formula has been changed from `y = x + 1` to `y = x**2`. The derivative is now `2x`, and we can obviously see the value change corresponding to epoch. 2. A comment "The `tf.Variable` has been inadvertently replaced with a `tf.Tensor`." has been added. 3. A epoch indicator is added. `print("epoch:", epoch)` 4. The number of epoch is changed from 2 to 3. REF: https://github.com/HsienChing/ML_DL_project_State_Estimation_of_Li-ion_Batteries/blob/main/other/Issues_in_TensorFlow_official_doc_Introduction_to_gradients_and_automatic_differentiation.ipynb
PreviewPreview and run these notebook edits with Google Colab: Rendered notebook diffs available on ReviewNB.com.Format and styleUse the TensorFlow docs notebook tools to format for consistent source diffs and lint for style:$ python3 -m pip install -U --user git+https://github.com/tensorflow/docsIf commits are added to the pull request, synchronize your local branch: git pull origin patch-3
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Better example code for the subsection "1. Replaced a variable with a tensor"
Position: "1. Replaced a variable with a tensor" subsection
Link: https://www.tensorflow.org/guide/autodiff#1_replaced_a_variable_with_a_tensor
Condition: The original example is very concise. However, it took me a considerable amount of time to modify the code and test it to understand the example fully.
I think there are two points that confused me.
Point 1: The derivative of
y = x + 1is a constant scalar1. This will cause no value change as the number of epoch increases. We can't obviously see the change in the value. Point 2: The comment directly gives the correct code# This should be x.assign_add(1)without the reason.Suggestion: I have modified the example code as shown below.
y = x + 1toy = x**2. The derivative is now2x, and we can obviously see the value change corresponding to epoch.tf.Variablehas been inadvertently replaced with atf.Tensor." has been added.print("epoch:", epoch)REF: https://github.com/HsienChing/ML_DL_project_State_Estimation_of_Li-ion_Batteries/blob/main/other/Issues_in_TensorFlow_official_doc_Introduction_to_gradients_and_automatic_differentiation.ipynb