Views
No views yet
pip install transformers torch numpy1import pickle
2import json
3import torch
4from transformers import AutoTokenizer, AutoModelForCausalLM
5
6# Load ITI components
7with open('iti_config.json', 'r') as f:
8 config = json.load(f)
9
10with open('iti_components.pkl', 'rb') as f:
11 components = pickle.load(f)
12
13# Initialize model
14model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
15model = AutoModelForCausalLM.from_pretrained(
16 model_name,
17 torch_dtype=torch.float16,
18 device_map="auto"
19)
20tokenizer = AutoTokenizer.from_pretrained(model_name)
21
22# Apply ITI with α=0.4
23alpha = config['metadata']['alpha']
24directions = components['directions']
25top_heads = components['top_heads']| 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) |
iti_config.json: Configuration, metadata, and intervention directionsiti_components.pkl: Binary format with top heads and directionsREADME.md: This documentation1def is_prime(n):
2 if n <= 1:
3 return False
4 for i in range(2, n):
5 if n % i == 0:
6 return False
7 return True1def is_prime(n):
2 return n > 1 and all(n % i for i in range(2, int(n**0.5) + 1))1@article{li2023inference,
2 title={Inference-Time Intervention: Eliciting Truthful Answers from a Language Model},
3 author={Li, Kenneth and others},
4 journal={NeurIPS},
5 year={2023}
6}