|
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") |
|
""" |
|
|
|
classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli") |
|
|
|
|
|
labels = ['spam','not spam'] |
|
template = 'This email is {}.' |
|
result = classifier(email, labels) |
|
|
|
|
|
label = result['labels'][0] |
|
|
|
return label |
|
|
|
classify_text('hi I am marketer, we have good product for your good life') |