|
--- |
|
language: |
|
- en |
|
license: apache-2.0 |
|
datasets: |
|
- semeval2014 |
|
tags: |
|
- aspect-based-sentiment-analysis |
|
- llama |
|
- instructabsa |
|
- alpaca |
|
- unsloth |
|
base_model: |
|
- meta-llama/Llama-3.1-8B-Instruct |
|
pipeline_tag: text-generation |
|
library_name: transformers |
|
--- |
|
|
|
# Aspect Extraction Model for Restaurant Reviews using Llama 3.1 8b |
|
|
|
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. |
|
|
|
## Model Overview |
|
|
|
- **Base Model:** [unsloth/meta-llama-3.1-8b-instruct-bnb-4bit](https://huggingface.co/unsloth/meta-llama-3.1-8b-instruct-bnb-4bit) |
|
- **Fine-tuning Dataset:** [SemEval 2014 Restaurant Dataset](https://alt.qcri.org/semeval2014/task4/) |
|
- **Task:** Aspect Extraction |
|
- **Prompt Format:** InstructABSA within Alpaca prompt format |
|
|
|
## Performance Metrics |
|
|
|
| Dataset | F1 Score | |
|
|---------|----------| |
|
| Train | 93.76% | |
|
| Test | 94.03% | |
|
|
|
## Use Cases |
|
|
|
This model is well-suited for: |
|
- **Research purposes:** Explore novel methodologies or validate existing theories in ABSA. |
|
- **Real-world applications:** Deriving actionable insights from restaurant reviews for businesses, marketers, and product developers. |
|
|
|
## Inference Speed |
|
|
|
- **Approximate inference time:** ~1 second per review (tested on NVIDIA GPUs with 4-bit quantization). |
|
|
|
|
|
|
|
## Installation |
|
|
|
Install the required dependencies using pip: |
|
|
|
```python |
|
import os |
|
if "COLAB_" not in "".join(os.environ.keys()): |
|
!pip install unsloth |
|
else: |
|
# Do this only in Colab notebooks! Otherwise, use pip install unsloth |
|
!pip install --no-deps bitsandbytes accelerate xformers==0.0.29 peft trl triton |
|
!pip install --no-deps cut_cross_entropy unsloth_zoo |
|
!pip install sentencepiece protobuf datasets huggingface_hub hf_transfer |
|
!pip install --no-deps unsloth |
|
|
|
``` |
|
## Example Usage |
|
|
|
```python |
|
from unsloth import FastLanguageModel |
|
import torch |
|
|
|
model, tokenizer = FastLanguageModel.from_pretrained( |
|
"RichardLu/Llama3_AE_res", |
|
load_in_4bit=True, |
|
max_seq_length=2048, |
|
) |
|
|
|
FastLanguageModel.for_inference(model) |
|
|
|
# Define the instruction for aspect extraction |
|
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. |
|
Positive example 1- |
|
input: With the great variety on the menu, I eat here often and never get bored. |
|
output: menu |
|
Positive example 2- |
|
input: Great food, good size menu, great service and an unpretensious setting. |
|
output: food, menu, service, setting |
|
Negative example 1- |
|
input: They did not have mayonnaise, forgot our toast, left out ingredients (ie cheese in an omelet), below hot temperatures and the bacon was so over cooked it crumbled on the plate when you touched it. |
|
output: toast, mayonnaise, bacon, ingredients, plate |
|
Negative example 2- |
|
input: The seats are uncomfortable if you are sitting against the wall on wooden benches. |
|
output: seats |
|
Neutral example 1- |
|
input: I asked for seltzer with lime, no ice. |
|
output: seltzer with lime |
|
Neutral example 2- |
|
input: They wouldnt even let me finish my glass of wine before offering another. |
|
output: glass of wine |
|
Now complete the following example:""" |
|
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. |
|
### Instruction: |
|
{} |
|
### Input: |
|
{} |
|
### Response: |
|
{}""" |
|
|
|
prompt = alpaca_prompt.format(instructabsa_instruction, "Great food, good size menu, great service and an unpretensious setting.", "") |
|
|
|
inputs = tokenizer(prompt, return_tensors="pt").to("cuda") |
|
output_ids = model.generate(**inputs, max_new_tokens=128) |
|
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True) |
|
|
|
print(output_text.split("### Response:")[-1].strip()) |
|
``` |
|
|
|
## License |
|
|
|
This model is intended for research and educational purposes. Please ensure proper citation if utilized in academic or industry research. |
|
|
|
## Citation |
|
|
|
If you utilize this model in your research, please cite it appropriately and reference this repository. |
|
|
|
```bibtex |
|
@misc{yourcitation2024, |
|
author = {Lu Phone Maw}, |
|
title = {Aspect Extraction Model for Restaurant Reviews using Llama 3.1 8b}, |
|
year = {2025}, |
|
publisher = {Lu Phone Maw}, |
|
journal = {Hugging Face repository}, |
|
howpublished = {\url{https://huggingface.co/RichardLu/Llama3_AE_res}} |
|
} |
|
``` |
|
|
|
For any questions or feedback, please contact the repository maintainer. |