Skip to content

Commit

Permalink
Merge branch 'main' into readme/update
Browse files Browse the repository at this point in the history
  • Loading branch information
firojalam committed Jan 20, 2025
2 parents 186a5b0 + 800926c commit b3d809c
Show file tree
Hide file tree
Showing 228 changed files with 16,395 additions and 24 deletions.
1 change: 0 additions & 1 deletion assets/ar/QA/MultiNativQA_GPT4_ZeroShot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def config():


def prompt(input_sample):

# Define the question prompt
question_prompt = f"""
Please use your expertise to answer the following Arabic question. Answer in Arabic and rate your confidence level from 1 to 10. Provide your response in the following JSON format: {{"answer": "your answer", "score": your confidence score}}. Please provide JSON output only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
Expand Down
1 change: 0 additions & 1 deletion assets/ar/QA/MultiNativQA_Llama3_8b_ZeroShot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def config():


def prompt(input_sample):

# Define the question prompt
question_prompt = f"""
Please use your expertise to answer the following Arabic question. Answer in Arabic and rate your confidence level from 1 to 10.
Expand Down
1 change: 0 additions & 1 deletion assets/ar/QA/MultiNativQA_Mistral_7b_ZeroShot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def config():


def prompt(input_sample):

# Define the question prompt
# Provide your response in the following JSON format and provide JSON output only. No additional text.
question_prompt = f"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from llmebench.datasets import AdultDataset
from llmebench.models import OpenAIModel
from llmebench.tasks import AdultTask


def metadata():
return {
"author": "Mohamed Bayan Kmainasi, Rakif Khan, Ali Ezzat Shahroor, Boushra Bendou, Maram Hasanain, and Firoj Alam",
"affiliation": "Arabic Language Technologies, Qatar Computing Research Institute (QCRI), Hamad Bin Khalifa University (HBKU)",
"model": "GPT-4o-2024-05-22",
"description": "For a comprehensive analysis and results, refer to our peer-reviewed publication available at [Springer](https://doi.org/10.1007/978-981-96-0576-7_30) or explore the preprint version on [arXiv](https://arxiv.org/abs/2409.07054).",
}


def config():
return {
"dataset": AdultDataset,
"task": AdultTask,
"model": OpenAIModel,
"model_args": {
"class_labels": ["ADULT", "NOT_ADULT"],
"max_tries": 30,
},
"general_args": {
"fewshot": {
"deduplicate": True,
},
},
}


def few_shot_prompt(input_sample, base_prompt, examples):
out_prompt = base_prompt + "\n\n"
out_prompt = out_prompt + "اليك بعض الامثلة:\n\n"
for index, example in enumerate(examples):
label = "للبالغين" if example["label"] == "ADULT" else "ليست للبالغين"

out_prompt = (
out_prompt
+ "مثال "
+ str(index)
+ ":"
+ "\n"
+ "التغريدة: "
+ example["input"]
+ "\التصنيف: "
+ label
+ "\n\n"
)

# Append the sentence we want the model to predict for but leave the Label blank
out_prompt = out_prompt + "التغريدة: " + input_sample + "\التصنيف: \n"

return out_prompt


def prompt(input_sample, examples):
base_prompt = "هل تحتوي التغريدة التالية على لغة للبالغين؟ اجب 'للبالغين' أو 'ليست للبالغين' بدون أي تفسير."
return [
{
"role": "system",
"content": "أنت محلل خبير، يمكنك تحديد وتصنيف المحتوى الخاص بالبالغين في التغريدة.",
},
{
"role": "user",
"content": few_shot_prompt(input_sample, base_prompt, examples),
},
]


def post_process(response):
if not response:
return None

label = response["choices"][0]["message"]["content"]
label = label.replace("التصنيف:", "").strip()
label = label.replace("label:", "").strip()
label = label.lower()

if (
"ليس" in label
or "ليست" in label
or "not" in label
or "no" in label
or "غير" in label
or "لا" in label
or "not_adult" in label
or "not adult" in label
):
return "NOT_ADULT"
elif "للبالغين" in label or "نعم" in label or "adult" in label:
return "ADULT"
else:
return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from llmebench.datasets import AdultDataset
from llmebench.models import OpenAIModel
from llmebench.tasks import AdultTask


def metadata():
return {
"author": "Mohamed Bayan Kmainasi, Rakif Khan, Ali Ezzat Shahroor, Boushra Bendou, Maram Hasanain, and Firoj Alam",
"affiliation": "Arabic Language Technologies, Qatar Computing Research Institute (QCRI), Hamad Bin Khalifa University (HBKU)",
"model": "GPT-4o-2024-05-22",
"description": "For a comprehensive analysis and results, refer to our peer-reviewed publication available at [Springer](https://doi.org/10.1007/978-981-96-0576-7_30) or explore the preprint version on [arXiv](https://arxiv.org/abs/2409.07054).",
}


def config():
return {
"dataset": AdultDataset,
"task": AdultTask,
"model": OpenAIModel,
"model_args": {
"class_labels": ["ADULT", "NOT_ADULT"],
"max_tries": 30,
},
"general_args": {
"fewshot": {
"deduplicate": True,
},
},
}


def few_shot_prompt(input_sample, base_prompt, examples):
out_prompt = base_prompt + "\n\n"
out_prompt = out_prompt + "Here are some examples:\n\n"
for index, example in enumerate(examples):
out_prompt = (
out_prompt
+ "Example "
+ str(index)
+ ":"
+ "\n"
+ "tweet: "
+ example["input"]
+ "\nlabel: "
+ example["label"]
+ "\n\n"
)

# Append the sentence we want the model to predict for but leave the Label blank
out_prompt = out_prompt + "tweet: " + input_sample + "\nlabel: \n"

return out_prompt


