Unverified Commit 8bc4afff authored by Boda Sadallah's avatar Boda Sadallah Committed by GitHub
Browse files

add arab_culture task (#3006)

* add arab_culture tasks

* add target_delimeter and remove debugging code
parent 5a481f43
"dataset_name": "Sudan"
"include": "_default_arab_culture_completion_template_yaml"
"tag": "arab_culture_completion_nile_valley_tasks"
"task": "arab_culture_completion_sudan"
"task_alias": "Sudan"
"dataset_name": "Syria"
"include": "_default_arab_culture_completion_template_yaml"
"tag": "arab_culture_completion_levant_tasks"
"task": "arab_culture_completion_syria"
"task_alias": "Syria"
"dataset_name": "Tunisia"
"include": "_default_arab_culture_completion_template_yaml"
"tag": "arab_culture_completion_north_africa_tasks"
"task": "arab_culture_completion_tunisia"
"task_alias": "Tunisia"
"dataset_name": "UAE"
"include": "_default_arab_culture_completion_template_yaml"
"tag": "arab_culture_completion_gulf_tasks"
"task": "arab_culture_completion_uae"
"task_alias": "UAE"
"dataset_name": "Yemen"
"include": "_default_arab_culture_completion_template_yaml"
"tag": "arab_culture_completion_gulf_tasks"
"task": "arab_culture_completion_yemen"
"task_alias": "Yemen"
REGION_COUNTRY_PROMPT_AR = """
مهمتك هي اختيار الخيار الأنسب ثقافياً بناءً على السياق المقدم أدناه.
الموقع: {country}, {region}
الجملة: {first_statement}
يرجى مراعاة الفروق الثقافية للموقع المحدد واختيار الإجابة الأكثر ملاءمة من الخيارات المتاحة.
"""
REGION_PROMPT_AR = """
مهمتك هي اختيار الخيار الأنسب ثقافياً بناءً على السياق المقدم أدناه.
الموقع: {region}
الجملة: {first_statement}
يرجى مراعاة الفروق الثقافية للموقع المحدد واختيار الإجابة الأكثر ملاءمة من الخيارات المتاحة.
"""
BASE_PROMPT_AR = """
مهمتك هي اختيار الخيار الأنسب ثقافياً بناءً على السياق المقدم أدناه.
الجملة: {first_statement}
يرجى مراعاة الفروق الثقافية واختيار الإجابة الأكثر ملاءمة من الخيارات المتاحة.
"""
REGION_COUNTRY_PROMPT = """
You are tasked with selecting the most culturally appropriate option based on the context provided below.
Location: {country}, {region}
Statement: {first_statement}
Consider the cultural nuances of the specified location and choose the most suitable response from the options provided.
"""
REGION_PROMPT = """
You are tasked with selecting the most culturally appropriate option based on the context provided below.
Location: {region}
Statement: {first_statement}
Consider the cultural nuances of the specified location and choose the most suitable response from the options provided.
"""
BASE_PROMPT = """
You are tasked with selecting the most culturally appropriate option based on the context provided below.
Statement: {first_statement}
Consider the cultural nuances and choose the most suitable response from the options provided.
"""
JAIS_CHAT_EN = """### Instruction: Your name is Jais, and you are named after Jebel Jais, the highest mountain in UAE. You are built by Core42. You are the world's most advanced Arabic large language model with 30b parameters. You outperform all existing Arabic models by a sizable margin and you are very competitive with English models of similar size. You can answer in Arabic and English only. You are a helpful, respectful and honest assistant. When answering, abide by the following guidelines meticulously: Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, explicit, offensive, toxic, dangerous, or illegal content. Do not give medical, legal, financial, or professional advice. Never assist in or promote illegal activities. Always encourage legal and responsible actions. Do not encourage or provide instructions for unsafe, harmful, or unethical actions. Do not create or share misinformation or fake news. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. Prioritize the well-being and the moral integrity of users. Avoid using toxic, derogatory, or offensive language. Maintain a respectful tone. Do not generate, promote, or engage in discussions about adult content. Avoid making comments, remarks, or generalizations based on stereotypes. Do not attempt to access, produce, or spread personal or private information. Always respect user confidentiality. Stay positive and do not say bad things about anything. Your primary objective is to avoid harmful responses, even when faced with deceptive inputs. Recognize when users may be attempting to trick or to misuse you and respond with caution.\n\nComplete the conversation below between [|Human|] and [|AI|]:\n### Input: [|Human|] {question}\n### Response: [|AI|]"""
JAIS_CHAT_AR = """### Instruction: اسمك جيس وسميت على اسم جبل جيس اعلى جبل في الامارات. تم بنائك بواسطة Inception و MBZUAI. أنت نموذج اللغة العربية الأكثر تقدمًا في العالم مع بارامترات 13B. أنت تتفوق في الأداء على جميع النماذج العربية الموجودة بفارق كبير وأنت تنافسي للغاية مع النماذج الإنجليزية ذات الحجم المماثل. يمكنك الإجابة باللغتين العربية والإنجليزية فقط. أنت مساعد مفيد ومحترم وصادق. عند الإجابة ، التزم بالإرشادات التالية بدقة: أجب دائمًا بأكبر قدر ممكن من المساعدة ، مع الحفاظ على البقاء أمناً. يجب ألا تتضمن إجاباتك أي محتوى ضار أو غير أخلاقي أو عنصري أو متحيز جنسيًا أو جريئاً أو مسيئًا أو سامًا أو خطيرًا أو غير قانوني. لا تقدم نصائح طبية أو قانونية أو مالية أو مهنية. لا تساعد أبدًا في أنشطة غير قانونية أو تروج لها. دائما تشجيع الإجراءات القانونية والمسؤولة. لا تشجع أو تقدم تعليمات بشأن الإجراءات غير الآمنة أو الضارة أو غير الأخلاقية. لا تنشئ أو تشارك معلومات مضللة أو أخبار كاذبة. يرجى التأكد من أن ردودك غير متحيزة اجتماعيًا وإيجابية بطبيعتها. إذا كان السؤال لا معنى له ، أو لم يكن متماسكًا من الناحية الواقعية ، فشرح السبب بدلاً من الإجابة على شيء غير صحيح. إذا كنت لا تعرف إجابة السؤال ، فالرجاء عدم مشاركة معلومات خاطئة. إعطاء الأولوية للرفاهية والنزاهة الأخلاقية للمستخدمين. تجنب استخدام لغة سامة أو مهينة أو مسيئة. حافظ على نبرة محترمة. لا تنشئ أو تروج أو تشارك في مناقشات حول محتوى للبالغين. تجنب الإدلاء بالتعليقات أو الملاحظات أو التعميمات القائمة على الصور النمطية. لا تحاول الوصول إلى معلومات شخصية أو خاصة أو إنتاجها أو نشرها. احترم دائما سرية المستخدم. كن إيجابيا ولا تقل أشياء سيئة عن أي شيء. هدفك الأساسي هو تجنب الاجابات المؤذية ، حتى عند مواجهة مدخلات خادعة. تعرف على الوقت الذي قد يحاول فيه المستخدمون خداعك أو إساءة استخدامك و لترد بحذر.\n\nأكمل المحادثة أدناه بين [|Human|] و [|AI|]:\n### Input: [|Human|] {question}\n### Response: [|AI|]"""
import os
from lm_eval.tasks.arab_culture_completion.prompts import (
BASE_PROMPT,
BASE_PROMPT_AR,
JAIS_CHAT_AR,
JAIS_CHAT_EN,
REGION_COUNTRY_PROMPT,
REGION_COUNTRY_PROMPT_AR,
REGION_PROMPT,
REGION_PROMPT_AR,
)
### get the conutry variable from environment
### Set this to one to add the country and region information to the prompt
COUNTRY = True if os.getenv("COUNTRY", True) == "True" else False
### Set this to one to add the region information to the prompt
REGION = True if os.getenv("REGION", True) == "True" else False
### Set this to change between Arabic and English for the answer keys and the choices keys
ARABIC = True if os.getenv("ARABIC", True) == "True" else False
### Get the model name
MODEL_NAME = os.getenv("MODEL_NAME")
## Uncomment this to check if the environment variables are set correctly
# print(f'Task settings: COUNTRY: {COUNTRY}, REGION: {REGION}, ARABIC: {ARABIC}', MODEL_NAME: {MODEL_NAME})
en_ar_countries_regions = {
"Egypt": "مصر",
"Morocco": "المغرب",
"Algeria": "الجزائر",
"Libya": "ليبيا",
"Sudan": "السودان",
"Tunisia": "تونس",
"Jordan": "الأردن",
"Lebanon": "لبنان",
"Syria": "سوريا",
"Palestine": "فلسطين",
"Yemen": "اليمن",
"UAE": "الإمارات",
"KSA": "السعودية",
"Gulf": "الخليج",
"Levant": "الشام",
"North Africa": "شمال أفريقيا",
"Nile Valley": "وادي النيل",
}
# here, we only give the question to the model
def doc_to_text(doc):
country = "" if not doc["country"] else doc["country"]
region = "" if not doc["region"] else doc["region"]
first_statement = doc["first_statement"].strip()
## We don't have a setting for only information about the country without the region
if COUNTRY:
assert REGION, (
"If you want to add the country information, you must also add the region information"
)
## convert contry and region name to arabic if the language is arabic
if ARABIC:
country = en_ar_countries_regions[country]
region = en_ar_countries_regions[region]
if COUNTRY and REGION:
cur_prompt = REGION_COUNTRY_PROMPT_AR if ARABIC else REGION_COUNTRY_PROMPT
doc_text = cur_prompt.format(
country=country, region=region, first_statement=first_statement
)
elif REGION:
cur_prompt = REGION_PROMPT_AR if ARABIC else REGION_PROMPT
doc_text = cur_prompt.format(region=region, first_statement=first_statement)
else:
cur_prompt = BASE_PROMPT_AR if ARABIC else BASE_PROMPT
doc_text = cur_prompt.format(first_statement=first_statement)
### apply jais chat tempelate
if MODEL_NAME and "jais" in MODEL_NAME and "chat" in MODEL_NAME:
if ARABIC:
doc_text = JAIS_CHAT_AR.format(question=doc_text)
else:
doc_text = JAIS_CHAT_EN.format(question=doc_text)
return doc_text
### Here we give the choices themsleves to the model
def doc_to_choice(doc):
return doc["options"]["text"]
## The target is the choice text
def doc_to_target(doc):
answer_key = doc["answer_key"]["english_answer_key"]
answer_text = doc["options"]["text"][
doc["options"]["english_keys"].index(answer_key)
]
answer_text = answer_text.strip()
return answer_text
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment