Views
No views yet
neuralmind/bert-base-portuguese-cased for 4-class offensive / hate-speech detection in Brazilian parliamentary discourse.| id | label |
|---|---|
| 0 | NEUTRAL |
| 1 | GENERIC_OFFENSE |
| 2 | TARGETED_OFFENSE |
| 3 | EXPLICIT_HATE_SPEECH |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4repo = "parliamentary-bertimbau-auditor" # or your HF repo id
5tok = AutoTokenizer.from_pretrained(repo)
6model = AutoModelForSequenceClassification.from_pretrained(repo)
7text = "Senhor presidente, peço a palavra."
8inputs = tok(text, return_tensors="pt", truncation=True, max_length=128)
9with torch.no_grad():
10 probs = torch.softmax(model(**inputs).logits, dim=-1)[0]
11pred = int(probs.argmax())
12print(model.config.id2label[pred], float(probs[pred]))