Views
No views yet
distilbert-base-uncased0: Unproductive (emails that don't require action)1: Productive (emails that require action or response)pip install transformers torch1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="MiguelJeronimoOliveira/email-classifier"
6)
7
8# Classify an email
9result = classifier("Hi, I need urgent technical support. The system is down.")
10print(result)
11# [{'label': 'LABEL_1', 'score': 0.98}]
12
13result = classifier("Thank you for the excellent work!")
14print(result)
15# [{'label': 'LABEL_0', 'score': 0.95}]1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "MiguelJeronimoOliveira/email-classifier"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Prepare input
10email_text = "Hi, I would like to schedule a meeting to discuss the project timeline."
11inputs = tokenizer(
12 email_text,
13 truncation=True,
14 padding=True,
15 max_length=512,
16 return_tensors="pt"
17)
18
19# Get prediction
20with torch.no_grad():
21 outputs = model(**inputs)
22 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
23 predicted_class = predictions.argmax(dim=-1).item()
24 confidence = predictions[0][predicted_class].item()
25
26# Interpret result
27label = "productive" if predicted_class == 1 else "unproductive"
28print(f"Classification: {label} (confidence: {confidence:.2f})")LABEL_0 or 0: UnproductiveLABEL_1 or 1: Productive1@misc{email-classifier-2024,
2 title={Email Classifier: A Fine-tuned DistilBERT for Productivity Classification},
3 author={Miguel Jeronimo Oliveira},
4 year={2024},
5 howpublished={\url{https://huggingface.co/MiguelJeronimoOliveira/email-classifier}}
6}