Download test.py from cibi11/turkish-content-moderation: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/cibi11/turkish-content-moderation/resolve/main/test.py
- Command line
-
hf download hf://cibi11/turkish-content-moderation/test.py
-
curl -L -o test.py https://huggingface.co/cibi11/turkish-content-moderation/resolve/main/test.py
1.11 kB
| 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") | |