Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAIS ZeroShot for ArSarcasm asset #254

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from llmebench.datasets import ArSarcasm2Dataset
from llmebench.models import FastChatModel
from llmebench.tasks import SarcasmTask


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": ArSarcasm2Dataset,
"task": SarcasmTask,
"model": FastChatModel,
"model_args": {
"class_labels": ["TRUE", "FALSE"],
"max_tries": 3,
},
}


def prompt(input_sample):
base_prompt = (
f'Predict whether the following "tweet" is sarcastic. Return "yes" if the tweet is sarcastic '
f'and "no" if the tweet is not sarcastic. Provide only label.\n\ntweet: {input_sample} \n'
f"label: \n"
)

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


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

if "i apologize" in out:
return None

j = out.find("label:")
if j > 0:
out = out[j + len("label:") :]
else:
j = out.find(" is:\n\n")
if j > 0:
out = out[j + len(" is:\n\n") :]
out = out.strip().title()
if out.lower() == "yes":
return "TRUE"
elif out.lower() == "no":
return "FALSE"
return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from llmebench.datasets import ArSarcasmDataset
from llmebench.models import FastChatModel
from llmebench.tasks import SarcasmTask


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": ArSarcasmDataset,
"task": SarcasmTask,
"model": FastChatModel,
"model_args": {
"class_labels": ["TRUE", "FALSE"],
"max_tries": 3,
},
}


def prompt(input_sample):
base_prompt = (
f'Predict whether the following "tweet" is sarcastic. Return "yes" if the tweet is sarcastic '
f'and "no" if the tweet is not sarcastic. Provide only label.\n\ntweet: {input_sample} \n'
f"label: \n"
)

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


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

if "i apologize" in out:
return None

j = out.find("label:")
if j > 0:
out = out[j + len("label:") :]
else:
j = out.find(" is:\n\n")
if j > 0:
out = out[j + len(" is:\n\n") :]
out = out.strip().title()
if out.lower() == "yes":
return "TRUE"
elif out.lower() == "no":
return "FALSE"
return None
Loading