|
|
|
|
|
""" |
|
|
Türkçe Komplo Teorisi Tespit Modeli Test Scripti |
|
|
""" |
|
|
|
|
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
import torch |
|
|
|
|
|
def test_model(): |
|
|
"""Model ve tokenizer'ı test eder""" |
|
|
|
|
|
print("🧪 Model test ediliyor...") |
|
|
|
|
|
try: |
|
|
|
|
|
print("📄 Model ve tokenizer yükleniyor...") |
|
|
tokenizer = AutoTokenizer.from_pretrained("./") |
|
|
model = AutoModelForSequenceClassification.from_pretrained("./") |
|
|
print("✅ Model başarıyla yüklendi!") |
|
|
|
|
|
|
|
|
print(f"\n📊 Model Bilgileri:") |
|
|
print(f" - Model Türü: {model.config.model_type}") |
|
|
print(f" - Sınıf Sayısı: {model.config.num_labels}") |
|
|
print(f" - Vocabulary Boyutu: {model.config.vocab_size}") |
|
|
print(f" - Max Uzunluk: {model.config.max_position_embeddings}") |
|
|
print(f" - Sınıf Etiketleri: {model.config.id2label}") |
|
|
|
|
|
|
|
|
def predict_text(text): |
|
|
"""Verilen metni sınıflandırır""" |
|
|
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512) |
|
|
|
|
|
with torch.no_grad(): |
|
|
outputs = model(**inputs) |
|
|
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1) |
|
|
|
|
|
probabilities = predictions[0].tolist() |
|
|
predicted_class = torch.argmax(predictions, dim=-1).item() |
|
|
|
|
|
return { |
|
|
'prediction': 'Komplo Teorisi' if predicted_class == 1 else 'Gerçek Haber', |
|
|
'confidence': max(probabilities), |
|
|
'probabilities': { |
|
|
'Gerçek Haber': probabilities[0], |
|
|
'Komplo Teorisi': probabilities[1] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
test_examples = [ |
|
|
"5G teknolojisi insanları kontrol etmek için tasarlanmış gizli bir sistemdir.", |
|
|
"Bilim insanları, 5G teknolojisinin daha hızlı internet bağlantısı sağladığını doğruladı.", |
|
|
"COVID-19 aşıları insanların DNA'sını değiştirmek için tasarlanmıştır.", |
|
|
"COVID-19 aşıları, virüse karşı bağışıklık sistemini güçlendiren mRNA teknolojisi kullanır.", |
|
|
"Ay'a gerçekten hiç çıkmadık, tüm görüntüler Hollywood'da çekildi.", |
|
|
"NASA, Ay misyonlarından getirilen kaya örneklerini bilim insanlarına inceleme için sağladı." |
|
|
] |
|
|
|
|
|
print(f"\n🧪 Test Örnekleri:") |
|
|
print("=" * 80) |
|
|
|
|
|
for i, text in enumerate(test_examples, 1): |
|
|
result = predict_text(text) |
|
|
print(f"\n{i}. Metin: {text}") |
|
|
print(f" 🎯 Tahmin: {result['prediction']}") |
|
|
print(f" 📊 Güven: {result['confidence']:.1%}") |
|
|
|
|
|
if result['probabilities']['Komplo Teorisi'] > 0.7: |
|
|
print(f" ⚠️ Yüksek komplo teorisi riski!") |
|
|
elif result['probabilities']['Komplo Teorisi'] > 0.5: |
|
|
print(f" ⚡ Orta düzey komplo teorisi riski.") |
|
|
else: |
|
|
print(f" ✅ Güvenilir içerik.") |
|
|
|
|
|
print(f"\n🎉 Model test tamamlandı!") |
|
|
print(f"✅ Model çalışıyor ve tahminler yapabiliyor.") |
|
|
|
|
|
except Exception as e: |
|
|
print(f"❌ Hata: {e}") |
|
|
return False |
|
|
|
|
|
return True |
|
|
|
|
|
if __name__ == "__main__": |
|
|
test_model() |