want to know the use of this?? #360
-
|
as I have used the forward function , what is the use of this(marked in image ) in forward function |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi @maxsn2005, That is called a "type annotation" or "type hints" in Python. def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.weights * x + self.biasThe And the Type hints/annotations are helpful for when you'd like to know the inputs/outputs of your code/functions. They don't necessarily return errors but when looking up documentation for what code does, the type annotation/hint shows you what the code is expecting as input/output. You can see more here: https://realpython.com/python-type-checking/ |
Beta Was this translation helpful? Give feedback.

Hi @maxsn2005,
That is called a "type annotation" or "type hints" in Python.
The
x: torch.Tensormeans that theforward()method is expectingxto be of typetorch.Tensor.And the
-> torch.Tensormeans that theforward()method returns atorch.Tensortoo.Type hints/annotations are helpful for when you'd like to know the inputs/outputs of your code/functions.
They don't necessarily return errors but when looking up documentation for what code does, the type annotation/hint shows you what the code is expecting as input/output.
You can see more here: https://realpython.com/python-type-checking/
Or he…