syed-aliredha commited on
Commit
8af4610
Β·
verified Β·
1 Parent(s): ad0379e

Upload Creativity ITI components for LLaMA 3.1 8B

Browse files
Files changed (4) hide show
  1. README.md +171 -0
  2. iti_components.pkl +3 -0
  3. iti_config.json +0 -0
  4. requirements.txt +4 -0
README.md ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - inference-time-intervention
5
+ - code-generation
6
+ - creativity
7
+ - llama
8
+ - pytorch
9
+ datasets:
10
+ - neocoder
11
+ language:
12
+ - en
13
+ library_name: transformers
14
+ pipeline_tag: text-generation
15
+ base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
16
+ ---
17
+
18
+ # Creativity ITI for LLaMA 3.1 8B Instruct
19
+
20
+ ## 🎯 Model Description
21
+
22
+ This repository contains **Inference-Time Intervention (ITI)** components for enhancing creativity in code generation with LLaMA 3.1 8B Instruct.
23
+
24
+ ITI modifies model activations during inference to steer behavior without retraining - think of it as "creativity steering" for AI code generation.
25
+
26
+ ## πŸ“Š Key Results
27
+
28
+ - **68.8% test accuracy** in creativity detection
29
+ - **Optimal Ξ±=0.4** intervention strength
30
+ - **48 attention heads** identified for creativity
31
+ - Trained on **1058 coding problems** from NeoCoder
32
+
33
+ ## πŸš€ Quick Start
34
+
35
+ ### Installation
36
+
37
+ ```bash
38
+ pip install transformers torch numpy
39
+ ```
40
+
41
+ ### Basic Usage
42
+
43
+ ```python
44
+ import pickle
45
+ import json
46
+ import torch
47
+ from transformers import AutoTokenizer, AutoModelForCausalLM
48
+
49
+ # Load ITI components
50
+ with open('iti_config.json', 'r') as f:
51
+ config = json.load(f)
52
+
53
+ with open('iti_components.pkl', 'rb') as f:
54
+ components = pickle.load(f)
55
+
56
+ # Initialize model
57
+ model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
58
+ model = AutoModelForCausalLM.from_pretrained(
59
+ model_name,
60
+ torch_dtype=torch.float16,
61
+ device_map="auto"
62
+ )
63
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
64
+
65
+ # Apply ITI with Ξ±=0.4
66
+ alpha = config['metadata']['alpha']
67
+ directions = components['directions']
68
+ top_heads = components['top_heads']
69
+ ```
70
+
71
+ ## πŸ“ˆ Performance Metrics
72
+
73
+ | Metric | Value |
74
+ |--------|-------|
75
+ | Training Samples | 48 (balanced) |
76
+ | Validation Accuracy | 62.5% |
77
+ | Test Accuracy | 68.8% |
78
+ | Optimal Alpha (Ξ±) | 0.4 |
79
+ | Intervention Heads | 48 |
80
+ | Best Single Layer | Layer 3 |
81
+ | Top Head | Layer 17, Head 21 (AUC=0.734) |
82
+
83
+ ## πŸ”¬ Technical Details
84
+
85
+ ### How ITI Works
86
+
87
+ 1. **Probe Training**: Linear probes identify which attention heads correlate with creative code
88
+ 2. **Direction Finding**: Calculate "creativity directions" in activation space
89
+ 3. **Runtime Intervention**: During inference, shift activations by Ξ±=0.4 in creative direction
90
+ 4. **Result**: Model generates more innovative code solutions
91
+
92
+ ### File Contents
93
+
94
+ - `iti_config.json`: Configuration, metadata, and intervention directions
95
+ - `iti_components.pkl`: Binary format with top heads and directions
96
+ - `README.md`: This documentation
97
+
98
+ ## πŸ’‘ Example Output Comparison
99
+
100
+ **Problem**: "Check if a number is prime"
101
+
102
+ **Without ITI (Baseline):**
103
+ ```python
104
+ def is_prime(n):
105
+ if n <= 1:
106
+ return False
107
+ for i in range(2, n):
108
+ if n % i == 0:
109
+ return False
110
+ return True
111
+ ```
112
+
113
+ **With ITI (Ξ±=0.4):**
114
+ ```python
115
+ def is_prime(n):
116
+ return n > 1 and all(n % i for i in range(2, int(n**0.5) + 1))
117
+ ```
118
+
119
+ The ITI version is more concise and uses advanced techniques (generator expression, all()).
120
+
121
+ ## πŸ“š Dataset
122
+
123
+ Trained on the **NeoCoder** dataset:
124
+ - 1058 competitive programming problems
125
+ - Creativity labeled based on novel technique usage
126
+ - Only 4.3% of solutions were labeled as truly creative
127
+ - Balanced training set: 40 creative + 40 non-creative samples
128
+
129
+ ## πŸ—οΈ Implementation Details
130
+
131
+ ### Key Components
132
+
133
+ 1. **Top Heads**: 48 attention heads most predictive of creativity
134
+ 2. **Intervention Layers**: Distributed across layers 3-31
135
+ 3. **Direction Vectors**: 128-dimensional vectors per head
136
+ 4. **Activation Shift**: Applied to last token during generation
137
+
138
+ ## πŸ“– Citation
139
+
140
+ If you use this work, please cite:
141
+
142
+ ```bibtex
143
+ @article{li2023inference,
144
+ title={Inference-Time Intervention: Eliciting Truthful Answers from a Language Model},
145
+ author={Li, Kenneth and others},
146
+ journal={NeurIPS},
147
+ year={2023}
148
+ }
149
+ ```
150
+
151
+ ## πŸ™ Acknowledgments
152
+
153
+ - Original ITI paper authors (Li et al., 2023)
154
+ - NeoCoder dataset creators
155
+ - Meta AI for LLaMA 3.1
156
+ - NSCC Singapore for compute resources
157
+
158
+ ## πŸ“œ License
159
+
160
+ Apache 2.0 - See LICENSE file for details
161
+
162
+ ## ⚠️ Limitations
163
+
164
+ - Intervention may occasionally produce syntactically invalid code
165
+ - Effectiveness varies by problem complexity
166
+ - Requires LLaMA 3.1 8B model (not included)
167
+
168
+ ## πŸ”— Links
169
+
170
+ - [Original ITI Paper](https://arxiv.org/abs/2306.03341)
171
+ - [Base Model: LLaMA 3.1 8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct)
iti_components.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:560cbf82915fc4ce490b08f24dbe06e60f0ecfe915b3bc93431771d0ada978cc
3
+ size 17539
iti_config.json ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers>=4.30.0
2
+ torch>=2.0.0
3
+ numpy>=1.20.0
4
+ huggingface-hub>=0.16.0