ner.nn.models.rnn module#
- class ner.nn.models.rnn.RNN(embedding_dim: int, hidden_dim: int, output_dim: int, num_layers: int = 1, bias: bool = True, nonlinearity: str = 'tanh')#
Bases:
Module
A multi-layer recurrent neural network with ReLU, tanh, or PReLU nonlinearity to an input sequence.
- Parameters:
- embedding_dim
int
Number of dimensions of an input embedding.
- hidden_dim
int
Number of dimensions of the hidden layer(s).
- output_dim
int
Number of dimensions for the output layer.
- num_layers
int
, default: 1 Number of layers in the multi-layer RNN model.
- bias
bool
, default:True
If set to False, the input-to-hidden and hidden-to-hidden transformations will not include bias. Note: the hidden-to-output transformation remains unaffected by
bias
.- nonlinearity{“tanh”, “relu”, “prelu”}, default: “tanh”
Name of the nonlinearity to be applied during the forward pass.
- embedding_dim
Returns a list of
num_layers
number of initial hidden states.- Parameters:
- Returns:
List
[torch.Tensor
]List holding tensors of initialized initial hidden states of shape (num_layers, batch_size, hidden_dim).
- forward(embeddings: Tensor) Tensor #
Computes a forward pass of the given input embeddings through the RNN model.
- Parameters:
- embeddings
torch.Tensor
Input tensor of embeddings of shape
(batch_size, max_length, embedding_dim)
.
- embeddings
- Returns:
torch.Tensor
Output tensor resulting from forward pass of shape
(batch_size, max_length, output_dim)
.