Projection Layers¶
- class fairseq2.nn.Projection(input_dim, output_dim)[source]¶
-
Applies a linear transformation to incoming data.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- abstract forward(x)[source]¶
- Parameters:
x (Tensor) – The input to project. Shape: \((*,H_{inp})\), where \(H_{inp}\) is the input dimensionality.
- Returns:
The projected output. Shape: \((*,H_{out})\), where all but the last dimension are the same shape as the input and \(H_{out}\) is the output dimensionality.
- Return type:
- final class fairseq2.nn.Linear(input_dim, output_dim, bias, *, init_fn=None, device=None, dtype=None)[source]¶
Bases:
Projection
Applies a linear transformation to incoming data using weights and bias.
Unless overridden by a subclass, the weights and bias are initialized from \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\), where \(k = \frac{1}{\text{input_dim}}\).
Note
This class is identical to
torch.nn.Linear
.- Parameters:
- forward(x)[source]¶
- Parameters:
x (Tensor) – The input to project. Shape: \((*,H_{inp})\), where \(H_{inp}\) is the input dimensionality.
- Returns:
The projected output. Shape: \((*,H_{out})\), where all but the last dimension are the same shape as the input and \(H_{out}\) is the output dimensionality.
- Return type:
- final class fairseq2.nn.TiedProjection(weight, bias)[source]¶
Bases:
Projection
Applies a linear transformation to incoming data using the weights and bias of another
Module
instance.- Parameters:
weight (Parameter) – The shared weights.
bias (Parameter | None) – The shared bias.
- forward(x)[source]¶
- Parameters:
x (Tensor) – The input to project. Shape: \((*,H_{inp})\), where \(H_{inp}\) is the input dimensionality.
- Returns:
The projected output. Shape: \((*,H_{out})\), where all but the last dimension are the same shape as the input and \(H_{out}\) is the output dimensionality.
- Return type: