Text Classification
File size: 741 Bytes
f9da252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from transformers import pipeline

def classify_text(email):
    """
    Use Facebook BART model to classify an email into "spam" or "not spam"
    
    Args:
        email (str): The email to classify
    
    Returns:
        str: The classification of the email ("spam" or "not spam")
    """
    # Load the BART model for text classification
    classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")

    # Classify the email
    labels = ['spam','not spam']
    template = 'This email is {}.'
    result = classifier(email, labels)

    # Get the label with the highest score
    label = result['labels'][0]

    return label

classify_text('hi I am marketer, we have good product for your good life')