TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Antisource/heronaisec/llms.txt
Use this file to discover all available pages before exploring further.
models module manages the lifecycle of pretrained sequence classification models: constructing them from the Hugging Face Hub, persisting trained checkpoints to disk, and reloading those checkpoints for evaluation or downstream fine-tuning. It is intentionally free of training, evaluation, and attack logic — its sole concern is the model object itself. Tokenizer saving is handled separately in src.train, not here, to keep responsibilities clearly separated.
Functions
build_model()
Construct a pretrained sequence classification model ready for fine-tuning. CallsAutoModelForSequenceClassification.from_pretrained() with the supplied model_name and num_labels. The classification head is randomly initialised on top of the pretrained backbone.
Hugging Face model identifier (e.g.
"distilbert-base-uncased", "bert-base-cased"). Any model supported by AutoModelForSequenceClassification can be used.Number of output classes for the classification head. Use
2 for binary tasks such as SST-2 sentiment analysis.A
PreTrainedModel instance with pretrained encoder weights and a freshly initialised classification head, ready for Trainer-based fine-tuning.Building a model with
num_labels different from the checkpoint’s original configuration reinitialises the classification head and will log a warning from the Transformers library. This is expected behaviour during task-specific fine-tuning.save_model()
Persist a trained model checkpoint to disk. Callsmodel.save_pretrained(output_dir), which writes config.json and the model weights file (pytorch_model.bin or sharded equivalents) to output_dir. The tokenizer is not saved by this function — use tokenizer.save_pretrained() separately, or rely on train_model() in src.train which handles both in one call.
The trained model to save.
Destination directory. The directory is created by Hugging Face if it does not already exist.
Returns
None. Raises an OSError if the path is not writable.load_model()
Reload a previously saved model checkpoint from disk. CallsAutoModelForSequenceClassification.from_pretrained(checkpoint_dir). Both local paths and Hugging Face Hub identifiers are accepted, since the function delegates directly to the Transformers library.
Path to a local directory containing
config.json and model weights, or a Hugging Face Hub repository identifier.A
PreTrainedModel restored from the checkpoint, in evaluation mode by default.