pytorch / 1.8.0 / generated / torch.nn.linear.html /

Linear

class torch.nn.Linear(in_features, out_features, bias=True) [source]

Applies a linear transformation to the incoming data: y = x A T + b y = xA^T + b

This module supports TensorFloat32.

Parameters
  • in_features – size of each input sample
  • out_features – size of each output sample
  • bias – If set to False, the layer will not learn an additive bias. Default: True
Shape:
  • Input: ( N , , H i n ) (N, *, H_{in}) where * means any number of additional dimensions and H i n = in_features H_{in} = \text{in\_features}
  • Output: ( N , , H o u t ) (N, *, H_{out}) where all but the last dimension are the same shape as the input and H o u t = out_features H_{out} = \text{out\_features} .
Variables
  • ~Linear.weight – the learnable weights of the module of shape ( out_features , in_features ) (\text{out\_features}, \text{in\_features}) . The values are initialized from U ( k , k ) \mathcal{U}(-\sqrt{k}, \sqrt{k}) , where k = 1 in_features k = \frac{1}{\text{in\_features}}
  • ~Linear.bias – the learnable bias of the module of shape ( out_features ) (\text{out\_features}) . If bias is True, the values are initialized from U ( k , k ) \mathcal{U}(-\sqrt{k}, \sqrt{k}) where k = 1 in_features k = \frac{1}{\text{in\_features}}

Examples:

>>> m = nn.Linear(20, 30)
>>> input = torch.randn(128, 20)
>>> output = m(input)
>>> print(output.size())
torch.Size([128, 30])

© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.nn.Linear.html