Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "SamanthaStorm/fallacyfinder"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Function to predict fallacy
10def predict_fallacy(text):
11 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
12
13 with torch.no_grad():
14 outputs = model(**inputs)
15 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
16 predicted_class_id = predictions.argmax().item()
17 confidence = predictions.max().item()
18
19 predicted_label = model.config.id2label[predicted_class_id]
20 return predicted_label, confidence
21
22# Example usage
23text = "You're just being emotional and can't think rationally"
24fallacy_type, confidence = predict_fallacy(text)
25print(f"Fallacy Type: {fallacy_type}")
26print(f"Confidence: {confidence:.3f}")1@misc{fallacyfinder2024,
2 author = {SamanthaStorm},
3 title = {FallacyFinder: Advanced Logical Fallacy Detection Model},
4 year = {2024},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/SamanthaStorm/fallacyfinder}
7}