What does -> torch.Tensor
mean?
#198
-
In the code: class LinearRegressionModel(nn.Module):
def __init__(self):
super().__init__()
self.weights = nn.Paramter(torch.randn(1,
requires_grad=True,
dtype =torch.float))
self.bias = nn.Paramter(torch.randn(1,
requires_grad=True,
dtype =torch.float))
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.weights * x + self.bias What is the meaning of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
They're called function typehints. i.e. the output/return value of that function forward() is a type of 'torch.Tensor' I think it's only used for documentation and code hints and not actually enforced by Python. |
Beta Was this translation helpful? Give feedback.
-
Thank you @fivefishstudios for the answer! And @mostfa00, they aren't required but they do help with code/communication. Type hints are a way of specifying the expected data types of function arguments and return values in Python. Here's an example: from typing import List
def combine_strings(strings: List[str]) -> str:
return ''.join(strings) In this example, the The |
Beta Was this translation helpful? Give feedback.
They're called function typehints. i.e. the output/return value of that function forward() is a type of 'torch.Tensor'
I think it's only used for documentation and code hints and not actually enforced by Python.