Local Inferring: Email Subject Sentiment Classifier#


Import Modules#

from langchain.llms import GPT4All

Initialize GPT4All with Local Model#

# Model downloaded manually from https://gpt4all.io/index.html
llm = GPT4All(model='./model/orca-mini-3b-gguf2-q4_0.gguf')

Email Sentiment Classifier#

Create Prompt Classifier#

prompt = """
Classify the email subject text below, delimited by three dashes (-),
as being malicious or benign. Explain why.

---
Account email verification code, enter now and reply
---
"""

Run Prompt#

llm(prompt)
'\nThis email is likely to be considered as a phishing attempt because it requests the recipient to provide an account verification code that they may not have received from the actual email provider. Additionally, the email does not contain any legitimate information or context that would make the recipient believe that this is a genuine request for account verification. Therefore, it can be classified as malicious.'

Provide a few Examples (Few-Shot Learning)#

prompt = """
Classify the email subject text below, delimited by triple backticks ('''),
as being malicious or benign. Explain why.

Examples:

Subjet: CY23 Email Verification Now
Label: malicious

Subjet: Enter Market Email Verification Code Today
Label: malicious

Subjet: New Account Email Verification Code Verify now
Label: malicious

Subject: Submit your code review today
Label: benign

Subject: '''Account email verification code, enter now and reply'''
Label:
"""
llm(prompt)
'\nSubject: **Your account email verification code**\nLabel: benign'