LMLSTM implements a word-level language model that uses LSTMs to represent the document.
forward(tokens, *inputs) → List[torch.Tensor]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
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.
from_config(model_config, feat_config, metadata: pytext.data.data_handler.CommonMetadata)¶
Factory method to construct an instance of LMLSTM from the module’s config object and the field’s metadata object.
- config (LMLSTM.Config) – Configuration object specifying all the parameters of LMLSTM.
- feat_config (FeatureConfig) – Configuration object specifying all the parameters of all input features.
- metadata (FieldMeta) – Object containing this field’s metadata.
An instance of LMLSTM.
Initialize the hidden states of the LSTM if the language model is stateful.
Parameters: bsz (int) – Batch size. Returns: Initialized hidden state and cell state of the LSTM. Return type: Tuple[torch.Tensor, torch.Tensor]
Wraps hidden states in new Tensors, to detach them from their history.
Parameters: hidden (Union[torch.Tensor, Tuple[torch.Tensor, ..]]) – Tensor or a tuple of tensors to repackage. Returns: Repackaged output Return type: Union[torch.Tensor, Tuple[torch.Tensor, ..]]