This repository contains the code accompanying the paper:
Want Better Synthetic Data? Steer It: Activation Steering for Low-Resource Language Generation
- Language Steering — steering generation toward the linguistic identity of a target language.
- Quality Steering — steering generation toward higher-quality / more natural generations using contrastive activation vectors.
The repository includes:
- scripts for creating contrastive datasets,
- scripts for collecting activations and building steering vectors,
- generation pipelines for steered and non-steered generation,
- downstream fine-tuning scripts,
- preprocessing utilities.
.
├── create_contrast_data/
├── create_steer_vecs/
├── finetune_downstream/
├── steering_gen_llms/
├── create_steer_vector_alt.py
├── preprocess_sentiment.py
├── preprocess_topic.py
├── requirements.txt
└── Synthetic_data_steering_vectors.pdf
The repository intentionally omits several large files due to repository and attachment size limits:
- Generated synthetic datasets
- Human-written datasets
- Precomputed steering vectors
- Full experimental outputs
These resources will be added after acceptance.
The generation scripts provided in this repository are intended as examples/templates demonstrating how experiments were run.
The repository does not contain exhaustive scripts for every configuration reported in the paper. Instead, it includes representative examples for:
- Zero-shot generation
- Few-shot generation
- Language steering vectors
- Quality steering vectors
These can be adapted for additional languages, models, and experimental settings.
python -m venv venv
source venv/bin/activatepip install -r requirements.txtDirectory:
create_contrast_data/
This directory contains scripts used to create contrastive data pairs for steering vector construction.
Creates paired datasets used for activation contrast experiments.
Typical usage:
- constructing positive/negative examples,
- preparing text pairs,
- formatting data for activation extraction.
Performs backtranslation-based processing used for quality steering experiments.
This script is used to generate lower-quality or transformed variants of text for contrastive activation collection.
Directory:
create_steer_vecs/
This directory contains the core pipeline for:
- collecting activations,
- computing steering vectors,
- preparing vectors for generation.
Collects hidden-state activations for quality steering experiments.
Used to:
- process contrastive datasets,
- extract activations from target LLMs,
- save activations for later vector computation.
Collects activations for language steering and creates steering vectors directly.
Used for:
- language identity steering,
- multilingual activation extraction,
- vector generation.
Builds quality steering vectors from previously collected activations.
Typically computes:
- mean activation differences,
- contrastive steering directions.
Example end-to-end pipeline for:
- collecting activations,
- computing language steering vectors.
Example end-to-end pipeline for:
- creating contrastive pairs,
- collecting activations,
- computing quality steering vectors.
Contains example contrastive data pairs used for language steering experiments.
Example files:
pairs_flor_de.json
pairs_flor_cs.json
pairs_flor_he.json
...
These correspond to language-specific contrastive examples.
Directory:
steering_gen_llms/
This directory contains scripts for generating synthetic datasets using steered LLM inference.
The scripts support:
- Gemma-based models,
- LLaMA-based models,
- zero-shot prompting,
- few-shot prompting,
- language steering,
- quality steering.
Example sentiment-generation pipeline using:
- Gemma models,
- language steering vectors.
Example sentiment-generation pipeline using:
- LLaMA models.
Example topic-generation pipeline using:
- Gemma,
- in-context learning (few-shot prompting).
Example topic-generation pipeline using:
- LLaMA,
- language steering,
- few-shot prompting.
Example orchestration script for:
- generation,
- steering,
- downstream fine-tuning,
using:
- Gemma,
- quality steering vectors,
- one target language.
Equivalent orchestration pipeline for:
- LLaMA,
- language steering vectors.
Inference script for steered generation with Gemma models.
Gemma inference with:
- steering,
- in-context learning / few-shot prompting.
Inference script for steered generation with LLaMA models.
LLaMA inference with:
- steering,
- few-shot prompting.
Directory:
finetune_downstream/
Contains scripts for training downstream classifiers on generated datasets.
Main fine-tuning script used for downstream classification experiments.
Typical tasks include:
- sentiment classification,
- topic classification.
Example fine-tuning command script.
Additional fine-tuning examples/configurations.
Preprocessing utilities for sentiment datasets.
Typical functionality:
- formatting labels,
- cleaning generations,
- converting datasets into training format.
Preprocessing utilities for topic-classification datasets.