psimm commited on
Commit
b4dcdd9
1 Parent(s): 4170981

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -5
README.md CHANGED
@@ -117,17 +117,46 @@ It achieves the following results on the evaluation set:
117
  - Loss: 0.0695
118
  - F1 Score: 83.14
119
 
 
 
 
 
 
 
 
 
120
  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.
121
 
122
- For more details, see my [article](https://simmering.dev/open-absa)
 
 
123
 
124
- ## Model description
 
125
 
126
- More information needed
 
127
 
128
- ## Intended uses & limitations
129
 
130
- 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]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  ## Training and evaluation data
133
 
 
117
  - Loss: 0.0695
118
  - F1 Score: 83.14
119
 
120
+ For more details, see my [article](https://simmering.dev/open-absa)
121
+
122
+ ## Intended uses & limitations
123
+
124
+ 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]
125
+
126
+ ## How to run
127
+
128
  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.
129
 
130
+ ```python
131
+ from peft import PeftModel
132
+ from transformers import AutoModelForCausalLM, AutoTokenizer
133
 
134
+ extra_tokens = ["[INST]", "[/INST]"]
135
+ base_model = "NousResearch/Meta-Llama-3-8B"
136
 
137
+ base_model = AutoModelForCausalLM.from_pretrained("NousResearch/Meta-Llama-3-8B")
138
+ base_model.resize_token_embeddings(base_model.config.vocab_size + len(extra_tokens))
139
 
140
+ tokenizer = AutoTokenizer.from_pretrained("NousResearch/Meta-Llama-3-8B")
141
 
142
+ tokenizer.add_special_tokens({"additional_special_tokens": extra_tokens})
143
+
144
+ model = PeftModel.from_pretrained(base_model, "psimm/llama-3-8B-semeval2014")
145
+
146
+ input_text = "[INST]The food was tasty[/INST]"
147
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids
148
+
149
+ gen_tokens = model.generate(
150
+ input_ids,
151
+ max_length=256,
152
+ temperature=0.01,
153
+ )
154
+
155
+ # Remove the input tokens
156
+ output_tokens = gen_tokens[:, input_ids.shape[1] :]
157
+
158
+ print(tokenizer.batch_decode(output_tokens, skip_special_tokens=True))
159
+ ```
160
 
161
  ## Training and evaluation data
162