Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPT4 FewShot asset for ArSAS #217

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions assets/ar/sentiment_emotion_others/sentiment/ArSAS_GPT4_FewShot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os

from llmebench.datasets import ArSASDataset
from llmebench.models import OpenAIModel
from llmebench.tasks import SentimentTask


def config():
return {
"dataset": ArSASDataset,
"dataset_args": {},
"task": SentimentTask,
"task_args": {},
"model": OpenAIModel,
"model_args": {
"class_labels": ["Positive", "Negative", "Neutral", "Mixed"],
"max_tries": 3,
},
"general_args": {
"data_path": "data/sentiment_emotion_others/sentiment/ArSAS-test.txt",
"fewshot": {
"train_data_path": "data/sentiment_emotion_others/sentiment/ArSAS-train.txt",
},
},
}


def few_shot_prompt(input_sample, base_prompt, examples):
out_prompt = base_prompt + "\n"
for example in examples:
out_prompt = (
out_prompt
+ "Sentence: "
+ example["input"]
+ "\n"
+ example["label"]
+ "\n\n"
)
out_prompt = out_prompt + "Sentence: " + input_sample + "\n"

return out_prompt


def prompt(input_sample, examples):
base_prompt = "Choose only one sentiment between: Positive, Negative, Neutral, or Mixed for this Arabic sentence."

return [
{
"role": "system",
"content": "You are an AI assistant that helps people find information.",
},
{
"role": "user",
"content": few_shot_prompt(input_sample, base_prompt, examples),
},
]


def post_process(response):
out = response["choices"][0]["message"]["content"]
j = out.find(".")
if j > 0:
out = out[0:j]
return out
Loading