oneflow.nn.Linear¶
-
class
oneflow.nn.
Linear
(in_features: int, out_features: int, bias: bool = True, device=None, dtype=None)¶ Applies a linear transformation to the incoming data: \(y = xA^T + b\)
- 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_{in})\) where \(*\) means any number of additional dimensions and \(H_{in} = {in\_features}\)
Output: \((N, *, H_{out})\) where all but the last dimension are the same shape as the input and \(H_{out} = {out\_features}\).
- Attr:
weight
: the learnable weights of the module of shape \(({out\_features}, {in\_features})\). The values are initialized from \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\), where \((k = 1 / {in\_features})\)bias
: the learnable bias of the module of shape \(({out\_features})\). Ifbias
isTrue
, the values are initialized from \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\) where \((k = 1 / {in\_features})\)
For example:
>>> import numpy as np >>> import oneflow as flow >>> m = flow.nn.Linear(20, 30, False) >>> input = flow.Tensor(np.random.randn(128, 20)) >>> output = m(input) >>> output.size() oneflow.Size([128, 30])