OSM-Det (Online Social Media Detector) is a AI-generated text detection model specifically designed for social media content. This model is introduced in the paper "
Are We in the AI-Generated Text World Already? Quantifying and Monitoring AIGT on Social Media".
1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model = AutoModelForSequenceClassification.from_pretrained("tarryzhang/OSM-Det")
6tokenizer = AutoTokenizer.from_pretrained("tarryzhang/OSM-Det")
7
8# Example text
9text = "Your text to analyze here..."
10
11# Tokenize and predict
12inputs = tokenizer(text, return_tensors="pt", max_length=4096, truncation=True, padding=True)
13with torch.no_grad():
14 outputs = model(**inputs)
15 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
16 predicted_class = torch.argmax(predictions, dim=1).item()
17
18# Interpret results
19labels = ["Human-written", "AI-generated"]
20confidence = predictions[0][predicted_class].item()
21
22print(f"Prediction: {labels[predicted_class]}")
23print(f"Confidence: {confidence:.3f}")
1def detect_ai_text_batch(texts, model, tokenizer, max_length=4096, batch_size=32):
2 results = []
3
4 for i in range(0, len(texts), batch_size):
5 batch_texts = texts[i:i+batch_size]
6
7 # Tokenize batch
8 inputs = tokenizer(
9 batch_texts,
10 return_tensors="pt",
11 max_length=max_length,
12 truncation=True,
13 padding=True
14 )
15
16 # Predict
17 with torch.no_grad():
18 outputs = model(**inputs)
19 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
20 predicted_classes = torch.argmax(predictions, dim=1)
21
22 # Store results
23 for j, text in enumerate(batch_texts):
24 pred_class = predicted_classes[j].item()
25 confidence = predictions[j][pred_class].item()
26 results.append({
27 'text': text,
28 'prediction': 'AI-generated' if pred_class == 1 else 'Human-written',
29 'confidence': confidence,
30 'ai_probability': predictions[j][1].item(),
31 'human_probability': predictions[j][0].item()
32 })
33
34 return results
1@inproceedings{SZSZLBZH25,
2 title = {{Are We in the AI-Generated Text World Already? Quantifying and Monitoring AIGT on Social Media}},
3 author = {Zhen Sun and Zongmin Zhang and Xinyue Shen and Ziyi Zhang and Yule Liu and Michael Backes and Yang Zhang and Xinlei He},
4 booktitle = {{Annual Meeting of the Association for Computational Linguistics (ACL)}},
5 pages = {},
6 publisher ={ACL},
7 year = {2025}
8}