allegro/klej-allegro-reviews
Viewer • Updated • 11.6k • 399 • 1
How to use rafal-adamczyk/herbert-polish-sentiment-lora with PEFT:
from peft import PeftModel
from transformers import AutoModelForSequenceClassification
base_model = AutoModelForSequenceClassification.from_pretrained("allegro/herbert-base-cased")
model = PeftModel.from_pretrained(base_model, "rafal-adamczyk/herbert-polish-sentiment-lora")How to use rafal-adamczyk/herbert-polish-sentiment-lora with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="rafal-adamczyk/herbert-polish-sentiment-lora") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("rafal-adamczyk/herbert-polish-sentiment-lora", device_map="auto")This is a LoRA fine-tuned version of allegro/herbert-base-cased for Polish sentiment analysis.
0: Positive1: Neutral2: NegativeLoraConfig(
task_type=TaskType.SEQ_CLS,
r=16,
lora_alpha=32,
target_modules=["query", "value"],
lora_dropout=0.01,
bias="none"
)
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from peft import PeftModel, PeftConfig
import torch
# Load configuration
config = PeftConfig.from_pretrained("YOUR_USERNAME/{REPO_NAME}")
# Load base model
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
base_model = AutoModelForSequenceClassification.from_pretrained(
config.base_model_name_or_path,
num_labels=3,
id2label={{0: "positive", 1: "neutral", 2: "negative"}},
label2id={{"positive": 0, "neutral": 1, "negative": 2}}
)
# Load LoRA adapters
model = PeftModel.from_pretrained(base_model, "YOUR_USERNAME/{REPO_NAME}")
model.eval()
# Predict
def predict(text):
inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
predicted_class = logits.argmax(dim=-1).item()
probabilities = torch.softmax(logits, dim=-1)[0]
return {{
"label": model.config.id2label[predicted_class],
"confidence": probabilities[predicted_class].item(),
"probabilities": {{
"positive": probabilities[0].item(),
"neutral": probabilities[1].item(),
"negative": probabilities[2].item()
}}
}}
# Example
result = predict("Świetny produkt, polecam!")
print(result)
# Output: {{'label': 'positive', 'confidence': 0.95, ...}}
@misc{{herbert-sentiment-lora,
author = Rafał Adamczyk,
title = {{HerBERT Polish Sentiment Analysis with LoRA}},
year = {{2025}},
publisher = {{HuggingFace}},
howpublished = {{\\url{{https://huggingface.co/rafal-adamczyk/herbert-polish-sentiment-lora}}}}
}}
This model inherits the license from the base model: CC BY-SA 4.0
Base model
allegro/herbert-base-cased