-
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
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
assets/ar/sentiment_emotion_others/stance_detection/ANSStance_JAIS13b_ZeroShot.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,61 @@ | ||
from llmebench.datasets import ANSStanceDataset | ||
from llmebench.models import FastChatModel | ||
from llmebench.tasks import StanceTask | ||
|
||
|
||
def metadata(): | ||
return { | ||
"author": "Arabic Language Technologies, QCRI, HBKU", | ||
"model": "JAIS-13b", | ||
"description": "Locally hosted JAIS-13b-chat model using FastChat.", | ||
"scores": {"Macro-F1": ""}, | ||
} | ||
|
||
|
||
def config(): | ||
return { | ||
"dataset": ANSStanceDataset, | ||
"task": StanceTask, | ||
"model": FastChatModel, | ||
"model_args": { | ||
"class_labels": ["agree", "disagree"], | ||
"max_tries": 30, | ||
}, | ||
} | ||
|
||
|
||
def prompt(input_sample): | ||
ref_s = input_sample["sentence_1"] | ||
claim = input_sample["sentence_2"] | ||
base_prompt = ( | ||
f"Given a reference sentence and a claim, predict whether the claim agrees or disagrees with the reference sentence. Reply only using 'agree', 'disagree', or use 'other' if the sentence and claim are unrelated." | ||
f"\n\n" | ||
f"reference sentence: {ref_s}" | ||
f"\nclaim: {claim}" | ||
f"\nlabel: \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() | ||
return out.lower() |