Skip to content
Discussion options

You must be logged in to vote

Hi @Reetos,

Good question!

I answered a similar question here: #360 (comment)

But I'll paste it here too (because the question is similar):

Those are called "type annotations" 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 s…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Reetos
Comment options

@avish121
Comment options

@Mingfei-Jiang
Comment options

Answer selected by Reetos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants