allennlp.modules.feedforward¶
A feed-forward neural network.
-
class
allennlp.modules.feedforward.FeedForward(input_dim: int, num_layers: int, hidden_dims: Union[int, List[int]], activations: Union[allennlp.nn.activations.Activation, List[allennlp.nn.activations.Activation]], dropout: Union[float, List[float]] = 0.0)[source]¶ Bases:
torch.nn.modules.module.Module,allennlp.common.from_params.FromParamsThis
Moduleis a feed-forward neural network, just a sequence ofLinearlayers with activation functions in between.- Parameters
- input_dim
int The dimensionality of the input. We assume the input has shape
(batch_size, input_dim).- num_layers
int The number of
Linearlayers to apply to the input.- hidden_dims
Union[int, List[int]] The output dimension of each of the
Linearlayers. If this is a singleint, we use it for allLinearlayers. If it is aList[int],len(hidden_dims)must benum_layers.- activations
Union[Callable, List[Callable]] The activation function to use after each
Linearlayer. If this is a single function, we use it after allLinearlayers. If it is aList[Callable],len(activations)must benum_layers.- dropout
Union[float, List[float]], optional If given, we will apply this amount of dropout after each layer. Semantics of
floatversusList[float]is the same as with other parameters.
- input_dim
-
forward(self, inputs: torch.Tensor) → torch.Tensor[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.