Dataset
MuranoDataset: dataset representations for pipeline steps.
MuranoDataset
Section titled “MuranoDataset”Dataset container supporting contrastive pairs.
For a steering direction: positive and negative hold the two contrasting classes (e.g. positive vs negative sentiment).
Attributes:
positive_texts: List of strings in the positive class (possibly templated).negative_texts: List of strings in the negative class (possibly templated).raw_positive: Original positive texts before chat template (None if no template).raw_negative: Original negative texts before chat template (None if no template).
__init__
Section titled “__init__”def __init__(self, positive_texts: list[str], negative_texts: list[str], raw_positive: list[str] | None = None, raw_negative: list[str] | None = None):from_hub
Section titled “from_hub”def from_hub(cls, positive: str | tuple, negative: str | tuple, n_train: int = 150, n_eval: int = 50, template_fn: Callable[[list[dict]], str] | None = None) -> tuple[MuranoDataset, MuranoDataset]:Load contrastive datasets directly from HuggingFace Hub.
Args:
positive: HF source for positive class. Either:- A tuple of (dataset_name, config, column): (“walledai/HarmBench”, “standard”, “prompt”)- A tuple of (dataset_name, column): (“tatsu-lab/alpaca”, “instruction”)negative: HF source for negative class, same format as positive.n_train: Number of examples for the training split.n_eval: Number of examples for the evaluation split.template_fn: If provided, wraps each text in a chat template.
Returns:
- Tuple of (train_dataset, eval_dataset).
Raises:
ValueError: Ifpositiveornegativeis a malformed source- tuple, or the named column is missing from the loaded dataset.
Example:
- train_ds, eval_ds = MuranoDataset.from_hub(
- positive=(“walledai/HarmBench”, “standard”, “prompt”),
- negative=(“tatsu-lab/alpaca”, “instruction”),
- n_train=150, n_eval=50,
- template_fn=model.chat_template,
- )
contrastive
Section titled “contrastive”def contrastive(cls, positive: list[str], negative: list[str], template_fn: Callable[[list[dict]], str] | None = None) -> MuranoDataset:Create a contrastive dataset from paired text lists.
Args:
positive: Texts in the positive class (e.g., positive sentiment).negative: Texts in the negative class (e.g., negative sentiment).template_fn: If provided, wraps each text in a chat template.- Should accept a list of message dicts and return a string.
- Typically model.chat_template.
Returns:
- MuranoDataset with formatted texts.
LabeledDataset
Section titled “LabeledDataset”Dataset pairing texts with per-example integer labels.
Attributes:
texts: List of input strings (possibly chat-templated).labels: List of integer labels (0-indexed).label_names: Optional mapping from int to human-readable name.raw_texts: Original texts before chat template (None if no template).
Raises:
ValueError: Iftextsandlabelshave different lengths.
__init__
Section titled “__init__”def __init__(self, texts: list[str], labels: list[int], label_names: list[str] | None = None, raw_texts: list[str] | None = None):from_hub
Section titled “from_hub”def from_hub(cls, source: str | tuple, text_column: str = 'text', label_column: str = 'label', split: str = 'train', n: int | None = None, label_names: list[str] | None = None, template_fn: Callable[[list[dict]], str] | None = None) -> LabeledDataset:Load a labeled dataset from HuggingFace Hub.
Args:
source: Dataset name or (name, config) tuple.text_column: Column containing text.label_column: Column containing integer labels.split: Dataset split.n: Max examples (None = all).label_names: Optional label name list. If None, inferred from- dataset features if available.
template_fn: Optional chat template function.
Returns:
- LabeledDataset ready for use in a probing pipeline.
Raises:
ValueError: Iftext_columnorlabel_columnis missing- from the loaded dataset.
Example:
- ds = LabeledDataset.from_hub(
- “stanfordnlp/sst2”,
- text_column=“sentence”,
- label_column=“label”,
- n=500,
- label_names=[“negative”, “positive”],
- )
from_lists
Section titled “from_lists”def from_lists(cls, texts: list[str], labels: list[int], label_names: list[str] | None = None, template_fn: Callable[[list[dict]], str] | None = None) -> LabeledDataset:Create from Python lists.
Args:
texts: Input strings.labels: Integer labels.label_names: Optional label name list.template_fn: Optional chat template function.
Returns:
- LabeledDataset wrapping the supplied texts and labels.
CleanCorruptDataset
Section titled “CleanCorruptDataset”Matched clean and corrupt prompt pairs for causal experiments.
Holds index-paired inputs: clean[i] and corrupt[i] are one matched
example (for instance a factual prompt and its counterfactual). The pair
optionally carries the answer tokens used to score it, so it feeds the
logit-difference and recovered metrics directly; leave them None for a
distribution-only comparison such as KL.
Token-level position alignment between the two halves is required only by the consumers that patch or resample across them, which validate it themselves; this container only checks that the two sides, and any per-example answer list, have matching lengths.
Attributes:
clean: Clean prompts.corrupt: Corrupt prompts, paired withcleanby index.correct: Correct-answer spec for scoring, in the formsLogitDiffStepaccepts (a token id, a string, a per-example list- of either, or a tensor);
Noneif unset. incorrect: Incorrect-answer spec, in the same forms ascorrect.raw_clean: Clean prompts before chat templating (None if no template).raw_corrupt: Corrupt prompts before chat templating (None if no template).metadata: Arbitrary pair-level metadata.
Raises:
ValueError: Ifcleanandcorruptdiffer in length, or a- per-example answer list does not match the number of pairs.
__init__
Section titled “__init__”def __init__(self, clean: list[str], corrupt: list[str], correct: Any = None, incorrect: Any = None, raw_clean: list[str] | None = None, raw_corrupt: list[str] | None = None, metadata: dict | None = None):from_pairs
Section titled “from_pairs”def from_pairs(cls, clean: list[str], corrupt: list[str], correct: Any = None, incorrect: Any = None) -> CleanCorruptDataset:Create a paired dataset from matched clean and corrupt lists.
Args:
clean: Clean prompts.corrupt: Corrupt prompts, paired by index.correct: Optional correct-answer spec (see the class docstring).incorrect: Optional incorrect-answer spec.
Returns:
- The paired dataset.