Skip to content
Discussion options

You must be logged in to vote

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.bias

The x: torch.Tensor means that the forward() method is expecting x to be of type torch.Tensor.

And the -> torch.Tensor means that the forward() method returns a torch.Tensor too.

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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 23f2005639
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants