Download training/src/few_shot_prompts.py from SinhalaMMLU-SharedTask/team-riswan: direct link, hf CLI and curl.
- Browser
- Download file 27.5 kB
-
https://huggingface.co/SinhalaMMLU-SharedTask/team-riswan/resolve/main/training/src/few_shot_prompts.py
- Command line
-
hf download hf://SinhalaMMLU-SharedTask/team-riswan/training/src/few_shot_prompts.py
-
curl -L -o few_shot_prompts.py https://huggingface.co/SinhalaMMLU-SharedTask/team-riswan/resolve/main/training/src/few_shot_prompts.py
27.5 kB
| # Historical source snapshot. Comments about accuracy, data origin, or compliance | |
| # are author claims, not verification; see training/README.md and REPRODUCIBILITY.md. | |
| """ | |
| SinhalaMMLU Few-Shot (In-Context Learning) Prompt Builder | |
| Derived from the EMNLP 2025 benchmark paper: | |
| 'SinhalaMMLU: A Comprehensive Benchmark for Evaluating Multitask Language Understanding in Sinhala' | |
| Features: | |
| - 100% external Sri Lankan curriculum exemplars (zero overlap with test questions, strictly abiding by Rule #04) | |
| - Balanced exemplars covering Humanities, Social Sciences, STEM, Language, and Other | |
| - Non-sequential balanced gold answer order (2, 4, 1, 3) to prevent ascending 1->2->3->4->1 continuation bias | |
| - Supports Direct Mode, English Cross-Lingual CoT (--cot), and Tamil Cross-Lingual CoT (--cot --cot_lang ta) | |
| """ | |
| # Exact task-849 (57.78% overall, 73.33% Hard) exemplars ordered (2, 4, 1, 3) | |
| EXEMPLARS_BY_DOMAIN = { | |
| "humanities": [ | |
| { | |
| "question": "අනුරාධපුර රාජධානියේ පළමු රජු ලෙස සැලකෙන්නේ කවුරුන්ද?", | |
| "choices": ["දේවානම්පියතිස්ස රජු", "පණ්ඩුකාභය රජු", "දුටුගැමුණු රජු", "වළගම්බා රජු"], | |
| "analysis": "The question asks who is considered the first king of the Anuradhapura Kingdom. Options: (1) Devanampiyatissa, (2) Pandukabhaya, (3) Dutugemunu, (4) Valagamba. King Pandukabhaya founded Anuradhapura as the capital and was its first king.", | |
| "analysis_ta": "வினா: அனுராதபுர இராச்சியத்தின் முதல் மன்னராகக் கருதப்படுபவர் யார்? தெரிவுகள்: (1) தேவநம்பியதிஸ்ஸ, (2) பண்டுகாபய, (3) துட்டகைமுனு, (4) வலகம்பா. அனுராதபுரத்தைத் தலைநகராகக் கொண்டு ஆட்சி செய்த முதல் மன்னன் பண்டுகாபய ஆவார்.", | |
| "answer": "2" | |
| }, | |
| { | |
| "question": "මහාචාර්ය එදිරිවීර සරච්චන්ද්රයන් විසින් රචිත ප්රකට ශෛලිගත නාට්යය කුමක්ද?", | |
| "choices": ["කැලණි පාලම", "හුණුවටයේ කතාව", "සුබ සහ යස", "මනමේ"], | |
| "analysis": "The question asks for the famous stylized drama written by Prof. Ediriweera Sarachchandra. Options: (1) Kelani Palama, (2) Hunuwataye Kathawa, (3) Suba saha Yasa, (4) Maname. Maname (1956) is Sarachchandra's iconic stylized drama.", | |
| "analysis_ta": "வினா: பேராசிரியர் எதிரிவீர சரச்சந்திரவால் எழுதப்பட்ட புகழ்பெற்ற நாடகம் எது? தெரிவுகள்: (1) களனி பாலம, (2) ஹுனுவட்டயே கதாவ, (3) சுப சஹ யச, (4) மனமே. 'மனமே' (1956) சரச்சந்திரவின் புகழ்பெற்ற நாடகமாகும்.", | |
| "answer": "4" | |
| }, | |
| { | |
| "question": "සිදුහත් කුමරු ගිහිගෙය හැර යාමේ සිදුවීම බෞද්ධ සාහිත්යයේ හඳුන්වනු ලබන්නේ කුමන නමකින්ද?", | |
| "choices": ["මහාභිනිෂ්ක්රමණය", "ධම්මචක්කප්පවත්තනය", "මහා පරිනිර්වාණය", "සම්බෝධිය"], | |
| "analysis": "The question asks how Prince Siddhartha's renunciation of worldly life is known in Buddhist literature. Options: (1) Mahabinishkramanaya (Great Renunciation), (2) Dhammacakkappavattana, (3) Maha Parinirvana, (4) Sambodhi. Renunciation is Mahabinishkramanaya.", | |
| "analysis_ta": "வினா: சித்தார்த்த இளவரசர் இல்லற வாழ்வைத் துறந்த நிகழ்வு பௌத்த இலக்கியத்தில் எவ்வாறு அழைக்கப்படுகிறது? தெரிவுகள்: (1) மஹாபினிஷ்கிரமணய (மகா துறவு), (2) தம்மசக்கப்பவத்தன, (3) மகா பரிநிர்வாணம், (4) சம்போதி. இல்லறத் துறவு மஹாபினிஷ்கிரமணய எனப்படும்.", | |
| "answer": "1" | |
| }, | |
| { | |
| "question": "උඩරට නර්තන සම්ප්රදායේ ප්රධානතම අවනද්ධ භාණ්ඩය කුමක්ද?", | |
| "choices": ["දවුල", "තම්මැට්ටම", "ගැට බෙරය", "යක් බෙරය"], | |
| "analysis": "The question asks for the main percussion drum of the Kandyan (Udarata) dance tradition. Options: (1) Dawula, (2) Thammattama, (3) Geta Beraya, (4) Yak Beraya. Geta Beraya is the primary drum of Kandyan dance.", | |
| "analysis_ta": "வினா: கண்டிய (உடரட்ட) நடன மரபின் முக்கிய தோற்கருவி எது? தெரிவுகள்: (1) தவுல, (2) தம்மட்டம, (3) கெட்ட பெரய, (4) யக் பெரய. கண்டிய நடனத்தின் பிரதான மேளம் கெட்ட பெரய ஆகும்.", | |
| "answer": "3" | |
| } | |
| ], | |
| "stem": [ | |
| { | |
| "question": "ශාක ප්රභාසංශ්ලේෂණ ක්රියාවලියේදී අතුරු ඵලයක් ලෙස පරිසරයට නිදහස් වන වායුව කුමක්ද?", | |
| "choices": ["කාබන් ඩයොක්සයිඩ්", "ඔක්සිජන්", "නයිට්රජන්", "හයිඩ්රජන්"], | |
| "analysis": "The question asks which gas is released as a byproduct of plant photosynthesis. Options: (1) Carbon dioxide, (2) Oxygen, (3) Nitrogen, (4) Hydrogen. Photosynthesis absorbs CO2 and releases Oxygen.", | |
| "analysis_ta": "வினா: தாவர ஒளித்தொகுப்பின் போது பக்க விளைபொருளாகச் சூழலுக்கு விடுவிக்கப்படும் வாயு எது? தெரிவுகள்: (1) காபீரனீரொட்சைட்டு, (2) ஒட்சிசன், (3) நைதரசன், (4) ஐதரசன். ஒளித்தொகுப்பின் போது ஒட்சிசன் வாயு வெளியேற்றப்படுகிறது.", | |
| "answer": "2" | |
| }, | |
| { | |
| "question": "විද්යුත් ධාරාව මැනීම සඳහා භාවිත කරන ජාත්යන්තර සම්මත (SI) ඒකකය කුමක්ද?", | |
| "choices": ["වෝල්ට් (V)", "ඕම් (Ω)", "වොට් (W)", "ඇම්පියර් (A)"], | |
| "analysis": "The question asks for the SI unit used to measure electric current. Options: (1) Volt, (2) Ohm, (3) Watt, (4) Ampere. Electric current is measured in Amperes (A).", | |
| "analysis_ta": "வினா: மின்னோட்டத்தை அளவிடப் பயன்படும் சர்வதேச நியம (SI) அலகு யாது? தெரிவுகள்: (1) வோல்ட் (V), (2) ஓம் (Ω), (3) வாட் (W), (4) அம்பியர் (A). மின்னோட்டத்தின் SI அலகு அம்பியர் (A) ஆகும்.", | |
| "answer": "4" | |
| }, | |
| { | |
| "question": "ජලයේ රසායනික සූත්රය නිවැරදිව දක්වා ඇත්තේ කවරේද?", | |
| "choices": ["H2O", "CO2", "NaCl", "CH4"], | |
| "analysis": "The question asks for the chemical formula of water. Options: (1) H2O, (2) CO2, (3) NaCl, (4) CH4. Water is H2O.", | |
| "analysis_ta": "வினா: நீரின் இரசாயனச் சூத்திரம் எது? தெரிவுகள்: (1) H2O, (2) CO2, (3) NaCl, (4) CH4. நீரின் இரசாயனச் சூத்திரம் H2O ஆகும்.", | |
| "answer": "1" | |
| }, | |
| { | |
| "question": "දිග මැනීම සඳහා භාවිත වන ජාත්යන්තර සම්මත (SI) ඒකකය කුමක්ද?", | |
| "choices": ["මිලිමීටර්", "සෙන්ටිමීටර්", "මීටර්", "කිලෝමීටර්"], | |
| "analysis": "The question asks for the SI base unit of length. Options: (1) millimeter, (2) centimeter, (3) meter, (4) kilometer. The SI base unit of length is the meter.", | |
| "analysis_ta": "வினா: நீளத்தை அளவிடப் பயன்படும் சர்வதேச நியம (SI) அலகு எது? தெரிவுகள்: (1) மில்லிமீற்றர், (2) சென்ரிமீற்றர், (3) மீற்றர், (4) கிலோமீற்றர். நீளத்தின் SI அடிப்படை அலகு மீற்றர் ஆகும்.", | |
| "answer": "3" | |
| } | |
| ], | |
| "social_science": [ | |
| { | |
| "question": "ශ්රී ලංකාවේ මුදල් නෝට්ටු නිකුත් කිරීමේ නිල බලය හිමි ආයතනය කුමක්ද?", | |
| "choices": ["මුදල් අමාත්යාංශය", "ශ්රී ලංකා මහ බැංකුව", "ලංකා බැංකුව", "මහා භාණ්ඩාගාරය"], | |
| "analysis": "The question asks which institution has official authority to issue currency notes in Sri Lanka. Options: (1) Ministry of Finance, (2) Central Bank of Sri Lanka, (3) Bank of Ceylon, (4) General Treasury. The Central Bank of Sri Lanka issues currency.", | |
| "analysis_ta": "வினா: இலங்கையில் நாணயத்தாள்களை வெளியிடும் அதிகாரம் கொண்ட நிறுவனம் எது? தெரிவுகள்: (1) நிதி அமைச்சு, (2) இலங்கை மத்திய வங்கி, (3) இலங்கை வங்கி, (4) மகா திறைசேரி. இலங்கை மத்திய வங்கியே நாணயத்தாள்களை வெளியிடுகிறது.", | |
| "answer": "2" | |
| }, | |
| { | |
| "question": "නිෂ්පාදන සාධක සතරට අයත් නොවන සාධකය තෝරන්න.", | |
| "choices": ["භූමිය", "ශ්රමය", "ප්රාග්ධනය", "උද්ධමනය"], | |
| "analysis": "The question asks which item does NOT belong to the four factors of production. Options: (1) Land, (2) Labor, (3) Capital, (4) Inflation. Land, labor, capital, and entrepreneurship are factors of production; inflation is not.", | |
| "analysis_ta": "வினா: நான்கு உற்பத்திக் காரணிகளில் அடங்காத ஒன்றைத் தெரிவு செய்க. தெரிவுகள்: (1) நிலம், (2) உழைப்பு, (3) மூலதனம், (4) பணவீக்கம். நிலம், உழைப்பு, மூலதனம், முயற்சியாண்மை என்பன உற்பத்திக் காரணிகள்; பணவீக்கம் உற்பத்திக் காரணி அல்ல.", | |
| "answer": "4" | |
| }, | |
| { | |
| "question": "ශ්රී ලංකාවේ දිගම ගංගාව කුමක්ද?", | |
| "choices": ["මහවැලි ගඟ", "කැලණි ගඟ", "කළු ගඟ", "වලවේ ගඟ"], | |
| "analysis": "The question asks for the longest river in Sri Lanka. Options: (1) Mahaweli River, (2) Kelani River, (3) Kalu River, (4) Walawe River. Mahaweli River (335 km) is the longest.", | |
| "analysis_ta": "வினா: இலங்கையின் மிக நீளமான ஆறு எது? தெரிவுகள்: (1) மகாவலி கங்கை, (2) களனி கங்கை, (3) களு கங்கை, (4) வளவை கங்கை. மகாவலி கங்கை (335 கி.மீ) இலங்கையின் மிக நீளமான ஆறாகும்.", | |
| "answer": "1" | |
| }, | |
| { | |
| "question": "ශ්රී ලංකාවේ භූමි ප්රමාණය අනුව විශාලතම පළාත කුමක්ද?", | |
| "choices": ["බස්නාහිර පළාත", "වයඹ පළාත", "උතුරු මැද පළාත", "දකුණු පළාත"], | |
| "analysis": "The question asks for the largest province in Sri Lanka by land area. Options: (1) Western, (2) North Western, (3) North Central, (4) Southern. North Central Province is the largest by area.", | |
| "analysis_ta": "வினா: நிலப்பரப்பின் அடிப்படையில் இலங்கையின் மிகப்பெரிய மாகாணம் எது? தெரிவுகள்: (1) மேல் மாகாணம், (2) வயம்ப மாகாணம், (3) வடமத்திய மாகாணம், (4) தென் மாகாணம். வடமத்திய மாகாணமே நிலப்பரப்பில் மிகப்பெரியது.", | |
| "answer": "3" | |
| } | |
| ], | |
| "language": [ | |
| { | |
| "question": "'ගම්පෙරළිය' නවකතාව රචනා කළ ලේඛකයා කවුරුන්ද?", | |
| "choices": ["කුමාරතුංග මුනිදාස", "මාර්ටින් වික්රමසිංහ", "ඩබ්ලියු. ඒ. සිල්වා", "පියදාස සිරිසේන"], | |
| "analysis": "The question asks who wrote the Sinhala novel 'Gamperaliya'. Options: (1) Kumaratunga Munidasa, (2) Martin Wickramasinghe, (3) W. A. Silva, (4) Piyadasa Sirisena. Gamperaliya was written by Martin Wickramasinghe.", | |
| "analysis_ta": "வினா: 'கம்பெரலிய' நாவலை எழுதிய ஆசிரியர் யார்? தெரிவுகள்: (1) குமாரதுங்க முனிதாச, (2) மார்ட்டின் விக்கிரமசிங்க, (3) டபிள்யூ. ஏ. சில்வா, (4) பியதாச சிறிசேன. கம்பெரலிய நாவலை எழுதியவர் மார்ட்டின் விக்கிரமசிங்க ஆவார்.", | |
| "answer": "2" | |
| }, | |
| { | |
| "question": "සිංහල ව්යාකරණයට අනුව උක්ත ආඛ්යාත සම්බන්ධය නිවැරදි වාක්යය තෝරන්න.", | |
| "choices": ["ළමයි පොත් කියවයි.", "මම පාසල් ගියෝය.", "අපි ගීත ගයති.", "ගොවියෝ කුඹුරු කොටති."], | |
| "analysis": "The question asks for the grammatically correct Sinhala subject-verb agreement. Options 1, 2, 3 mismatch plural/first-person subjects with third-person singular/plural verbs. Option 4 ('ගොවියෝ කුඹුරු කොටති') correctly pairs plural animate subject 'ගොවියෝ' with plural verb 'කොටති'.", | |
| "analysis_ta": "வினா: சிங்கள இலக்கணத்தின்படி எழுவாய்-பயனிலை இயைபு சரியாக உள்ள வாக்கியத்தைத் தெரிவு செய்க. 4-வது தெரிவு ('ගොවියෝ කුඹුරු කොටති') பன்மை எழுவாயுடன் ('ගොවියෝ') பன்மை வினைமுற்றை ('කොටති') சரியாக இணைக்கிறது.", | |
| "answer": "4" | |
| }, | |
| { | |
| "question": "නූතන සම්මත සිංහල වර්ණ මාලාවේ අඩංගු මුළු අක්ෂර ගණන කීයද?", | |
| "choices": ["60 කි.", "54 කි.", "36 කි.", "42 කි."], | |
| "analysis": "The question asks for the total number of letters in the modern standard Sinhala alphabet (Nuthana Sinhala Varnamalawa). It contains 60 letters.", | |
| "analysis_ta": "வினா: நவீன நியம சிங்கள நெடுங்கணக்கில் உள்ள மொத்த எழுத்துக்களின் எண்ணிக்கை யாது? தெரிவுகள்: (1) 60, (2) 54, (3) 36, (4) 42. நவீன சிங்கள நெடுங்கணக்கில் மொத்தம் 60 எழுத்துக்கள் உள்ளன.", | |
| "answer": "1" | |
| }, | |
| { | |
| "question": "'හිරු' යන පදයට සමානාර්ථ පදයක් නොවන්නේ කුමක්ද?", | |
| "choices": ["සූර්යයා", "දිනකර", "නිශාකර", "රවි"], | |
| "analysis": "The question asks which word is NOT a synonym for 'Hiru' (Sun). Options: (1) Suryaya (Sun), (2) Dinakara (Sun), (3) Nishakara (Moon - night maker), (4) Ravi (Sun). Nishakara means Moon, not Sun.", | |
| "analysis_ta": "வினா: 'ஹிரு' (சூரியன்) என்ற சொல்லுக்கு ஒத்த கருத்துச் சொல் அல்லாதது எது? தெரிவுகள்: (1) சூர்யயா (சூரியன்), (2) தினகர (சூரியன்), (3) நிஷாகர (சந்திரன்), (4) ரவி (சூரியன்). நிஷாகர என்பது சந்திரனைக் குறிக்கும்.", | |
| "answer": "3" | |
| } | |
| ], | |
| "other": [ | |
| { | |
| "question": "මිනිස් සිරුරේ වර්ධනයට සහ පටක අලුත්වැඩියාවට ප්රධාන වශයෙන් අවශ්ය වන පෝෂකය කුමක්ද?", | |
| "choices": ["කාබෝහයිඩ්රේට්", "ප්රෝටීන්", "ලිපිඩ", "ඛනිජ ලවණ"], | |
| "analysis": "The question asks which nutrient is primarily needed for human body growth and tissue repair. Options: (1) Carbohydrates, (2) Proteins, (3) Lipids, (4) Minerals. Proteins are responsible for growth and tissue repair.", | |
| "analysis_ta": "வினா: மனித உடல் வளர்ச்சிக்கும் இழையங்களைப் பழுதுபார்த்தலுக்கும் பிரதானமாகத் தேவைப்படும் போசணைப் பொருள் எது? தெரிவுகள்: (1) காபோவைதரேற்று, (2) புரதம், (3) இலிப்பிட்டு, (4) கனியுப்பு. புரதமே உடல் வளர்ச்சிக்குப் பிரதானமாகத் தேவைப்படுகிறது.", | |
| "answer": "2" | |
| }, | |
| { | |
| "question": "සමබල ආහාර වේලක අඩංගු විය යුතු සංඝටකයක් නොවන්නේ කුමක්ද?", | |
| "choices": ["විටමින්", "ප්රෝටීන්", "ජලය", "කෘත්රිම වර්ණක"], | |
| "analysis": "The question asks what is NOT an essential component of a balanced diet. Options: (1) Vitamins, (2) Proteins, (3) Water, (4) Artificial colorings. Artificial colorings are not part of a healthy balanced diet.", | |
| "analysis_ta": "வினா: சமநிலை உணவில் அடங்கக்கூடாத கூறு எது? தெரிவுகள்: (1) விற்றமின், (2) புரதம், (3) நீர், (4) செயற்கை நிறமூட்டிகள். செயற்கை நிறமூட்டிகள் சமநிலை உணவின் கூறு அல்ல.", | |
| "answer": "4" | |
| }, | |
| { | |
| "question": "පරිගණකයක මධ්ය සැකසුම් ඒකකය හඳුන්වන කෙටි නාමය කුමක්ද?", | |
| "choices": ["CPU", "RAM", "ROM", "USB"], | |
| "analysis": "The question asks for the abbreviation of a computer's Central Processing Unit. It is CPU.", | |
| "analysis_ta": "வினா: கணினியின் மையச் செயற்பாட்டு அலகைக் குறிக்கும் சுருக்கப் பெயர் யாது? அது CPU ஆகும்.", | |
| "answer": "1" | |
| }, | |
| { | |
| "question": "ශාක වර්ධනය සඳහා අත්යවශ්ය මහා පෝෂක තුන වන්නේ,", | |
| "choices": ["යකඩ, තඹ, සින්ක්", "කැල්සියම්, මැග්නීසියම්, ගෙන්දගම්", "නයිට්රජන්, පොස්පරස්, පොටෑසියම්", "බෝරෝන්, මැංගනීස්, ක්ලෝරීන්"], | |
| "analysis": "The question asks for the three primary macronutrients essential for plant growth. Options: (3) Nitrogen, Phosphorus, Potassium (NPK). NPK are the three primary macronutrients.", | |
| "analysis_ta": "வினா: தாவர வளர்ச்சிக்கு அத்தியாவசியமான மூன்று மாபோசணைப் பதார்த்தங்கள் யாவை? தெரிவு (3) நைதரசன், பொசுபரசு, பொட்டாசியம் (NPK) ஆகும்.", | |
| "answer": "3" | |
| } | |
| ] | |
| } | |
| # Standard 4 balanced exemplars ordered (2, 4, 1, 3) to break sequential bias | |
| GLOBAL_BALANCED_EXEMPLARS = [ | |
| EXEMPLARS_BY_DOMAIN["humanities"][0], # answer: 2 | |
| EXEMPLARS_BY_DOMAIN["social_science"][1],# answer: 4 | |
| EXEMPLARS_BY_DOMAIN["stem"][2], # answer: 1 | |
| EXEMPLARS_BY_DOMAIN["language"][3], # answer: 3 | |
| ] | |
| def normalize_category(raw_category: str) -> str: | |
| """Normalizes dataset category strings (e.g., 'Social_science', 'social science', 'Humanities').""" | |
| cat = (raw_category or "").strip().lower().replace(" ", "_") | |
| if cat in EXEMPLARS_BY_DOMAIN: | |
| return cat | |
| return "other" | |
| def build_few_shot_prompt(question_dict: dict, num_shots: int = 4, cot: bool = False, cot_lang: str = "en") -> str: | |
| """ | |
| Constructs a few-shot prompt with strictly balanced (2, 4, 1, 3) exemplars | |
| followed by the target question. | |
| If cot=True, includes a concise 1-line translation & fact-check Analysis (in English or Tamil) before Answer. | |
| """ | |
| subject = question_dict.get("subject", "සාමාන්ය දැනීම") | |
| category = normalize_category(question_dict.get("category", "")) | |
| if cot and cot_lang == "ta": | |
| prompt_parts = [ | |
| f"Subject: {subject} (இலங்கைப் பாடத்திட்டம் - சிங்கள மூலம்).\n" | |
| f"ஒவ்வொரு வினாவிற்கும் சிங்கள வினாவையும் தெரிவுகளையும் தமிழில் சுருக்கமாக மொழிபெயர்த்து ('Analysis:'), " | |
| f"சரியான விடையைத் தீர்மானித்து 'Answer: <digit>' (1, 2, 3, or 4) என எழுதுக.\n" | |
| ] | |
| elif cot: | |
| prompt_parts = [ | |
| f"Subject: {subject} (Sri Lankan School Curriculum - Sinhala Medium).\n" | |
| f"For each question, briefly translate the Sinhala question and options into English in 1-2 sentences ('Analysis:'), " | |
| f"verify the curriculum fact, and output 'Answer: <digit>' (1, 2, 3, or 4).\n" | |
| ] | |
| else: | |
| prompt_parts = [ | |
| f"මෙය {subject} විෂයට අදාළ බහුවරණ ප්රශ්නයකි. පහත උදාහරණ පරිදි නිවැරදි පිළිතුරේ අංකය (1, 2, 3, හෝ 4) පමණක් තෝරන්න.\n" | |
| ] | |
| # Select exemplars: domain specific if available, else global balanced | |
| exemplars = GLOBAL_BALANCED_EXEMPLARS[:num_shots] | |
| if category in EXEMPLARS_BY_DOMAIN and len(EXEMPLARS_BY_DOMAIN[category]) >= num_shots: | |
| exemplars = EXEMPLARS_BY_DOMAIN[category][:num_shots] | |
| for ex in exemplars: | |
| opts_formatted = "\n".join([f"{idx+1}. {c}" for idx, c in enumerate(ex["choices"])]) | |
| if cot: | |
| analysis_text = ex.get("analysis_ta", ex["analysis"]) if cot_lang == "ta" else ex["analysis"] | |
| ex_block = ( | |
| f"ප්රශ්නය: {ex['question']}\n{opts_formatted}\n" | |
| f"Analysis: {analysis_text}\n" | |
| f"Answer: {ex['answer']}\n" | |
| ) | |
| else: | |
| ex_block = f"ප්රශ්නය: {ex['question']}\n{opts_formatted}\nපිළිතුර: {ex['answer']}\n" | |
| prompt_parts.append(ex_block) | |
| # Now the target question | |
| q_text = question_dict.get("question", "").strip() | |
| choices = question_dict.get("choices") | |
| if choices is None: | |
| choices = question_dict.get("options", []) | |
| if isinstance(choices, dict): | |
| keys = sorted(choices.keys(), key=lambda x: str(x)) | |
| opt_list = [choices[k] for k in keys] | |
| elif isinstance(choices, list): | |
| opt_list = choices | |
| else: | |
| opt_list = [] | |
| target_opts = "\n".join([f"{idx+1}. {c}" for idx, c in enumerate(opt_list)]) | |
| if cot: | |
| target_block = f"ප්රශ්නය: {q_text}\n{target_opts}\nAnalysis:" | |
| else: | |
| target_block = f"දැන් මෙම ප්රශ්නයට පිළිතුරු දෙන්න:\nප්රශ්නය: {q_text}\n{target_opts}\nපිළිතුර: " | |
| prompt_parts.append(target_block) | |
| return "\n".join(prompt_parts) | |