pytext.models.language_models package¶
Submodules¶
pytext.models.language_models.lmlstm module¶
-
class
pytext.models.language_models.lmlstm.
LMLSTM
(embedding: pytext.models.embeddings.embedding_base.EmbeddingBase = <pytext.config.field_config.WordFeatConfig object>, representation: pytext.models.representations.representation_base.RepresentationBase = <pytext.models.representations.bilstm.BiLSTM.Config object>, decoder: pytext.models.decoders.decoder_base.DecoderBase = <pytext.models.decoders.mlp_decoder.MLPDecoder.Config object>, output_layer: pytext.models.output_layers.output_layer_base.OutputLayerBase = <pytext.models.output_layers.lm_output_layer.LMOutputLayer.Config object>, stateful: bool = False, exporter: object = <class 'pytext.exporters.exporter.ModelExporter'>)[source]¶ Bases:
pytext.models.model.BaseModel
LMLSTM implements a word-level language model that uses LSTMs to represent the document.
-
classmethod
checkTokenConfig
(tokens: Optional[pytext.data.tensorizers.TokenTensorizer.Config])[source]¶
-
forward
(tokens: torch.Tensor, seq_len: torch.Tensor) → List[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
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
-
classmethod
from_config
(config: pytext.models.language_models.lmlstm.LMLSTM.Config, tensorizers: Dict[str, pytext.data.tensorizers.Tensorizer])[source]¶
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]
-
classmethod
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, ..]]