-
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.
* Add propaganda assets * Fix errors * Add wise-claim_detection assets
- Loading branch information
1 parent
390ece8
commit 98f082a
Showing
18 changed files
with
1,377 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...actuality_disinformation_harmful_content/claim_detection/CT22Claim_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,88 @@ | ||
from llmebench.datasets import CT22ClaimDataset | ||
from llmebench.models import OpenAIModel | ||
from llmebench.tasks import ClaimDetectionTask | ||
|
||
|
||
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": CT22ClaimDataset, | ||
"task": ClaimDetectionTask, | ||
"model": OpenAIModel, | ||
"model_args": { | ||
"max_tries": 3, | ||
}, | ||
"general_args": {"test_split": "ar", "fewshot": {"train_split": "ar"}}, | ||
} | ||
|
||
|
||
def prompt(input_sample, examples): | ||
base_prompt = ( | ||
"هل تحتوي هذه التغريدة على ادعاء؟ أجب فقط بـ 'نعم' أو 'لا'. قدم التصنيف فقط.\n" | ||
) | ||
prompt = few_shot_prompt(input_sample, base_prompt, examples) | ||
|
||
return [ | ||
{ | ||
"role": "system", | ||
"content": "أنت خبير في تحليل و تصنيف التغريدات.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": prompt, | ||
}, | ||
] | ||
|
||
|
||
def few_shot_prompt(input_sample, base_prompt, examples): | ||
out_prompt = base_prompt + "\n" | ||
for example in examples: | ||
# Found chatgpt confused when using 0 and 1 in the prompt | ||
label = "لا" if example["label"] == "0" else "نعم" | ||
out_prompt = ( | ||
out_prompt + "التغريدة: " + 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" | ||
|
||
# print("=========== FS Prompt =============\n") | ||
# print(out_prompt) | ||
|
||
return out_prompt | ||
|
||
|
||
def post_process(response): | ||
input_label = response["choices"][0]["message"]["content"] | ||
input_label = input_label.replace(".", "").strip().lower() | ||
|
||
if ( | ||
"لا" in input_label | ||
or "لا تحتوي" in input_label | ||
or "ليست" in input_label | ||
or "not" in input_label | ||
or "label: 0" in input_label | ||
or "label: no" in input_label | ||
or "not contain" in input_label | ||
or "doesn't contain" in input_label | ||
): | ||
return "0" | ||
|
||
elif ( | ||
"نعم" in input_label | ||
or "تحتوي" in input_label | ||
or "yes" in input_label | ||
or "contains" in input_label | ||
or "label: 1" in input_label | ||
): | ||
return "1" | ||
else: | ||
return None |
84 changes: 84 additions & 0 deletions
84
...ctuality_disinformation_harmful_content/claim_detection/CT22Claim_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,84 @@ | ||
from llmebench.datasets import CT22ClaimDataset | ||
from llmebench.models import OpenAIModel | ||
from llmebench.tasks import ClaimDetectionTask | ||
|
||
|
||
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": CT22ClaimDataset, | ||
"task": ClaimDetectionTask, | ||
"model": OpenAIModel, | ||
"model_args": { | ||
"max_tries": 3, | ||
}, | ||
"general_args": {"test_split": "ar", "fewshot": {"train_split": "ar"}}, | ||
} | ||
|
||
|
||
def prompt(input_sample, examples): | ||
base_prompt = "Does the following tweet contain a factual claim? If it does, return 'yes', if it does not, return 'no'. Provide only label.\n" | ||
prompt = few_shot_prompt(input_sample, base_prompt, examples) | ||
|
||
return [ | ||
{ | ||
"role": "system", | ||
"content": "You are expert in text analysis and classification.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": prompt, | ||
}, | ||
] | ||
|
||
|
||
def few_shot_prompt(input_sample, base_prompt, examples): | ||
out_prompt = base_prompt + "\n" | ||
for example in examples: | ||
# Found chatgpt confused when using 0 and 1 in the prompt | ||
label = "no" if example["label"] == "0" else "yes" | ||
out_prompt = ( | ||
out_prompt + "tweet: " + example["input"] + "\nlabel: " + label + "\n\n" | ||
) | ||
|
||
# Append the tweet we want the model to predict for but leave the label blank | ||
out_prompt = out_prompt + "tweet: " + input_sample + "\nlabel: \n" | ||
|
||
# print("=========== FS Prompt =============\n") | ||
# print(out_prompt) | ||
|
||
return out_prompt | ||
|
||
|
||
def post_process(response): | ||
input_label = response["choices"][0]["message"]["content"] | ||
input_label = input_label.replace(".", "").strip().lower() | ||
pred_label = "" | ||
|
||
if ( | ||
"yes" in input_label | ||
or "contains a factual claim" in input_label | ||
or "label: 1" in input_label | ||
): | ||
pred_label = "1" | ||
if ( | ||
input_label == "no" | ||
or "label: 0" in input_label | ||
or "label: no" in input_label | ||
or "not contain a factual claim" in input_label | ||
or "doesn't contain a factual claim" in input_label | ||
): | ||
pred_label = "0" | ||
|
||
if pred_label == "": | ||
pred_label = None | ||
|
||
return pred_label |
89 changes: 89 additions & 0 deletions
89
...factuality_disinformation_harmful_content/claim_detection/CT22Claim_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,89 @@ | ||
from llmebench.datasets import CT22ClaimDataset | ||
from llmebench.models import OpenAIModel | ||
from llmebench.tasks import ClaimDetectionTask | ||
|
||
|
||
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": CT22ClaimDataset, | ||
"task": ClaimDetectionTask, | ||
"model": OpenAIModel, | ||
"model_args": { | ||
"max_tries": 3, | ||
}, | ||
"general_args": {"test_split": "ar", "fewshot": {"train_split": "ar"}}, | ||
} | ||
|
||
|
||
def prompt(input_sample, examples): | ||
base_prompt = ( | ||
"هل تحتوي هذه التغريدة على ادعاء؟ أجب فقط بـ 'yes' أو 'no'. قدم التصنيف فقط.\n" | ||
) | ||
prompt = few_shot_prompt(input_sample, base_prompt, examples) | ||
|
||
return [ | ||
{ | ||
"role": "system", | ||
"content": "أنت خبير في تحليل و تصنيف التغريدات.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": prompt, | ||
}, | ||
] | ||
|
||
|
||
def few_shot_prompt(input_sample, base_prompt, examples): | ||
out_prompt = base_prompt + "\n" | ||
for example in examples: | ||
# Found chatgpt confused when using 0 and 1 in the prompt | ||
label = "no" if example["label"] == "0" else "yes" | ||
out_prompt = ( | ||
out_prompt + "التغريدة: " + 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" | ||
|
||
# print("=========== FS Prompt =============\n") | ||
# print(out_prompt) | ||
|
||
return out_prompt | ||
|
||
|
||
def post_process(response): | ||
input_label = response["choices"][0]["message"]["content"] | ||
input_label = input_label.replace(".", "").strip().lower() | ||
|
||
if ( | ||
"لا" in input_label | ||
or "لا تحتوي" in input_label | ||
or "ليست" in input_label | ||
or "not" in input_label | ||
or "no" in input_label | ||
or "label: 0" in input_label | ||
or "label: no" in input_label | ||
or "not contain" in input_label | ||
or "doesn't contain" in input_label | ||
): | ||
return "0" | ||
|
||
elif ( | ||
"نعم" in input_label | ||
or "تحتوي" in input_label | ||
or "yes" in input_label | ||
or "contains" in input_label | ||
or "label: 1" in input_label | ||
): | ||
return "1" | ||
else: | ||
return None |
71 changes: 71 additions & 0 deletions
71
...ctuality_disinformation_harmful_content/claim_detection/CT22Claim_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,71 @@ | ||
from llmebench.datasets import CT22ClaimDataset | ||
from llmebench.models import OpenAIModel | ||
from llmebench.tasks import ClaimDetectionTask | ||
|
||
|
||
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": CT22ClaimDataset, | ||
"task": ClaimDetectionTask, | ||
"model": OpenAIModel, | ||
"model_args": { | ||
"class_labels": ["0", "1"], | ||
"max_tries": 30, | ||
}, | ||
"general_args": {"test_split": "ar"}, | ||
} | ||
|
||
|
||
def prompt(input_sample): | ||
prompt_string = ( | ||
f"هل تحتوي هذه التغريدة على ادعاء؟ أجب فقط بـ 'نعم' أو 'لا'. قدم التصنيف فقط.\n" | ||
f"التغريدة: {input_sample}\n" | ||
f"التصنيف: \n" | ||
) | ||
return [ | ||
{ | ||
"role": "system", | ||
"content": "أنت خبير في تحليل و تصنيف التغريدات.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": prompt_string, | ||
}, | ||
] | ||
|
||
|
||
def post_process(response): | ||
input_label = response["choices"][0]["message"]["content"] | ||
input_label = input_label.replace(".", "").strip().lower() | ||
|
||
if ( | ||
"لا" in input_label | ||
or "لا تحتوي" in input_label | ||
or "ليست" in input_label | ||
or "not" in input_label | ||
or "label: 0" in input_label | ||
or "label: no" in input_label | ||
or "not contain" in input_label | ||
or "doesn't contain" in input_label | ||
): | ||
return "0" | ||
|
||
elif ( | ||
"نعم" in input_label | ||
or "تحتوي" in input_label | ||
or "yes" in input_label | ||
or "contains" in input_label | ||
or "label: 1" in input_label | ||
): | ||
return "1" | ||
else: | ||
return None |
Oops, something went wrong.