Skip to content

Commit

Permalink
Wise claim detection (#380)
Browse files Browse the repository at this point in the history
* Add propaganda assets

* Fix errors

* Add wise-claim_detection assets
  • Loading branch information
MohamedBayan authored Jan 20, 2025
1 parent 390ece8 commit 98f082a
Show file tree
Hide file tree
Showing 18 changed files with 1,377 additions and 0 deletions.
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
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
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
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
Loading

0 comments on commit 98f082a

Please sign in to comment.