secmlt.models package#
Subpackages#
Submodules#
secmlt.models.base_language_model module#
Basic wrapper for generic language model.
- class secmlt.models.base_language_model.BaseLanguageModel[source]#
Bases:
ABCAbstract base class defining the common interface for language models.
- abstract decode(ids: LongTensor, **kwargs) str | list[str][source]#
Convert token IDs back into text.
- Parameters:
ids (torch.LongTensor) – Token IDs tensor.
- Returns:
Decoded text(s).
- Return type:
str or list of str
- abstract encode(text: str | list[str], **kwargs) LongTensor[source]#
Convert input text into token IDs.
- Parameters:
text (str or list of str) – Input text(s) to tokenize.
- Returns:
Token IDs tensor.
- Return type:
torch.LongTensor
- abstract generate(prompts: list[str], **kwargs) list[str][source]#
Generate text continuations from given prompts.
- Parameters:
prompts (list of str) – List of prompt strings.
- Returns:
Generated text outputs.
- Return type:
list of str
Return hidden states of the model for given input.
- Parameters:
input_ids (torch.LongTensor) – Input token IDs.
- Returns:
Hidden representations per layer.
- Return type:
list of torch.Tensor
- abstract logprobs(prompts: list[str], targets: list[str], **kwargs) list[Tensor][source]#
Compute log-probabilities for each token in the target continuations.
- Parameters:
prompts (list of str) – Conditioning prompts.
targets (list of str) – Target continuations.
- Returns:
List of log-probability tensors, one per sample in the batch. Each tensor has shape [target_len_i].
- Return type:
list of torch.Tensor
secmlt.models.base_model module#
Basic wrapper for generic model.
- class secmlt.models.base_model.BaseModel(preprocessing: DataProcessing | None = None, postprocessing: DataProcessing | None = None)[source]#
Bases:
ABCBasic model wrapper.
- decision_function(x: Tensor, *args, **kwargs) Tensor[source]#
Return the decision function from the model.
Requires override to specify custom args and kwargs passing.
- Parameters:
x (torch.Tensor) – Input damples.
- Returns:
Model output scores.
- Return type:
torch.Tensor
secmlt.models.base_trainer module#
Model trainers.
Module contents#
Machine learning models and wrappers.