Creativity ITI for LLaMA 3.1 8B Instruct
π― Model Description
This repository contains Inference-Time Intervention (ITI) components for enhancing creativity in code generation with LLaMA 3.1 8B Instruct.
ITI modifies model activations during inference to steer behavior without retraining - think of it as "creativity steering" for AI code generation.
π Key Results
- 68.8% test accuracy in creativity detection
- Optimal Ξ±=0.4 intervention strength
- 48 attention heads identified for creativity
- Trained on 1058 coding problems from NeoCoder
π Quick Start
Installation
pip install transformers torch numpy
Basic Usage
import pickle
import json
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load ITI components
with open('iti_config.json', 'r') as f:
config = json.load(f)
with open('iti_components.pkl', 'rb') as f:
components = pickle.load(f)
# Initialize model
model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Apply ITI with Ξ±=0.4
alpha = config['metadata']['alpha']
directions = components['directions']
top_heads = components['top_heads']
π Performance Metrics
| Metric | Value |
|---|---|
| Training Samples | 48 (balanced) |
| Validation Accuracy | 62.5% |
| Test Accuracy | 68.8% |
| Optimal Alpha (Ξ±) | 0.4 |
| Intervention Heads | 48 |
| Best Single Layer | Layer 3 |
| Top Head | Layer 17, Head 21 (AUC=0.734) |
π¬ Technical Details
How ITI Works
- Probe Training: Linear probes identify which attention heads correlate with creative code
- Direction Finding: Calculate "creativity directions" in activation space
- Runtime Intervention: During inference, shift activations by Ξ±=0.4 in creative direction
- Result: Model generates more innovative code solutions
File Contents
iti_config.json: Configuration, metadata, and intervention directionsiti_components.pkl: Binary format with top heads and directionsREADME.md: This documentation
π‘ Example Output Comparison
Problem: "Check if a number is prime"
Without ITI (Baseline):
def is_prime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
With ITI (Ξ±=0.4):
def is_prime(n):
return n > 1 and all(n % i for i in range(2, int(n**0.5) + 1))
The ITI version is more concise and uses advanced techniques (generator expression, all()).
π Dataset
Trained on the NeoCoder dataset:
- 1058 competitive programming problems
- Creativity labeled based on novel technique usage
- Only 4.3% of solutions were labeled as truly creative
- Balanced training set: 40 creative + 40 non-creative samples
ποΈ Implementation Details
Key Components
- Top Heads: 48 attention heads most predictive of creativity
- Intervention Layers: Distributed across layers 3-31
- Direction Vectors: 128-dimensional vectors per head
- Activation Shift: Applied to last token during generation
π Citation
If you use this work, please cite:
@article{li2023inference,
title={Inference-Time Intervention: Eliciting Truthful Answers from a Language Model},
author={Li, Kenneth and others},
journal={NeurIPS},
year={2023}
}
π Acknowledgments
- Original ITI paper authors (Li et al., 2023)
- NeoCoder dataset creators
- Meta AI for LLaMA 3.1
- NSCC Singapore for compute resources
π License
Apache 2.0 - See LICENSE file for details
β οΈ Limitations
- Intervention may occasionally produce syntactically invalid code
- Effectiveness varies by problem complexity
- Requires LLaMA 3.1 8B model (not included)
π Links
Model tree for syed-aliredha/creativity-iti-llama31-8b
Base model
meta-llama/Llama-3.1-8B
Finetuned
meta-llama/Llama-3.1-8B-Instruct