-
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.
- Loading branch information
1 parent
98f082a
commit 2f10ba2
Showing
18 changed files
with
1,451 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...ality_disinformation_harmful_content/adult_content_detection/Adult_GPT4_FewShot_Arabic.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,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 |
91 changes: 91 additions & 0 deletions
91
...lity_disinformation_harmful_content/adult_content_detection/Adult_GPT4_FewShot_English.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,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 |
95 changes: 95 additions & 0 deletions
95
...uality_disinformation_harmful_content/adult_content_detection/Adult_GPT4_FewShot_Mixed.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,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 |
68 changes: 68 additions & 0 deletions
68
...lity_disinformation_harmful_content/adult_content_detection/Adult_GPT4_ZeroShot_Arabic.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,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 |
Oops, something went wrong.