def prompt(input_sample, examples):
base_prompt = f'Does the following tweet contain adult content? label it as "ADULT" if it does, or "NOT_ADULT" otherwise. Return label only.'
return [
{
"role": "system",
"content": "You are an expert annotator, you can identify and label adult content within a tweet.",
},
{
"role": "user",
"content": few_shot_prompt(input_sample, base_prompt, examples),
},
]


def post_process(response):
label = response["choices"][0]["message"]["content"]
label = label.replace("التصنيف:", "").strip()
label = label.replace("label:", "").strip()

label = label.replace("<s>", "").replace("</s>", "")
label = label.lower()

if (
"ليس" in label
or "ليست" in label
or "not" in label
or "no" in label
or "غير" in label
or "لا" in label
or "not_adult" in label
or "not adult" in label
):
return "NOT_ADULT"
elif "للبالغين" in label or "نعم" in label or "adult" in label:
return "ADULT"
else:
return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from llmebench.datasets import AdultDataset
from llmebench.models import OpenAIModel
from llmebench.tasks import AdultTask


def metadata():
return {
"author": "Mohamed Bayan Kmainasi, Rakif Khan, Ali Ezzat Shahroor, Boushra Bendou, Maram Hasanain, and Firoj Alam",
"affiliation": "Arabic Language Technologies, Qatar Computing Research Institute (QCRI), Hamad Bin Khalifa University (HBKU)",
"model": "GPT-4o-2024-05-22",
"description": "For a comprehensive analysis and results, refer to our peer-reviewed publication available at [Springer](https://doi.org/10.1007/978-981-96-0576-7_30) or explore the preprint version on [arXiv](https://arxiv.org/abs/2409.07054).",
}


def config():
return {
"dataset": AdultDataset,
"task": AdultTask,
"model": OpenAIModel,
"model_args": {
"class_labels": ["ADULT", "NOT_ADULT"],
"max_tries": 30,
},
"general_args": {
"fewshot": {
"deduplicate": True,
},
},
}


def few_shot_prompt(input_sample, base_prompt, examples):
out_prompt = base_prompt + "\n\n"
out_prompt = out_prompt + "اليك بعض الامثلة:\n\n"
for index, example in enumerate(examples):
out_prompt = (
out_prompt
+ "مثال "
+ str(index)
+ ":"
+ "\n"
+ "التغريدة: "
+ example["input"]
+ "\التصنيف: "
+ example["label"]
+ "\n\n"
)

# Append the sentence we want the model to predict for but leave the Label blank
out_prompt = out_prompt + "التغريدة: " + input_sample + "\التصنيف: \n"

return out_prompt


def prompt(input_sample, examples):
base_prompt = f'بالنظر إلى التغريدة التالية، صنفها على أنها "ADULT" أو "NOT_ADULT" بناء على محتوى التغريدة'
return [
{
"role": "system",
"content": "أنت محلل خبير، يمكنك تحديد وتصنيف المحتوى الخاص بالبالغين في التغريدة.",
},
{
"role": "user",
"content": few_shot_prompt(input_sample, base_prompt, examples),
},
]


def post_process(response):
if not response:
return None

label = response["choices"][0]["message"]["content"]

label = label.replace("التصنيف:", "").strip()
label = label.replace("label:", "").strip()

label = label.replace("<s>", "").replace("</s>", "")
label = label.lower()

if (
"ليس" in label
or "ليست" in label
or "not" in label
or "no" in label
or "غير" in label
or "لا" in label
or "not_adult" in label
or "not adult" in label
):
return "NOT_ADULT"
elif "للبالغين" in label or "نعم" in label or "adult" in label:
return "ADULT"
else:
return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from llmebench.datasets import AdultDataset
from llmebench.models import OpenAIModel
from llmebench.tasks import AdultTask


def metadata():
return {
"author": "Mohamed Bayan Kmainasi, Rakif Khan, Ali Ezzat Shahroor, Boushra Bendou, Maram Hasanain, and Firoj Alam",
"affiliation": "Arabic Language Technologies, Qatar Computing Research Institute (QCRI), Hamad Bin Khalifa University (HBKU)",
"model": "GPT-4o-2024-05-22",
"description": "For a comprehensive analysis and results, refer to our peer-reviewed publication available at [Springer](https://doi.org/10.1007/978-981-96-0576-7_30) or explore the preprint version on [arXiv](https://arxiv.org/abs/2409.07054).",
}


def config():
return {
"dataset": AdultDataset,
"task": AdultTask,
"model": OpenAIModel,
"model_args": {
"class_labels": ["ADULT", "NOT_ADULT"],
"max_tries": 3,
},
}


def prompt(input_sample):
prompt_string = (
"هل تحتوي التغريدة التالية على لغة للبالغين؟ اجب 'للبالغين' أو 'ليست للبالغين' بدون أي تفسير.\n\n"
+ "التغريدة: "
+ input_sample
+ "\nالتصنيف: "
)
return [
{
"role": "system",
"content": "أنت محلل خبير، يمكنك تحديد وتصنيف المحتوى الخاص بالبالغين في التغريدة.",
},
{
"role": "user",
"content": prompt_string,
},
]


def post_process(response):
label = response["choices"][0]["message"]["content"]
label = label.replace("التصنيف:", "").strip()
label = label.replace("label:", "").strip()

label = label.replace("<s>", "").replace("</s>", "")
label = label.lower()

if (
"ليس" in label
or "ليست" in label
or "not" in label
or "no" in label
or "غير" in label
or "لا" in label
or "not_adult" in label
or "not adult" in label
):
return "NOT_ADULT"
elif "للبالغين" in label or "نعم" in label or "adult" in label:
return "ADULT"
else:
return None
Loading

0 comments on commit b3d809c

Please sign in to comment.