-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added hate_speech/OSACT4SubtaskB_GPT4_ZeroShot
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
assets/ar/sentiment_emotion_others/sentiment/ArSAS_GPT4_FewShot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |