Skip to content

Commit

Permalink
Add factuality, disinformation, harmful content assets for JAIS (#260)
Browse files Browse the repository at this point in the history
* Add factuality, disinformation, harmful content assets for JAIS

* Format code

* Fix minor metadata issues and remove unused imports

* Fix paths in ANSFactuality dataset

---------

Co-authored-by: Fahim Imaduddin Dalvi <[email protected]>
  • Loading branch information
AridHasan and fdalvi authored Jan 30, 2024
1 parent 27d2402 commit b2b7817
Show file tree
Hide file tree
Showing 14 changed files with 822 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from llmebench.datasets import AdultDataset
from llmebench.models import FastChatModel
from llmebench.tasks import AdultTask


def metadata():
return {
"author": "Arabic Language Technologies, QCRI, HBKU",
"model": "Jais-13b-chat",
"description": "Locally hosted Jais-13b-chat model using FastChat.",
}


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


def prompt(input_sample):
base_prompt = (
f'Given the following tweet, label it as "ADULT" or "NOT_ADULT" based on the content of the tweet.\n\n'
f"tweet: {input_sample}\n"
f"label: \n"
)
return [
{
"role": "user",
"content": base_prompt,
},
]


def post_process(response):
out = response["choices"][0]["message"]["content"].replace("label: ", "")
j = out.find(".")
if j > 0:
out = out[0:j]
return out
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from llmebench.datasets import CT22AttentionworthyDataset
from llmebench.models import FastChatModel
from llmebench.tasks import AttentionworthyTask


def metadata():
return {
"author": "Arabic Language Technologies, QCRI, HBKU",
"model": "Jais-13b-chat",
"description": "Locally hosted Jais-13b-chat model using FastChat.",
}


def config():
return {
"dataset": CT22AttentionworthyDataset,
"task": AttentionworthyTask,
"model": FastChatModel,
"model_args": {
"class_labels": [
"yes_discusses_action_taken",
"harmful",
"yes_discusses_cure",
"yes_asks_question",
"no_not_interesting",
"yes_other",
"yes_blame_authorities",
"yes_contains_advice",
"yes_calls_for_action",
],
"max_tries": 30,
},
"general_args": {"test_split": "ar"},
}


def prompt(input_sample):
base_prompt = (
f'Annotate "tweet" into one of the following categories: yes_discusses_action_taken, harmful, yes_discusses_cure, yes_asks_question, no_not_interesting, yes_other, yes_blame_authorities, yes_contains_advice, yes_calls_for_action\n\n'
f"tweet: {input_sample}\n"
f"label: \n"
)
return [
{
"role": "user",
"content": base_prompt,
},
]


def post_process(response):
label = response["choices"][0]["message"]["content"]

label = (
label.lower()
.replace(" - ", ", ")
.replace(",", "")
.replace(".", "")
.replace("label:", "")
)
label = label.strip()
# label = re.sub("\s+", "_", label)
if label.startswith("no"):
label_fixed = "no_not_interesting"
elif label == "yes_discusses_covid-19_vaccine_side_effects":
label_fixed = "yes_discusses_cure"
elif label == "yes_harmful":
label_fixed = "harmful"
elif label.startswith("yes"):
label_fixed = label

return label_fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from llmebench.datasets import CT22CheckworthinessDataset
from llmebench.models import FastChatModel
from llmebench.tasks import CheckworthinessTask


def metadata():
return {
"author": "Arabic Language Technologies, QCRI, HBKU",
"model": "Jais-13b-chat",
"description": "Locally hosted Jais-13b-chat model using FastChat.",
}


def config():
return {
"dataset": CT22CheckworthinessDataset,
"task": CheckworthinessTask,
"model": FastChatModel,
"model_args": {
"class_labels": ["0", "1"],
"max_tries": 30,
},
"general_args": {"test_split": "ar"},
}


def prompt(input_sample):
base_prompt = (
f'Annotate the "tweet" into "one" of the following categories: checkworthy or not_checkworthy\n\n'
f"tweet: {input_sample}\n"
f"label: \n"
)
return [
{
"role": "user",
"content": base_prompt,
},
]


def post_process(response):
label = response["choices"][0]["message"]["content"]

label = label.replace("label:", "").strip()

if "label: " in label:
arr = label.split("label: ")
label = arr[1].strip()

if label == "checkworthy" or label == "Checkworthy":
label_fixed = "1"
elif label == "Not_checkworthy." or label == "not_checkworthy":
label_fixed = "0"
elif "not_checkworthy" in label or "label: not_checkworthy" in label:
label_fixed = "0"
elif "checkworthy" in label or "label: checkworthy" in label:
label_fixed = "1"
else:
label_fixed = None

return label_fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from llmebench.datasets import CT22ClaimDataset
from llmebench.models import FastChatModel
from llmebench.tasks import ClaimDetectionTask


def metadata():
return {
"author": "Arabic Language Technologies, QCRI, HBKU",
"model": "Jais-13b-chat",
"description": "Locally hosted Jais-13b-chat model using FastChat.",
}


def config():
return {
"dataset": CT22ClaimDataset,
"task": ClaimDetectionTask,
"model": FastChatModel,
"model_args": {
"class_labels": ["0", "1"],
"max_tries": 30,
},
"general_args": {"test_split": "ar"},
}


def prompt(input_sample):
base_prompt = (
f"Given the following tweet, please identify if it contains a claim. If it does, annotate 'yes', if it does not, annotate 'no'\n\n"
f"tweet: {input_sample}\n"
f"label: \n"
)
return [
{
"role": "user",
"content": base_prompt,
},
]


def post_process(response):
label = response["choices"][0]["message"]["content"]

label = label.replace("label:", "").strip()

if "label: " in label:
arr = label.split("label: ")
label = arr[1].strip()

if label == "yes" or label == "the sentence contains a factual claim":
label_fixed = "1"
if label == "no":
label_fixed = "0"

return label_fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from llmebench.datasets import ANSFactualityDataset
from llmebench.models import FastChatModel
from llmebench.tasks import FactualityTask


def metadata():
return {
"author": "Arabic Language Technologies, QCRI, HBKU",
"model": "Jais-13b-chat",
"description": "Locally hosted Jais-13b-chat model using FastChat.",
}


def config():
return {
"dataset": ANSFactualityDataset,
"task": FactualityTask,
"model": FastChatModel,
"model_args": {
"max_tries": 3,
},
}


def prompt(input_sample):
base_prompt = (
"Detect whether the information in the sentence is factually true or false. "
"Answer only by true or false.\n\n"
+ "Sentence: "
+ input_sample
+ "\nlabel: \n"
)

return [
{
"role": "user",
"content": base_prompt,
},
]


def post_process(response):
input_label = response["choices"][0]["message"]["content"]
input_label = input_label.replace(".", "").strip().lower()

if (
"true" in input_label
or "label: 1" in input_label
or "label: yes" in input_label
):
pred_label = "true"
elif (
"false" in input_label
or "label: 0" in input_label
or "label: no" in input_label
):
pred_label = "false"
else:
print("label problem!! " + input_label)
pred_label = None

return pred_label
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from llmebench.datasets import COVID19FactualityDataset
from llmebench.models import FastChatModel
from llmebench.tasks import FactualityTask


def metadata():
return {
"author": "Arabic Language Technologies, QCRI, HBKU",
"model": "Jais-13b-chat",
"description": "Locally hosted Jais-13b-chat model using FastChat.",
}


def config():
return {
"dataset": COVID19FactualityDataset,
"task": FactualityTask,
"model": FastChatModel,
"model_args": {
"class_labels": ["yes", "no"],
"max_tries": 30,
},
}


def prompt(input_sample):
base_prompt = (
f'Annotate the "tweet" into one of the following categories: correct or incorrect\n\n'
f"tweet: {input_sample}\n"
f"label: \n"
)
return [
{
"role": "user",
"content": base_prompt,
},
]


def post_process(response):
label = response["choices"][0]["message"]["content"]

if label.startswith("I am unable to verify".lower()) or label.startswith(
"I am unable to categorize".lower()
):
label_fixed = None
elif "label: incorrect" in label or "incorrect" in label:
label_fixed = "no"
elif "label: correct" in label or "correct" in label:
label_fixed = "yes"
else:
label_fixed = None

return label_fixed
Loading

0 comments on commit b2b7817

Please sign in to comment.