MCPcopy
hub / github.com/EleutherAI/lm-evaluation-harness / doc_to_text

Function doc_to_text

lm_eval/tasks/arab_culture/utils_mcq.py:49–98  ·  view source on GitHub ↗
(doc)

Source from the content-addressed store, hash-verified

47
48
49def doc_to_text(doc):
50 country = "" if not doc["country"] else doc["country"]
51 region = "" if not doc["region"] else doc["region"]
52 first_statement = doc["first_statement"].strip()
53
54 ## We don't have a setting for only information about the country without the region
55 if COUNTRY:
56 assert REGION, (
57 "If you want to add the country information, you must also add the region information"
58 )
59
60 ## convert contry and region name to arabic if the language is arabic
61 if ARABIC:
62 country = en_ar_countries_regions[country]
63 region = en_ar_countries_regions[region]
64
65 choices = doc["options"]
66 choices_str = ""
67 for i in range(3):
68 key = choices["arabic_keys"][i] if ARABIC else choices["english_keys"][i]
69 choice_str = key + ". " + choices["text"][i].strip() + "\n"
70 choices_str += choice_str
71
72 if COUNTRY and REGION:
73 cur_prompt = REGION_COUNTRY_PROMPT_AR if ARABIC else REGION_COUNTRY_PROMPT
74 doc_text = cur_prompt.format(
75 country=country,
76 region=region,
77 first_statement=first_statement,
78 choices=choices_str,
79 )
80 elif REGION:
81 cur_prompt = REGION_PROMPT_AR if ARABIC else REGION_PROMPT
82 doc_text = cur_prompt.format(
83 region=region, first_statement=first_statement, choices=choices_str
84 )
85 else:
86 cur_prompt = BASE_PROMPT_AR if ARABIC else BASE_PROMPT
87 doc_text = cur_prompt.format(
88 first_statement=first_statement, choices=choices_str
89 )
90
91 ### apply jais chat template
92 if MODEL_NAME and "jais" in MODEL_NAME and "chat" in MODEL_NAME:
93 if ARABIC:
94 doc_text = JAIS_CHAT_AR.format(question=doc_text)
95 else:
96 doc_text = JAIS_CHAT_EN.format(question=doc_text)
97
98 return doc_text
99
100
101def doc_to_choice(doc):

Callers

nothing calls this directly

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected