File size: 5,849 Bytes
e02a6c9
 
 
 
 
 
 
 
 
 
cb739d2
 
 
 
e02a6c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2986b3e
e02a6c9
 
0f21bc0
9e10e2e
b4dcdd9
 
 
 
 
 
 
 
975a1bc
 
b4dcdd9
 
 
e02a6c9
b4dcdd9
 
e02a6c9
b4dcdd9
 
e02a6c9
b4dcdd9
e02a6c9
b4dcdd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e02a6c9
 
 
cb739d2
e02a6c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
---
license: other
library_name: peft
tags:
- axolotl
- generated_from_trainer
base_model: NousResearch/Meta-Llama-3-8B
model-index:
- name: llama-3-8B-semeval2014
  results: []
language:
- en
metrics:
- f1
---

<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

[<img src="https://raw.githubusercontent.com/OpenAccess-AI-Collective/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/OpenAccess-AI-Collective/axolotl)
<details><summary>See axolotl config</summary>

axolotl version: `0.4.0`
```yaml
base_model: NousResearch/Meta-Llama-3-8B

load_in_8bit: false
load_in_4bit: false
strict: false

datasets:
  - path: semeval2014_train.jsonl
    ds_type: json
    type:
      # JSONL file contains instruction, input, output fields per line.
      # This gets mapped to the equivalent axolotl tags.
      field_instruction: instruction
      field_input: input
      field_output: output
      # Format is used by axolotl to generate the prompt.
      format: |-
        [INST] {input} [/INST]

tokens: # add new control tokens from the dataset to the model
  - "[INST]"
  - "[/INST]"

dataset_prepared_path:
val_set_size: 0.05
output_dir: ./lora-out

sequence_len: 4096
sample_packing: false
eval_sample_packing: false
pad_to_sequence_len: false

adapter: lora
lora_model_dir:
lora_r: 16
lora_alpha: 32
lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:
lora_modules_to_save: # required when adding new tokens to LLaMA/Mistral
  - embed_tokens
  - lm_head

wandb_project: absa-semeval2014
wandb_entity: psimm
wandb_log_model:
wandb_name: llama-3-8B-semeval2014

hub_model_id: psimm/llama-3-8B-semeval2014

gradient_accumulation_steps: 1
micro_batch_size: 32
num_epochs: 4
optimizer: adamw_torch
lr_scheduler: cosine
learning_rate: 0.0001

train_on_inputs: false
group_by_length: false
bf16: true
fp16: false
tf32: false

gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true

warmup_steps: 10
eval_steps: 0.05
eval_table_size:
eval_table_max_new_tokens: 128
save_steps:
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:
  pad_token: <|end_of_text|>

```

</details><br>

# llama-3-8B-semeval2014

This model is a fine-tuned version of [NousResearch/Meta-Llama-3-8B](https://huggingface.co/NousResearch/Meta-Llama-3-8B) on the SemEval2014 Task 4 dataset.
It achieves the following results on the evaluation set:
- Loss: 0.0695
- F1 Score: 82.13

For more details, see my [article](https://simmering.dev/open-absa)

## Intended uses & limitations

Aspect-based sentiment analysis in English. Pass it review sentences wrapped in tags, like this: [INST]The cheeseburger was tasty but the fries were soggy.[/INST]

## How to run

This adapter requires that two new tokens are added to the tokenizer. The tokens are: "[INST]" and "[/INST]". Also, the base model's embedding layer size has to be increased by 2.

```python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

extra_tokens = ["[INST]", "[/INST]"]
base_model = "NousResearch/Meta-Llama-3-8B"

base_model = AutoModelForCausalLM.from_pretrained("NousResearch/Meta-Llama-3-8B")
base_model.resize_token_embeddings(base_model.config.vocab_size + len(extra_tokens))

tokenizer = AutoTokenizer.from_pretrained("NousResearch/Meta-Llama-3-8B")

tokenizer.add_special_tokens({"additional_special_tokens": extra_tokens})

model = PeftModel.from_pretrained(base_model, "psimm/llama-3-8B-semeval2014")

input_text = "[INST]The food was tasty[/INST]"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids

gen_tokens = model.generate(
    input_ids,
    max_length=256,
    temperature=0.01,
)

# Remove the input tokens
output_tokens = gen_tokens[:, input_ids.shape[1] :]

print(tokenizer.batch_decode(output_tokens, skip_special_tokens=True))
```

## Training and evaluation data

SemEval 2014 Task 4 reviews.

## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 0.0001
- train_batch_size: 32
- eval_batch_size: 32
- seed: 42
- distributed_type: multi-GPU
- num_devices: 2
- total_train_batch_size: 64
- total_eval_batch_size: 64
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: cosine
- lr_scheduler_warmup_steps: 10
- num_epochs: 4

### Training results

| Training Loss | Epoch  | Step | Validation Loss |
|:-------------:|:------:|:----:|:---------------:|
| 2.5408        | 0.0112 | 1    | 2.2742          |
| 0.1159        | 0.2022 | 18   | 0.1026          |
| 0.1028        | 0.4045 | 36   | 0.0762          |
| 0.0813        | 0.6067 | 54   | 0.0709          |
| 0.0908        | 0.8090 | 72   | 0.0665          |
| 0.0431        | 1.0112 | 90   | 0.0639          |
| 0.0275        | 1.2135 | 108  | 0.0663          |
| 0.0224        | 1.4157 | 126  | 0.0659          |
| 0.0349        | 1.6180 | 144  | 0.0637          |
| 0.0281        | 1.8202 | 162  | 0.0589          |
| 0.0125        | 2.0225 | 180  | 0.0592          |
| 0.0088        | 2.2247 | 198  | 0.0682          |
| 0.0076        | 2.4270 | 216  | 0.0666          |
| 0.01          | 2.6292 | 234  | 0.0654          |
| 0.0131        | 2.8315 | 252  | 0.0704          |
| 0.0075        | 3.0337 | 270  | 0.0679          |
| 0.002         | 3.2360 | 288  | 0.0688          |
| 0.0029        | 3.4382 | 306  | 0.0692          |
| 0.0009        | 3.6404 | 324  | 0.0694          |
| 0.0064        | 3.8427 | 342  | 0.0695          |


### Framework versions

- PEFT 0.10.0
- Transformers 4.40.2
- Pytorch 2.2.2+cu121
- Datasets 2.19.1
- Tokenizers 0.19.1