Metin commited on
Commit
a98e5fd
1 Parent(s): 8baa228

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +181 -36
README.md CHANGED
@@ -1,40 +1,185 @@
1
  ---
2
  license: llama3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
4
 
5
- "mmlu_tr_v0.2": {
6
- "acc,none": 0.4907571724341911,
7
- "acc_stderr,none": 0.0041653031800367325,
8
- "alias": "mmlu_tr_v0.2"
9
- },
10
- "arc_tr-v0.2": {
11
- "acc,none": 0.3856655290102389,
12
- "acc_stderr,none": 0.014224250973257174,
13
- "acc_norm,none": 0.4377133105802048,
14
- "acc_norm_stderr,none": 0.01449757388110829,
15
- "alias": "arc_tr-v0.2"
16
- }
17
- "gsm8k_tr-v0.2": {
18
- "exact_match,strict-match": 0.5322703113135915,
19
- "exact_match_stderr,strict-match": 0.013754209828259586,
20
- "exact_match,flexible-extract": 0.02050113895216401,
21
- "exact_match_stderr,flexible-extract": 0.003906276830067441,
22
- "alias": "gsm8k_tr-v0.2"
23
- }
24
- "truthfulqa_v0.2": {
25
- "acc,none": 0.4962330625424611,
26
- "acc_stderr,none": 0.015774923327963934,
27
- "alias": "truthfulqa_v0.2"
28
- }
29
- "hellaswag_tr-v0.2": {
30
- "acc,none": 0.36061871965676867,
31
- "acc_stderr,none": 0.005102526725540464,
32
- "acc_norm,none": 0.4485717511572767,
33
- "acc_norm_stderr,none": 0.005284959475720029,
34
- "alias": "hellaswag_tr-v0.2"
35
- }
36
- "winogrande_tr": {
37
- "acc,none": 0.5513428120063191,
38
- "acc_stderr,none": 0.013983726161361853,
39
- "alias": "winogrande_tr"
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: llama3
3
+ language:
4
+ - tr
5
+ pipeline_tag: text-generation
6
+ base_model: meta-llama/Meta-Llama-3-8B-Instruct
7
+
8
+ model-index:
9
+ - name: LLaMA-3-8B-Instruct-Abliterated-TR
10
+ results:
11
+ - task:
12
+ type: multiple-choice
13
+ dataset:
14
+ type: multiple-choice
15
+ name: MMLU_TR_V0.2
16
+ metrics:
17
+ - name: 5-shot
18
+ type: 5-shot
19
+ value: 0.4908
20
+ verified: false
21
+ - task:
22
+ type: multiple-choice
23
+ dataset:
24
+ type: multiple-choice
25
+ name: Truthful_QA_V0.2
26
+ metrics:
27
+ - name: 0-shot
28
+ type: 0-shot
29
+ value: 0.4962
30
+ verified: false
31
+ - task:
32
+ type: multiple-choice
33
+ dataset:
34
+ type: multiple-choice
35
+ name: ARC_TR_V0.2
36
+ metrics:
37
+ - name: 25-shot
38
+ type: 25-shot
39
+ value: 0.4377
40
+ verified: false
41
+ - task:
42
+ type: multiple-choice
43
+ dataset:
44
+ type: multiple-choice
45
+ name: HellaSwag_TR_V0.2
46
+ metrics:
47
+ - name: 10-shot
48
+ type: 10-shot
49
+ value: 0.4486
50
+ verified: false
51
+ - task:
52
+ type: multiple-choice
53
+ dataset:
54
+ type: multiple-choice
55
+ name: GSM8K_TR_V0.2
56
+ metrics:
57
+ - name: 5-shot
58
+ type: 5-shot
59
+ value: 0.5323
60
+ verified: false
61
+ - task:
62
+ type: multiple-choice
63
+ dataset:
64
+ type: multiple-choice
65
+ name: Winogrande_TR_V0.2
66
+ metrics:
67
+ - name: 5-shot
68
+ type: 5-shot
69
+ value: 0.5513
70
+ verified: false
71
  ---
72
 
73
+ <img src=""
74
+ alt="A Llama with a band-aid on its head." width="420"/>
75
+
76
+ # What is abliteration?
77
+ Arditi et al. demonstrated in their [blog post](https://www.lesswrong.com/posts/jGuXSZgv6qfdhMCuJ/refusal-in-llms-is-mediated-by-a-single-direction) that refusal in LLMs is mediated by a single direction in the residual stream. They found that preventing the model from representing this direction can enable it to answer harmful questions. For a deeper understanding of this concept, you can refer to [Maxime Labonne's article](https://huggingface.co/blog/mlabonne/abliteration) on the topic.
78
+
79
+ To force the model to respond in Turkish, parallel instructions were crafted using the [stackexchange subset](https://huggingface.co/datasets/GAIR/lima/viewer/plain_text/train?f[source][value]=%27stackexchange%27) of the LIMA dataset. These instructions were then translated into Turkish, with an additional sentence appended during runtime, prompting the model to answer in Turkish.
80
+
81
+ You can find the datasets used in this experiment via the following links:
82
+
83
+ 1. https://huggingface.co/datasets/Metin/abliteration_en
84
+ 2. https://huggingface.co/datasets/Metin/abliteration_tr
85
+
86
+ # LLaMA-3-8B-Instruct-Abliterated-TR
87
+
88
+ LLaMA-3-8B-Instruct-Abliterated-TR is the abliterated version of [Meta-LLaMA-3-8B-Instruct](https://huggingface.co/meta-llama/meta-llama-3-8b-instruct)
89
+
90
+ ## Details:
91
+
92
+ - 40 samples were used to find the difference of means between activations.
93
+ - Layer 7 is selected as the layer with the highest potential Turkish speaking direction.
94
+
95
+ ## How to use
96
+
97
+ You can use the below code snippet to use the model:
98
+
99
+ ```python
100
+ from transformers import BitsAndBytesConfig
101
+ import transformers
102
+ import torch
103
+
104
+ bnb_config = BitsAndBytesConfig(
105
+ load_in_4bit=True,
106
+ bnb_4bit_use_double_quant=True,
107
+ bnb_4bit_quant_type="nf4",
108
+ bnb_4bit_compute_dtype=torch.bfloat16
109
+ )
110
+
111
+ model_id = "Metin/LLaMA-3-8B-Instruct-Abliterated-TR"
112
+
113
+ pipeline = transformers.pipeline(
114
+ "text-generation",
115
+ model=model_id,
116
+ model_kwargs={"torch_dtype": torch.bfloat16 ,'quantization_config': bnb_config},
117
+ device_map="auto",
118
+ )
119
+
120
+ messages = [
121
+ {"role": "system", "content": "You are a helpful assistant."}, # Ideally we should not have to tell the model to answer in Turkish after abliteration.
122
+ {"role": "user", "content": "Python'da bir öğenin bir listede geçip geçmediğini nasıl kontrol edebilirim?"},
123
+ ]
124
+
125
+ prompt = pipeline.tokenizer.apply_chat_template(
126
+ messages,
127
+ tokenize=False,
128
+ add_generation_prompt=True
129
+ )
130
+
131
+ terminators = [
132
+ pipeline.tokenizer.eos_token_id,
133
+ pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
134
+ ]
135
+
136
+ outputs = pipeline(
137
+ prompt,
138
+ max_new_tokens=512,
139
+ eos_token_id=terminators,
140
+ do_sample=True,
141
+ temperature=0.2,
142
+ top_p=0.9,
143
+ )
144
+
145
+ print(outputs[0]["generated_text"][len(prompt):])
146
+ ```
147
+
148
+ ## OpenLLMTurkishLeaderboard_v0.2 benchmark results
149
+
150
+ - **MMLU_TR_V0.2**: 49.08%
151
+ - **Truthful_QA_TR_V0.2**: 49.62%
152
+ - **ARC_TR_V0.2**: 43.77%
153
+ - **HellaSwag_TR_V0.2**: 44.86%
154
+ - **GSM8K_TR_V0.2**: 53.23%
155
+ - **Winogrande_TR_V0.2**: 55.13%
156
+ - **Average**: 49.28%
157
+
158
+ These scores may differ from what you will get when you run the same benchmarks, as I did not use any inference engine (vLLM, TensorRT-LLM, etc.)
159
+
160
+ ## Output Example (Abliterated Model vs Base Model)
161
+
162
+ Testing the model with a single example is not an accurate method. However, an example is provided here to showcase the model's capabilities.
163
+
164
+ ### Model: LLaMA-3-8B-Instruct-Abliterated-TR
165
+
166
+ #### Input
167
+
168
+ ```plaintext
169
+ TODO
170
+ ```
171
+
172
+ #### Output
173
+
174
+ ```plaintext
175
+ TODO
176
+ ```
177
+
178
+ ### Model: LLaMA-3-8B-Instruct
179
+
180
+ #### Input
181
+
182
+ ```plaintext
183
+ TODO
184
+ ```
185
+