The software tools we need for the activity covered in this post are:
- Google Colab
- GitHub
- And last: ChatGPT
Why I needed these three items?
I needed Google Colab to write code. Google Colab allowed to me not care about creating a local environment and setting it up with the required packages such as 'transformers' from Hugging Face.
I needed GitHub to put my code in a place that I can make available to myself anywhere and also to you (my readers).
I needed ChatGPT to get boilerplate code for our particular task. I learnt about the prompts I needed for this activity from the book by Sinan Ozdemir titled:
Quick Start Guide to Large Language Models. Strategies and Best Practices for using ChatGPT and Other LLMs - Addison-Wesley Professional (2023)
Download BookWhat you would need would (I think) is:
Google Colab that is connected for code to my public repository hosted on GitHub.
How to connect Google Colab with GitHub?
1. Once you would open the Google Colab, you get a screen as shown below.
Note that: I am logged in to my Google Account for this task.
2. Next: you would click on "File" at the top left.
You would click on "Open Notebook".
And you would select "GitHub" as shown below:
3. You would fill in the username. It is: ashishjain1547
Once you fill in the username, the "Repository" dropdown would auto populate with public repositories available for that user.
The repository you would select is: "generative_ai_workspace_2024_04_05"
4. Once repo is selected, it's notebooks start appearing below:
Code for zero shot Spam vs. Not Spam classifier using Facebook's BART
from transformers import pipeline def classify_text (email): """ Use Facebook's 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 """ classifier = pipeline('zero-shot-classification', model='facebook/bart-large-mnli') labels = ['spam', 'not spam'] hypothesis_template = 'This email is {}.' results = classifier(email, labels, hypothesis_template=hypothesis_template) return results['labels'][0]
Usage:
How we used ChatGPT?
Text: I love this product, it's amazing! Sentiment probabilities: positive: 0.4718 negative: 0.2679 neutral: 0.2603 Text: This movie was terrible, I hated it. Sentiment probabilities: negative: 0.3644 positive: 0.3179 neutral: 0.3177 Text: The weather today is fantastic. Sentiment probabilities: positive: 0.4026 negative: 0.3039 neutral: 0.2935 Text: I feel neutral about this situation. Sentiment probabilities: neutral: 0.3587 negative: 0.3248 positive: 0.3166
Additional Note
Question:
How does the BERT know that the problem is of sentiment analysis and not spam-vs-not_spam?
Answer:
No comments:
Post a Comment