-
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 ZeroShot Jais 13b asset for ArSAS (#252)
* JAIS 13b ZeroShot for ArSAS dataset * Fix minor issue in metadata --------- Co-authored-by: Fahim Imaduddin Dalvi <[email protected]>
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
assets/ar/sentiment_emotion_others/sentiment/ArSAS_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,52 @@ | ||
from llmebench.datasets import ArSASDataset | ||
from llmebench.models import FastChatModel | ||
from llmebench.tasks import SentimentTask | ||
|
||
|
||
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": ArSASDataset, | ||
"task": SentimentTask, | ||
"model": FastChatModel, | ||
} | ||
|
||
|
||
def prompt(input_sample): | ||
base_prompt = ( | ||
f'Classify the sentiment of the following sentence as "Positive", "Negative", "Neutral" or "Mixed". Output only the label and nothing else.\n' | ||
f"Sentence: {input_sample}\n" | ||
f"Label: " | ||
) | ||
|
||
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 |