Views
No views yet
| Model | Arch. | #Layers | #Params |
|---|---|---|---|
Silly-Machine/TuPy-Bert-Base-Binary-Classifier | BERT-Base | 12 | 109M |
Silly-Machine/TuPy-Bert-Large-Binary-Classifier | BERT-Large | 24 | 334M |
Silly-Machine/TuPy-Bert-Base-Multilabel | BERT-Base | 12 | 109M |
Silly-Machine/TuPy-Bert-Large-Multilabel | BERT-Large | 24 | 334M |
1from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
2import torch
3import numpy as np
4from scipy.special import softmax
5
6def classify_hate_speech(model_name, text):
7 model = AutoModelForSequenceClassification.from_pretrained(model_name)
8 tokenizer = AutoTokenizer.from_pretrained(model_name)
9 config = AutoConfig.from_pretrained(model_name)
10
11 # Tokenize input text and prepare model input
12 model_input = tokenizer(text, padding=True, return_tensors="pt")
13
14 # Get model output scores
15 with torch.no_grad():
16 output = model(**model_input)
17 scores = softmax(output.logits.numpy(), axis=1)
18 ranking = np.argsort(scores[0])[::-1]
19
20 # Print the results
21 for i, rank in enumerate(ranking):
22 label = config.id2label[rank]
23 score = scores[0, rank]
24 print(f"{i + 1}) Label: {label} Score: {score:.4f}")
25
26# Example usage
27model_name = "Silly-Machine/TuPy-Bert-Large-Binary-Classifier"
28text = "Bom dia, flor do dia!!"
29classify_hate_speech(model_name, text)
30