Text Classification
jeonseonjin commited on
Commit
f9da252
1 Parent(s): f7dc7f9
Files changed (1) hide show
  1. sample.py +26 -0
sample.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ def classify_text(email):
4
+ """
5
+ Use Facebook BART model to classify an email into "spam" or "not spam"
6
+
7
+ Args:
8
+ email (str): The email to classify
9
+
10
+ Returns:
11
+ str: The classification of the email ("spam" or "not spam")
12
+ """
13
+ # Load the BART model for text classification
14
+ classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
15
+
16
+ # Classify the email
17
+ labels = ['spam','not spam']
18
+ template = 'This email is {}.'
19
+ result = classifier(email, labels)
20
+
21
+ # Get the label with the highest score
22
+ label = result['labels'][0]
23
+
24
+ return label
25
+
26
+ classify_text('hi I am marketer, we have good product for your good life')