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.
data module provides the complete dataset preparation pipeline for Heron AI Security experiments. It is intentionally model-agnostic and attack-agnostic: it knows nothing about backdoor injections, training loops, or evaluation metrics. Its responsibilities are strictly limited to loading datasets from the Hugging Face Hub, validating that the expected schema is present, stripping whitespace, building tokenizers, converting text to token IDs, and setting the PyTorch tensor format. Tokenization is deliberately kept separate from loading so that attacks can be applied to raw text before any token-level transformation occurs.
Constants
REQUIRED_COLUMNS
validate_dataset() raises a ValueError before any processing begins. To support a dataset with different field names, rename the columns upstream (e.g. dataset.rename_column("text", "sentence")) before calling prepare_dataset().
Functions
load_text_dataset()
Load a text classification dataset from the Hugging Face Hub. A thin wrapper arounddatasets.load_dataset() that returns the full DatasetDict with all available splits.
Hugging Face dataset repository name (e.g.
"glue", "imdb").Dataset configuration name within the repository (e.g.
"sst2", "mnli").A
DatasetDict containing all available splits ("train", "validation", "test", etc.).validate_dataset()
Validate that every split in aDatasetDict contains the required columns.
Iterates over every split and computes the set difference between REQUIRED_COLUMNS and the split’s column_names. Raises immediately on the first violation — it does not accumulate errors across splits.
The dataset to validate. All splits are checked against
REQUIRED_COLUMNS.Returns
None on success.preprocess_dataset()
Apply generic text-level preprocessing to aDatasetDict.
Currently strips leading and trailing whitespace from every "sentence" field. This operation is idempotent and does not alter labels or any other metadata. The original dataset object is not mutated; a new mapped DatasetDict is returned.
A validated
DatasetDict containing a "sentence" column in every split.A new
DatasetDict with whitespace stripped from all "sentence" values.build_tokenizer()
Load the tokenizer corresponding to a pretrained model checkpoint. A thin wrapper aroundAutoTokenizer.from_pretrained(). The returned tokenizer is fully configured for the target model and is shared across tokenize_dataset() and the Hugging Face Trainer.
Hugging Face model identifier (e.g.
"distilbert-base-uncased", "bert-base-cased").A tokenizer instance ready to encode text sequences.
tokenize_dataset()
Tokenize the"sentence" field of a dataset using a pretrained tokenizer.
Applies the tokenizer in batched mode with truncation=True. Accepts either a Dataset (single split) or a DatasetDict (all splits are tokenized). The function adds "input_ids" and "attention_mask" columns; padding is handled dynamically at collation time in the training loop rather than here.
The dataset to tokenize. Must contain a
"sentence" column.A tokenizer instance obtained from
build_tokenizer() or AutoTokenizer.from_pretrained().The dataset with
"input_ids" and "attention_mask" columns appended. The return type mirrors the input type.Call
tokenize_dataset() after any attack transformations have been applied. Tokenizing before poisoning means the trigger token would need to be injected at the token-ID level instead of the text level.prepare_for_training()
Convert a tokenized dataset into PyTorch tensor format. Callsdataset.with_format(type="torch", columns=["input_ids", "attention_mask", "label"]). Only the three columns required by the Hugging Face Trainer are surfaced; all other columns (e.g. "sentence", "idx") are dropped from the tensor view.
A tokenized
Dataset that contains "input_ids", "attention_mask", and "label" columns.The same dataset object formatted as PyTorch tensors, restricted to the three training columns.
prepare_dataset()
Execute the full load → validate → preprocess → tokenizer pipeline in a single call. This is the standard entry-point for experiment scripts. It returns the raw (untokenized) train and validation splits together with the tokenizer so that attack transformations can be applied to the text before tokenization occurs.Hugging Face dataset repository name (e.g.
"glue").Dataset configuration name (e.g.
"sst2").Hugging Face model identifier used to load the matching tokenizer.
A three-element tuple of
(train_dataset, validation_dataset, tokenizer). Both dataset splits are preprocessed but not yet tokenized.