Text Classification
Transformers
Safetensors
Danish
modernbert
Blame
Politics
Classification
zero-shot
mmBERT
text-embeddings-inference
Instructions to use Lundsfryd/BlameBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Lundsfryd/BlameBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Lundsfryd/BlameBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Lundsfryd/BlameBERT") model = AutoModelForSequenceClassification.from_pretrained("Lundsfryd/BlameBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -13,4 +13,49 @@ tags:
|
|
| 13 |
- zero-shot
|
| 14 |
- mmBERT
|
| 15 |
- text-classification
|
| 16 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
- zero-shot
|
| 14 |
- mmBERT
|
| 15 |
- text-classification
|
| 16 |
+
---
|
| 17 |
+
BlameBERT is the first model for zero-shot classification of blame in Danish (following the definition of [Bilotta et al.](http://arxiv.org/abs/2504.06550)). As it is mmBERT based, it should theoretically generalize across languages, but it has only been tested in Danish.
|
| 18 |
+
|
| 19 |
+
BlameBERT has been tested against [QWEN 3.5:9B](https://ollama.com/library/qwen3.5:9b) in a schema-constrained setting, outperforming it on the test set.
|
| 20 |
+
|
| 21 |
+
More details can be found in the GitHub for the [BlameBERT Project](https://github.com/Lundsfryd/BlameBERT).
|
| 22 |
+
|
| 23 |
+
The model is ready for use straight out of the box.
|
| 24 |
+
|
| 25 |
+
**Example usage**
|
| 26 |
+
```
|
| 27 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 28 |
+
import torch
|
| 29 |
+
import numpy as np
|
| 30 |
+
|
| 31 |
+
tokenizer = AutoTokenizer.from_pretrained("Lundsfryd/DaBERT-BlameDetector")
|
| 32 |
+
model = AutoModelForMaskedLM.from_pretrained("Lundsfryd/DaBERT-BlameDetector")
|
| 33 |
+
|
| 34 |
+
def predict(text):
|
| 35 |
+
inputs = tokenizer(
|
| 36 |
+
text,
|
| 37 |
+
padding=True,
|
| 38 |
+
truncation=True,
|
| 39 |
+
max_length=512, #mmBERT accepts up to 8,192 tokens. For our purposes input was capped at 512.
|
| 40 |
+
return_tensors='pt'
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
inputs = {k: v.to(model.device) for k, v in inputs.items()}
|
| 44 |
+
|
| 45 |
+
with torch.no_grad():
|
| 46 |
+
outputs = model(**inputs)
|
| 47 |
+
logits = outputs.logits
|
| 48 |
+
probabilities = torch.softmax(logits, dim=1)
|
| 49 |
+
predicted_class = torch.argmax(probabilities, dim=1).item()
|
| 50 |
+
confidence = probabilities[0][predicted_class].item()
|
| 51 |
+
|
| 52 |
+
return predicted_class, confidence, probabilities[0].cpu().numpy()
|
| 53 |
+
|
| 54 |
+
texts = [
|
| 55 |
+
"Jeg er opmærksom på fængselspersonalets vilkår.",
|
| 56 |
+
"Det kommer både de studerende og erhvervslivet til gode.",
|
| 57 |
+
"Jeg er enig i, at der er kommet for mange hertil, som ikke vil Danmark, som ikke opfører sig ordentligt, som begår kriminalitet, og som i øvrigt med deres ideologiske tilgang til både religion og politik er med til at undergrave vores demokrati."
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
```
|