Skip to content

Commit edb0820

Browse files
firojalamfdalvi
andauthored
added assets for SpokenNativQA (#386)
* added assets for SpokenNativQA * fixed init file * updated spokenqa scripts * GH Actions: Use v4 for upload/download artifact (#389) * Use v4 for upload/download artifact GH Action * Fix formatting * Bump evaluate version * added assets for SpokenNativQA * fixed init file * updated spokenqa scripts --------- Co-authored-by: Fahim Dalvi <faimaduddin@hbku.edu.qa>
1 parent 0d9d78e commit edb0820

35 files changed

+1672
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import MultiNativQADataset
5+
from llmebench.models import AzureModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": MultiNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": AzureModel,
23+
"general_args": {"test_split": "arabic_qa"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
question_prompt = f"""
30+
Please use your expertise to answer the following Arabic question. Answer in Arabic. Please provide Answer only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
31+
32+
Question: {input_sample['question']}
33+
34+
"""
35+
36+
# Define the assistant prompt
37+
assistant_prompt = """
38+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
39+
"""
40+
return [
41+
{"role": "user", "content": question_prompt},
42+
{"role": "assistant", "content": assistant_prompt},
43+
]
44+
45+
46+
def post_process(response):
47+
content = response["output"].strip()
48+
return content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import MultiNativQADataset
5+
from llmebench.models import OpenAIModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": MultiNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": OpenAIModel,
23+
"general_args": {"test_split": "arabic_qa"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
question_prompt = f"""
30+
Please use your expertise to answer the following Arabic question. Answer in Arabic. Please provide Answer only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
31+
32+
Question: {input_sample['question']}
33+
34+
"""
35+
36+
# Define the assistant prompt
37+
assistant_prompt = """
38+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
39+
"""
40+
return [
41+
{"role": "user", "content": question_prompt},
42+
{"role": "assistant", "content": assistant_prompt},
43+
]
44+
45+
46+
def post_process(response):
47+
content = response["choices"][0]["message"]["content"].strip()
48+
return content

assets/ar/QA/MultiNativQA_GPT4_ZeroShot.py

-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,5 @@ def post_process(response):
4747
content = response["choices"][0]["message"]["content"].strip()
4848
content = content.replace("\n", "").strip()
4949
if "```json" in content:
50-
# content = content.replace("```json", "").replace('```', '').replace("\n}", "}")
51-
# content = content.replace("{\n", "{").replace("\",\n", "\",")
52-
5350
content = re.search(r"```json(.*)```", content).group(1)
5451
return json.loads(content)["answer"]

assets/ar/QA/MultiNativQA_Mistral_7b_ZeroShot.py

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ def prompt(input_sample):
4545
"role": "user",
4646
"content": question_prompt,
4747
},
48-
# {
49-
# "role": "assistant",
50-
# "content": assistant_prompt,
51-
# },
5248
]
5349

5450

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import SpokenNativQADataset
5+
from llmebench.models import AzureModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": SpokenNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": AzureModel,
23+
"general_args": {"test_split": "arabic_qa_azure"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
question_prompt = f"""
30+
Please use your expertise to answer the following Arabic question. Answer in Arabic. Please provide Answer only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
31+
32+
Question: {input_sample['question']}
33+
34+
"""
35+
36+
# Define the assistant prompt
37+
assistant_prompt = """
38+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
39+
"""
40+
return [
41+
{"role": "user", "content": question_prompt},
42+
{"role": "assistant", "content": assistant_prompt},
43+
]
44+
45+
46+
def post_process(response):
47+
content = response["output"].strip()
48+
return content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import SpokenNativQADataset
5+
from llmebench.models import OpenAIModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": SpokenNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": OpenAIModel,
23+
"general_args": {"test_split": "arabic_qa_azure"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
question_prompt = f"""
30+
Please use your expertise to answer the following Arabic question. Answer in Arabic. Please provide Answer only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
31+
32+
Question: {input_sample['question']}
33+
34+
"""
35+
36+
# Define the assistant prompt
37+
assistant_prompt = """
38+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
39+
"""
40+
return [
41+
{"role": "user", "content": question_prompt},
42+
{"role": "assistant", "content": assistant_prompt},
43+
]
44+
45+
46+
def post_process(response):
47+
content = response["choices"][0]["message"]["content"].strip()
48+
return content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import SpokenNativQADataset
5+
from llmebench.models import OpenAIModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": SpokenNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": OpenAIModel,
23+
"general_args": {"test_split": "arabic_qa_azure"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
base64_wav = input_sample["wav"]
30+
31+
question_prompt = f"""
32+
Please use your expertise to answer the following Arabic question. Answer in Arabic and rate your confidence level from 1 to 10. Provide your response in the following JSON format: {{"answer": "your answer", "score": your confidence score}}. Please provide JSON output only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
33+
34+
Question: {input_sample['question']}
35+
36+
"""
37+
# Define the assistant prompt
38+
assistant_prompt = """
39+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
40+
"""
41+
return [
42+
{
43+
"role": "user",
44+
"content": [
45+
{
46+
"type": "text",
47+
"text": question_prompt,
48+
},
49+
{
50+
"type": "input_audio",
51+
"input_audio": {"data": base64_wav, "format": "wav"},
52+
},
53+
],
54+
}
55+
]
56+
57+
58+
def post_process(response):
59+
content = response["choices"][0]["message"]["content"].strip()
60+
content = content.replace("\n", "").strip()
61+
if "```json" in content:
62+
content = re.search(r"```json(.*)```", content).group(1)
63+
return json.loads(content)["answer"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import SpokenNativQADataset
5+
from llmebench.models import OpenAIModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": SpokenNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": OpenAIModel,
23+
"general_args": {"test_split": "arabic_qa_azure"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
question_prompt = f"""
30+
Please use your expertise to answer the following Arabic question. Answer in Arabic and rate your confidence level from 1 to 10. Provide your response in the following JSON format: {{"answer": "your answer", "score": your confidence score}}. Please provide JSON output only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
31+
32+
Question: {input_sample['question']}
33+
34+
"""
35+
36+
# Define the assistant prompt
37+
assistant_prompt = """
38+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
39+
"""
40+
return [
41+
{"role": "user", "content": question_prompt},
42+
{"role": "assistant", "content": assistant_prompt},
43+
]
44+
45+
46+
def post_process(response):
47+
content = response["choices"][0]["message"]["content"].strip()
48+
content = content.replace("\n", "").strip()
49+
if "```json" in content:
50+
content = re.search(r"```json(.*)```", content).group(1)
51+
return json.loads(content)["answer"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import re
3+
4+
from llmebench.datasets import SpokenNativQADataset
5+
from llmebench.models import OpenAIModel
6+
from llmebench.tasks import MultiNativQATask
7+
8+
9+
def metadata():
10+
return {
11+
"author": "Arabic Language Technologies, QCRI, HBKU",
12+
"model": "GPT4-o",
13+
"description": "Deployed on Azure.",
14+
"scores": {},
15+
}
16+
17+
18+
def config():
19+
return {
20+
"dataset": SpokenNativQADataset,
21+
"task": MultiNativQATask,
22+
"model": OpenAIModel,
23+
"general_args": {"test_split": "arabic_qa_azure"},
24+
}
25+
26+
27+
def prompt(input_sample):
28+
# Define the question prompt
29+
question_prompt = f"""
30+
Please use your expertise to answer the following Arabic question. Answer in Arabic. Please provide Answer only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words.
31+
32+
Question: {input_sample['question']}
33+
34+
"""
35+
36+
# Define the assistant prompt
37+
assistant_prompt = """
38+
You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information.
39+
"""
40+
return [
41+
{"role": "user", "content": question_prompt},
42+
{"role": "assistant", "content": assistant_prompt},
43+
]
44+
45+
46+
def post_process(response):
47+
content = response["choices"][0]["message"]["content"].strip()
48+
return content

0 commit comments

Comments
 (0)