Update README.md
Browse files
README.md
CHANGED
@@ -1,22 +1,136 @@
|
|
1 |
---
|
2 |
-
base_model: unsloth/meta-llama-3.1-8b-instruct-bnb-4bit
|
3 |
-
tags:
|
4 |
-
- text-generation-inference
|
5 |
-
- transformers
|
6 |
-
- unsloth
|
7 |
-
- llama
|
8 |
-
- trl
|
9 |
-
license: apache-2.0
|
10 |
language:
|
11 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
---
|
13 |
|
14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
- **License:** apache-2.0
|
18 |
-
- **Finetuned from model :** unsloth/meta-llama-3.1-8b-instruct-bnb-4bit
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
language:
|
3 |
- en
|
4 |
+
license: apache-2.0
|
5 |
+
datasets:
|
6 |
+
- semeval2014
|
7 |
+
tags:
|
8 |
+
- aspect-based-sentiment-analysis
|
9 |
+
- llama
|
10 |
+
- instructabsa
|
11 |
+
- alpaca
|
12 |
+
- unsloth
|
13 |
+
base_model:
|
14 |
+
- meta-llama/Llama-3.1-8B-Instruct
|
15 |
+
pipeline_tag: text-generation
|
16 |
+
library_name: transformers
|
17 |
---
|
18 |
|
19 |
+
# Aspect Extraction Model for Restaurant Reviews using Llama 3.1 8b
|
20 |
+
|
21 |
+
This repository contains a fine-tuned version of [unsloth/meta-llama-3.1-8b-instruct-bnb-4bit](https://huggingface.co/unsloth/meta-llama-3.1-8b-instruct-bnb-4bit), trained specifically for Aspect Extraction tasks using the **SemEval 2014 Restaurant Dataset**. The model employs the **InstructABSA** instruction prompt format combined with the **Alpaca** prompting structure, optimizing its performance on real-world restaurant review analysis.
|
22 |
+
|
23 |
+
## Model Overview
|
24 |
+
|
25 |
+
- **Base Model:** [unsloth/meta-llama-3.1-8b-instruct-bnb-4bit](https://huggingface.co/unsloth/meta-llama-3.1-8b-instruct-bnb-4bit)
|
26 |
+
- **Fine-tuning Dataset:** [SemEval 2014 Restaurant Dataset](https://alt.qcri.org/semeval2014/task4/)
|
27 |
+
- **Task:** Aspect Extraction
|
28 |
+
- **Prompt Format:** InstructABSA within Alpaca prompt format
|
29 |
+
|
30 |
+
## Performance Metrics
|
31 |
+
|
32 |
+
| Dataset | F1 Score |
|
33 |
+
|---------|----------|
|
34 |
+
| Train | 93.76% |
|
35 |
+
| Test | 94.03% |
|
36 |
+
|
37 |
+
## Use Cases
|
38 |
+
|
39 |
+
This model is well-suited for:
|
40 |
+
- **Research purposes:** Explore novel methodologies or validate existing theories in ABSA.
|
41 |
+
- **Real-world applications:** Deriving actionable insights from restaurant reviews for businesses, marketers, and product developers.
|
42 |
+
|
43 |
+
## Inference Speed
|
44 |
+
|
45 |
+
- **Approximate inference time:** ~1 second per review (tested on NVIDIA GPUs with 4-bit quantization).
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
## Installation
|
50 |
+
|
51 |
+
Install the required dependencies using pip:
|
52 |
+
|
53 |
+
```python
|
54 |
+
import os
|
55 |
+
if "COLAB_" not in "".join(os.environ.keys()):
|
56 |
+
!pip install unsloth
|
57 |
+
else:
|
58 |
+
# Do this only in Colab notebooks! Otherwise, use pip install unsloth
|
59 |
+
!pip install --no-deps bitsandbytes accelerate xformers==0.0.29 peft trl triton
|
60 |
+
!pip install --no-deps cut_cross_entropy unsloth_zoo
|
61 |
+
!pip install sentencepiece protobuf datasets huggingface_hub hf_transfer
|
62 |
+
!pip install --no-deps unsloth
|
63 |
+
|
64 |
+
```
|
65 |
+
## Example Usage
|
66 |
+
|
67 |
+
```python
|
68 |
+
from unsloth import FastLanguageModel
|
69 |
+
import torch
|
70 |
+
|
71 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
72 |
+
"RichardLu/Llama3_AE_res",
|
73 |
+
load_in_4bit=True,
|
74 |
+
max_seq_length=2048,
|
75 |
+
)
|
76 |
+
|
77 |
+
FastLanguageModel.for_inference(model)
|
78 |
+
|
79 |
+
# Define the instruction for aspect extraction
|
80 |
+
instructabsa_instruction = """Definition: The output will be the aspects (both implicit and explicit) which have an associated opinion that are extracted from the input text. In cases where there are no aspects the output should be noaspectterm.
|
81 |
+
Positive example 1-
|
82 |
+
input: I charge it at night and skip taking the cord with me because of the good battery life.
|
83 |
+
output: battery life
|
84 |
+
Positive example 2-
|
85 |
+
input: I even got my teenage son one, because of the features that it offers, like, iChat, Photobooth, garage band and more!.
|
86 |
+
output: features, iChat, Photobooth, garage band
|
87 |
+
Negative example 1-
|
88 |
+
input: Speaking of the browser, it too has problems.
|
89 |
+
output: browser
|
90 |
+
Negative example 2-
|
91 |
+
input: The keyboard is too slick.
|
92 |
+
output: keyboard
|
93 |
+
Neutral example 1-
|
94 |
+
input: I took it back for an Asus and same thing- blue screen which required me to remove the battery to reset.
|
95 |
+
output: battery
|
96 |
+
Neutral example 2-
|
97 |
+
input: Nightly my computer defrags itself and runs a virus scan.
|
98 |
+
output: virus scan
|
99 |
+
Now complete the following example:"""
|
100 |
+
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
101 |
+
### Instruction:
|
102 |
+
{}
|
103 |
+
### Input:
|
104 |
+
{}
|
105 |
+
### Response:
|
106 |
+
{}"""
|
107 |
+
|
108 |
+
prompt = alpaca_prompt.format(instructabsa_instruction, "Great food, good size menu, great service and an unpretensious setting.", "")
|
109 |
+
|
110 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
111 |
+
output_ids = model.generate(**inputs, max_new_tokens=128)
|
112 |
+
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
113 |
+
|
114 |
+
print(output_text.split("### Response:")[-1].strip())
|
115 |
+
```
|
116 |
+
|
117 |
+
## License
|
118 |
+
|
119 |
+
This model is intended for research and educational purposes. Please ensure proper citation if utilized in academic or industry research.
|
120 |
+
|
121 |
+
## Citation
|
122 |
|
123 |
+
If you utilize this model in your research, please cite it appropriately and reference this repository.
|
|
|
|
|
124 |
|
125 |
+
```bibtex
|
126 |
+
@misc{yourcitation2024,
|
127 |
+
author = {Lu Phone Maw},
|
128 |
+
title = {Aspect Extraction Model for Restaurant Reviews using Llama 3.1 8b},
|
129 |
+
year = {2025},
|
130 |
+
publisher = {Lu Phone Maw},
|
131 |
+
journal = {Hugging Face repository},
|
132 |
+
howpublished = {\url{https://huggingface.co/RichardLu/Llama3_AE_res}}
|
133 |
+
}
|
134 |
+
```
|
135 |
|
136 |
+
For any questions or feedback, please contact the repository maintainer.
|