TR-ABSA: Small Language Models
Collection
5 items • Updated
How to use osmankagankurnaz/gemma-4-2b-tr-ecommerce-absa with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-4-E2B-it")
model = PeftModel.from_pretrained(base_model, "osmankagankurnaz/gemma-4-2b-tr-ecommerce-absa")This model is fine-tuned on Turkish e-commerce clothing reviews to perform multi-aspect Aspect-Based Sentiment Analysis (ABSA). It uses the google/gemma-4-E2B-it architecture and was trained via the QLoRA technique. The model analyzes texts to directly extract "which aspect is expressed with which sentiment."
You can download and integrate the model directly from Hugging Face. The following code demonstrates how to call the model using the correct prompt template:
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the base model and tokenizer
base_model_id = "google/gemma-4-E2B-it"
peft_model_id = "YOUR_HUGGINGFACE_USERNAME/gemma_4_e2b_it_absa_finetuned" # Replace with your HF ID
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.bfloat16, device_map="auto")
# Load the fine-tuned LoRA adapter
model = PeftModel.from_pretrained(base_model, peft_model_id)
system_prompt = """You are an expert Aspect-Based Sentiment Analysis (ABSA) assistant for Turkish e-commerce.
Analyze reviews and extract aspects with sentiments (positive, negative, neutral).
Format: aspect|sentiment; aspect|sentiment
Provide ONLY the tags."""
review = "İndirimden 50 liraya kaptım fiyatına göre iyi ama kargo tam 2 haftada geldi."
messages = [
{"role": "user", "content": f"{system_prompt}\n\nReview: {review}"}
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to("cuda")
outputs = model.generate(inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
# Expected Output: price_value|positive; product_quality|neutral; shipping|negative