banhxeo.model.classic.lstm module
- class banhxeo.model.classic.lstm.LSTMConfig(*, vocab_size: int | None = None, embedding_dim: int, hidden_size: int, bidirectional: bool = False, num_layers: int = 1, dropout: float = 0.0, bias: bool = False)[source]
Bases:
RNNConfig
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class banhxeo.model.classic.lstm.LSTMCell(input_size: int, hidden_size: int, cell_size: int, bias: bool)[source]
Bases:
Module
- __init__(input_size: int, hidden_size: int, cell_size: int, bias: bool)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(input_t: Tensor, h_prev: Tensor | None = None, cell_prev: Tensor | None = None)[source]
Define 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.
- class banhxeo.model.classic.lstm.LSTM(vocab: Vocabulary, embedding_dim: int, hidden_size: int, bias: bool = False)[source]
Bases:
NeuralLanguageModel
Use batch_first as default
- __init__(vocab: Vocabulary, embedding_dim: int, hidden_size: int, bias: bool = False)[source]
Initializes the NeuralLanguageModel.
- Parameters:
model_config – The configuration object, instance of NeuralModelConfig or its subclass.
vocab – The Vocabulary instance.
- forward(input_ids: Integer[Tensor, 'batch seq'], attention_mask: Integer[Tensor, 'batch seq'] | None = None, **kwargs)[source]
Defines the computation performed at every call.
Subclasses must implement this method. It should take tensors as input (e.g., input_ids, attention_mask) and return a dictionary of output tensors (e.g., logits, hidden_states, loss if computed).
- Parameters:
*args – Variable length argument list for model inputs.
**kwargs – Arbitrary keyword arguments for model inputs.
- Returns:
A dictionary where keys are string names of outputs (e.g., “logits”, “last_hidden_state”) and values are the corresponding `torch.Tensor`s.
- Raises:
NotImplementedError – If the subclass does not implement this method.