# oneflow.nn.Linear¶

class oneflow.nn.Linear(in_features: int, out_features: int, bias: bool = True)

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})$$. If bias is True, 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])

__init__(in_features: int, out_features: int, bias: bool = True)None

Initialize self. See help(type(self)) for accurate signature.

Methods

 __call__(*args, **kwargs) Call self as a function. __delattr__(name, /) Implement delattr(self, name). __dir__() Default dir() implementation. __eq__(value, /) Return self==value. __format__(format_spec, /) Default object formatter. __ge__(value, /) Return self>=value. __getattr__(name) __getattribute__(name, /) Return getattr(self, name). __gt__(value, /) Return self>value. __hash__() Return hash(self). __init__(in_features, out_features[, bias]) Initialize self. __init_subclass__ This method is called when a class is subclassed. __le__(value, /) Return self<=value. __lt__(value, /) Return self