File size: 1,106 Bytes
9055bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

MODEL_PATH = "cibi11/turkish-content-moderation"

KATEGORILER = ["normal", "kufur", "tehdit", "taciz", "nefret", "saka/igneleme", "cinsel"]

print("Model yukleniyor...")
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model.eval()
print("Hazir! Cikmak icin 'q' yazin.\n")

while True:
    text = input("Metin: ").strip()
    if text.lower() == "q":
        break
    if not text:
        continue

    inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)

    with torch.no_grad():
        logits = model(**inputs).logits
        probs = torch.softmax(logits, dim=-1)[0]

    print("-" * 50)
    for label, prob in zip(KATEGORILER, probs):
        prob_pct = prob.item() * 100
        bar = "#" * int(prob_pct / 2) + "-" * (50 - int(prob_pct / 2))
        print(f"  {label:<16} %{prob_pct:5.1f}  {bar[:50]}")
    print("-" * 50)
    en_yuksek = KATEGORILER[probs.argmax()]
    print(f"  >>> Sonuc: {en_yuksek}\n")