This repository contains a fine-tuned version of
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.
1import os
2if "COLAB_" not in "".join(os.environ.keys()):
3 !pip install unsloth
4else:
5 # Do this only in Colab notebooks! Otherwise, use pip install unsloth
6 !pip install --no-deps bitsandbytes accelerate xformers==0.0.29 peft trl triton
7 !pip install --no-deps cut_cross_entropy unsloth_zoo
8 !pip install sentencepiece protobuf datasets huggingface_hub hf_transfer
9 !pip install --no-deps unsloth
10
11!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir --no-deps git+https://github.com/unslothai/unsloth.git
12
1from unsloth import FastLanguageModel
2import torch
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 "RichardLu/Llama3_AE_res",
6 load_in_4bit=True,
7 max_seq_length=2048,
8)
9
10FastLanguageModel.for_inference(model)
11
12# Define the instruction for aspect extraction
13instructabsa_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.
14Positive example 1-
15input: With the great variety on the menu, I eat here often and never get bored.
16output: menu
17Positive example 2-
18input: Great food, good size menu, great service and an unpretensious setting.
19output: food, menu, service, setting
20Negative example 1-
21input: 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.
22output: toast, mayonnaise, bacon, ingredients, plate
23Negative example 2-
24input: The seats are uncomfortable if you are sitting against the wall on wooden benches.
25output: seats
26Neutral example 1-
27input: I asked for seltzer with lime, no ice.
28output: seltzer with lime
29Neutral example 2-
30input: They wouldnt even let me finish my glass of wine before offering another.
31output: glass of wine
32Now complete the following example:"""
33alpaca_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.
34### Instruction:
35{}
36### Input:
37{}
38### Response:
39{}"""
40
41prompt = alpaca_prompt.format(instructabsa_instruction, "Great food, good size menu, great service and an unpretensious setting.", "")
42
43inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
44output_ids = model.generate(**inputs, max_new_tokens=128)
45output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
46
47print(output_text.split("### Response:")[-1].strip())
This model is intended for research and educational purposes. Please ensure proper citation if utilized in academic or industry research.
If you utilize this model in your research, please cite it appropriately and reference this repository.
1@misc{yourcitation2024,
2 author = {Lu Phone Maw},
3 title = {Aspect Extraction Model for Restaurant Reviews using Llama 3.1 8b},
4 year = {2025},
5 publisher = {Lu Phone Maw},
6 journal = {Hugging Face repository},
7 howpublished = {\url{https://huggingface.co/RichardLu/Llama3_AE_res}}
8}
For any questions or feedback, please contact the repository maintainer.