| 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") |
|
|