Downloads · 30 days
11
42% of all-time downloads
NiklasKoch/modernbert-discussion-classifier
modernbert-discussion-classifier is a text classification model from NiklasKoch. Use it when you need a label for a piece of text. It is set up for peft.
A lightweight, high-throughput ModernBERT-based model for classifying constructive vs non-constructive conversations in online forums like Reddit. Optimized for processing vast amounts of Reddit discussion data effici…
Downloads · 30 days
11
42% of all-time downloads
All-time downloads
26
Public
Repo size
13.6 MB
Likes
0
Public
Click a slice to open those files.
.safetensors13.6 MB · 100%
From the Hugging Face model README
A lightweight, high-throughput ModernBERT-based model for classifying constructive vs non-constructive conversations in online forums like Reddit. Optimized for processing vast amounts of Reddit discussion data efficiently.
This model is a QLoRA (Quantized LoRA) fine-tuned version of answerdotai/ModernBERT-base specifically designed as a lightweight solution for large-scale Reddit discussion analysis.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from peft import PeftModel
import torch
# Load base model and tokenizer
base_model_name = "answerdotai/ModernBERT-base"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
model = AutoModelForSequenceClassification.from_pretrained(
base_model_name,
num_labels=2
)
# Load the fine-tuned adapters
model = PeftModel.from_pretrained(model, "NiklasKoch/modernbert-discussion-classifier")
model.eval()
# Classify text (optimized for batch processing)
def classify_text(text):
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
padding=True,
max_length=4096
)
# Move inputs to same device as model (important for GPU usage)
inputs = {k: v.to(next(model.parameters()).device) for k, v in inputs.items()}
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# 0 = non-constructive, 1 = constructive
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()
return {
'class': 'constructive' if predicted_class == 1 else 'non-constructive',
'confidence': confidence,
'scores': {
'non-constructive': predictions[0][0].item(),
'constructive': predictions[0][1].item()
}
}
# Example usage - Reddit discussion
text = "[author0] LEGO: What do you think you're doing?!? [author1] I don't get it did he reveal bionicle reboot or smthn? [author2] Not really, he did announce something but was super vague, seems like a sort of passion project we wants to do with the community, he even said it might not even be bionicle. [author1] So is that image fan made or is it one of his passion projects [author2] Those pictures are real and on his insta, he did a stream talking about it I'm sure you can find somewhere, search up Fabre bionicle stream 2020 or something. [author1] OK thanks"
result = classify_text(text)
print(result)
r: 16lora_alpha: 32lora_dropout: 0.1Wqkv, Wo, Wi, denseYNACC:
Accuracy: 0.63
Precision: 0.63
F1-Score: 0.65
IAC:
Accuracy: 0.79
Precision: 0.85
F1-Score: 0.87
Reddit:
Accuracy: 0.57
Precision: 0.74
F1-Score: 0.67
Niklas Koch, Georg August University of Göttingen