WestDRI / machine-learning

Old site on workshops & webinars on machine learning. Visit the new repo & site now (see README)
https://ml.westdri.ca/
0 stars 0 forks source link

Automatic differentiation with autograd · Machine-learning #2

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Automatic differentiation with autograd · Machine-learning

https://westgrid-ml.netlify.app/schoolremake/pt-13-autograd.html

vickeybu commented 4 years ago

when I was trying to run one of the statements, it gave me an error message (see below). I am so new to python and am not sure why.

with torch.no_grad(): ... manual_gradient_predicted = 2.0 * (predicted - real) ... print(manual_gradient_predicted) File "", line 3 print(manual_gradient_predicted) ^ SyntaxError: invalid syntax

prosoitos commented 4 years ago

Your problem is a wrong indentation.

Python uses indentation to delineate blocks instead of parentheses, braces, or other syntax as is common in other languages. So the indentation in Python is not just a question of readability. It is really part of the code.

The print statement should be aligned on the left-most side as it is a statement independent from what came above.

The way you indented it, you included it within the with torch.no_grad(): statement.

I added a blank line above that print statement to make it more obvious that it is independent from what precedes.