Views
No views yet
| Metric | Value |
|---|---|
| Accuracy | 95.06% |
| Precision | 95.13% |
| Recall | 95.06% |
| F1 Score | 95.08% |
1
2# Example inference #
3
4from transformers import DistilBertForSequenceClassification, DistilBertTokenizer
5import torch
6
7# Load model and tokenizer #
8model_name = 'zohfur/distilbert-commissions'
9tokenizer = DistilBertTokenizer.from_pretrained(model_name)
10model = DistilBertForSequenceClassification.from_pretrained(model_name, num_labels=3)
11
12# Example usage #
13example_sentences = [
14 "Commissions are currently closed.",
15 "Check my bio for commission status.",
16 "C*mms 0pen on p-site",
17 "DM for comms",
18 "Taking art requests, dm me",
19 "comm completed for personmcperson, thank you <3",
20 "open for trades",
21 "Comms are not open",
22 "Comms form will be open soon, please check back later",
23 "~ Furry artist - 25 y.o - he/him - c*mms 0pen: 2/5 - bots dni ~"
24]
25
26# Map label integers back to strings #
27label_map = {0: 'open', 1: 'closed', 2: 'unclear'}
28
29def predict_with_temperature(model, tokenizer, sentences, temperature=1.5):
30 # Prepare input #
31 encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
32 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
33 encoded_input = {key: value.to(device) for key, value in encoded_input.items()}
34 model.to(device)
35 model.eval()
36
37 # Make predictions with temperature scaling #
38 with torch.no_grad():
39 outputs = model(**encoded_input)
40 logits = outputs['logits'] / temperature # Apply temperature scaling #
41 probabilities = torch.softmax(logits, dim=1)
42
43 # Extract predictions and confidence scores #
44 predicted_class_indices = torch.argmax(probabilities, dim=1)
45 confidences = torch.max(probabilities, dim=1).values
46
47 # Convert to CPU and prepare results #
48 predictions = {
49 'sentences': sentences,
50 'labels': [label_map[idx.item()] for idx in predicted_class_indices],
51 'confidences': [score.item() for score in confidences]
52 }
53
54 return predictions
55
56def print_predictions(predictions):
57 """Print formatted predictions with confidence scores."""
58 print("\nClassification Results:")
59 print("=" * 50)
60 for i, (sentence, label, confidence) in enumerate(zip(
61 predictions['sentences'],
62 predictions['labels'],
63 predictions['confidences']
64 ), 1):
65 print(f"\n{i}. Sentence: '{sentence}'")
66 print(f" Predicted Label: {label}")
67 print(f" Confidence Score: {confidence:.4f}")
68
69# Make predictions with temperature scaling #
70predictions = predict_with_temperature(model, tokenizer, example_sentences, temperature=1.5)
71
72# Print results #
73print_predictions(predictions)