Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# Load base model
6base_model = AutoModelForCausalLM.from_pretrained(
7 "meta-llama/Llama-3.2-3B-Instruct",
8 torch_dtype=torch.float16,
9 low_cpu_mem_usage=True
10)
11
12# Load tokenizer
13tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
14
15# Load LoRA adapter
16peft_model = PeftModel.from_pretrained(base_model, "opdullah/Llama-3.2-3B-tr-ABSA")
17
18# Example review
19review = "Bu telefonun arka kamerasını beğendim ama bataryası yetersiz."
20
21# Prepare input
22messages = [{"role": "user", "content": review}]
23inp = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
24input_ids = tokenizer(inp, return_tensors="pt")["input_ids"].to("cuda")
25
26# Generate output
27outputs = peft_model.generate(input_ids, max_new_tokens=1024)
28result = tokenizer.decode(outputs[0]).split("<|start_header_id|>assistant<|end_header_id|>")[-1]
29
30print(result)[{"term": "arka kamerasını", "polarity": "positive"}, {"term": "bataryası", "polarity": "negative"}]1[
2 {
3 "term": "aspect_term_in_turkish",
4 "polarity": "positive|negative|neutral"
5 }
6][{"term": "arka kamerasını", "polarity": "positive"}, {"term": "bataryası", "polarity": "negative"}][{"term": "fiyatı", "polarity": "positive"}, {"term": "kalitesi", "polarity": "negative"}][{"term": "teslimat hızı", "polarity": "positive"}, {"term": "ambalaj", "polarity": "positive"}]torch>=2.0.0
transformers>=4.36.0
peft>=0.7.0
accelerate>=0.25.0@misc{llama-turkish-absa,
title={Llama-3.2-3B Turkish ABSA},
author={Abdullah Koçak},
year={2025},
url={https://huggingface.co/opdullah/Llama-3.2-3B-tr-ABSA}
}@misc{llama3.2,
title={Llama 3.2: Revolutionizing edge AI and vision with open, customizable models},
author={Meta},
year={2024},
publisher={Meta AI},
url={https://ai.meta.com/blog/llama-3-2-connect-2024-vision-edge-mobile-devices/}
}