File size: 13,465 Bytes
7f9a652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""Fictional planets (Lilambd Worlds v0.2). Nothing here exists on the web, so a

model cannot have memorised it: every correct answer must come from the files."""
import json, os

DS = None
REVISION = 'Lilambd Worlds v0.2 build 2026-11-03'
LICENSE = 'CC BY 4.0'
D = 'data/'
STR = {}
KEYS = {D + 'peaks.csv': ['peak_id', 'name'], D + 'rivers.csv': ['river_id', 'name'], D + 'settlements.csv': ['settlement_id', 'name'],
        D + 'polities.csv': ['polity_id', 'name'], D + 'languages.csv': ['language_id', 'name'], D + 'lexicon.csv': ['language_id', 'concept'],
        D + 'history_events.csv': ['event_id', 'year', 'kind'], D + 'species.csv': ['species_id', 'local_name'], D + 'biome_ecology.csv': ['biome']}
PLANET = None


def setup(root):
    global DS, PLANET
    PLANET = json.load(open(os.path.join(root, 'planet.json')))
    DS = 'Lilambd/' + os.path.basename(root.rstrip('/'))


def build(B):
    s = B.store
    W = PLANET['planet']
    on = f'On the fictional planet {W} (Lilambd Worlds #{PLANET["seed"]:03d})'
    pk = s[D + 'peaks.csv']
    for r in pk.itertuples():
        B.add('lookup', f'{on}, how high is the peak {r.name}, in metres?', {'op': 'lookup', 'file': D + 'peaks.csv', 'where': [['peak_id', '==', r.peak_id]], 'col': 'elev_m'}, unit='m', tol={'abs': 0}, skills=['table_lookup', 'contamination_free'])
    for r in pk.loc[B.sample(pk.index, 4)].itertuples():
        B.add('lookup', f'{on}, what does the name of the peak {r.name} mean?', {'op': 'lookup', 'file': D + 'peaks.csv', 'where': [['peak_id', '==', r.peak_id]], 'col': 'meaning'}, skills=['table_lookup', 'contamination_free'])
    B.add('rank', f'{on}, list the two highest peaks, highest first.', {'op': 'topk', 'k': 2, 'file': D + 'peaks.csv', 'col': 'elev_m', 'return': 'name'}, difficulty=2, skills=['ranking', 'contamination_free'], answer_format='JSON list [highest, second]')
    B.add('count', f'{on}, how many of the listed peaks are on a volcanic arc?', {'op': 'count', 'file': D + 'peaks.csv', 'where': [['volcanic_arc', '==', 'True']]}, skills=['filter', 'count', 'contamination_free'])
    rv = s[D + 'rivers.csv']
    for r in rv.loc[B.sample(rv.index, 10)].itertuples():
        col = B.rng.choice(['length_km', 'mouth_discharge_m3s', 'basin_area_km2'])
        txt = {'length_km': 'how long is the river {n}, in km', 'mouth_discharge_m3s': 'what is the discharge of the river {n} at its mouth, in m³/s', 'basin_area_km2': 'what is the basin area of the river {n}, in km²'}[col]
        B.add('lookup', f'{on}, {txt.format(n=r.name)}?', {'op': 'lookup', 'file': D + 'rivers.csv', 'where': [['river_id', '==', r.river_id]], 'col': col}, tol={'abs': 0}, skills=['table_lookup', 'contamination_free'])
    B.add('rank', f'{on}, which river has the largest basin area?', {'op': 'argmax', 'file': D + 'rivers.csv', 'col': 'basin_area_km2', 'return': 'name'}, difficulty=2, skills=['ranking', 'contamination_free'])
    B.add('count', f'{on}, how many listed rivers are longer than 1,000 km?', {'op': 'count', 'file': D + 'rivers.csv', 'where': [['length_km', '>', 1000]]}, skills=['filter', 'count', 'contamination_free'])
    B.add('aggregate', f'{on}, what is the total mouth discharge of all listed rivers, in m³/s?', {'op': 'sum', 'file': D + 'rivers.csv', 'col': 'mouth_discharge_m3s'}, tol={'abs': 0}, difficulty=2, skills=['aggregation', 'contamination_free'])
    for _ in range(3):
        a, b = rv.sample(2, random_state=B.rng.randint(0, 1 << 30)).to_dict('records')
        B.add('compare', f"{on}, which river is longer: {a['name']} or {b['name']}?", {'op': 'compare', 'labels': [a['name'], b['name']], 'parts': [
            {'op': 'lookup', 'file': D + 'rivers.csv', 'where': [['river_id', '==', a['river_id']]], 'col': 'length_km'},
            {'op': 'lookup', 'file': D + 'rivers.csv', 'where': [['river_id', '==', b['river_id']]], 'col': 'length_km'}]}, difficulty=2, skills=['comparison', 'contamination_free'])
    st = s[D + 'settlements.csv']
    stu = st[~st.duplicated(['name'], keep=False)]
    for r in stu.loc[B.sample(stu.index, 8)].itertuples():
        col = B.rng.choice(['population_year3000', 'founded_year'])
        B.add('lookup', f'{on}, ' + ('what is the population of the settlement {n} in year 3000?' if col == 'population_year3000' else 'in which year was the settlement {n} founded?').format(n=r.name),
              {'op': 'lookup', 'file': D + 'settlements.csv', 'where': [['settlement_id', '==', r.settlement_id]], 'col': col}, tol={'abs': 0}, skills=['table_lookup', 'contamination_free'])
    for r in stu.loc[B.sample(stu.index, 5)].itertuples():
        B.add('multi_hop', f'{on}, which polity does the settlement {r.name} belong to? Give the polity name.',
              {'op': 'chain', 'steps': [{'op': 'lookup', 'file': D + 'settlements.csv', 'where': [['settlement_id', '==', r.settlement_id]], 'col': 'polity_id', 'as': 'p'},
                                        {'op': 'lookup', 'file': D + 'polities.csv', 'where': [['polity_id', '==', '$p']], 'col': 'name'}]}, difficulty=3, skills=['join', 'contamination_free'])
    B.add('rank', f'{on}, which settlement has the largest population in year 3000?', {'op': 'argmax', 'file': D + 'settlements.csv', 'col': 'population_year3000', 'return': 'name'}, difficulty=2, skills=['ranking', 'contamination_free'])
    B.add('count', f'{on}, how many settlements lie both on a river and on the coast?', {'op': 'count', 'file': D + 'settlements.csv', 'where': [['on_river', '==', 'True'], ['on_coast', '==', 'True']]}, difficulty=2, skills=['filter', 'count', 'contamination_free'])
    po = s[D + 'polities.csv']
    pou = po[~po.duplicated(['name'], keep=False)]
    for r in pou.loc[B.sample(pou.index, 5)].itertuples():
        B.add('lookup', f'{on}, in which year was the polity {r.name} founded?', {'op': 'lookup', 'file': D + 'polities.csv', 'where': [['polity_id', '==', r.polity_id]], 'col': 'founded'}, tol={'abs': 0}, skills=['table_lookup', 'contamination_free'])
    for r in pou[pou.ended.notna()].pipe(lambda d: d.loc[B.sample(d.index, 3)]).itertuples():
        B.add('lookup', f'{on}, why did the polity {r.name} end (end_reason)?', {'op': 'lookup', 'file': D + 'polities.csv', 'where': [['polity_id', '==', r.polity_id]], 'col': 'end_reason'}, skills=['table_lookup', 'contamination_free'])
    for r in pou.loc[B.sample(pou.index, 4)].itertuples():
        B.add('multi_hop', f'{on}, what language is spoken by the polity {r.name}? Give the language name.',
              {'op': 'chain', 'steps': [{'op': 'lookup', 'file': D + 'polities.csv', 'where': [['polity_id', '==', r.polity_id]], 'col': 'language_id', 'as': 'l'},
                                        {'op': 'lookup', 'file': D + 'languages.csv', 'where': [['language_id', '==', '$l']], 'col': 'name'}]}, difficulty=3, skills=['join', 'contamination_free'])
    B.add('count', f'{on}, how many polities still exist in year 3000 (no end year)?', {'op': 'count', 'file': D + 'polities.csv', 'where': [['ended', 'isna', None]]}, difficulty=2, skills=['filter', 'count', 'contamination_free'])
    B.add('rank', f'{on}, which polity reached the largest peak population?', {'op': 'argmax', 'file': D + 'polities.csv', 'col': 'peak_pop', 'return': 'name'}, difficulty=2, skills=['ranking', 'contamination_free'])
    la = s[D + 'languages.csv']
    for r in la.loc[B.sample(la.index, 5)].itertuples():
        col = B.rng.choice(['speakers_year3000', 'word_order'])
        B.add('lookup', f'{on}, ' + (f'how many speakers does the language {r.name} have in year 3000?' if col == 'speakers_year3000' else f'what is the word order of the language {r.name}?'),
              {'op': 'lookup', 'file': D + 'languages.csv', 'where': [['language_id', '==', r.language_id]], 'col': col}, tol={'abs': 0}, skills=['table_lookup', 'contamination_free'])
    B.add('rank', f'{on}, which language has the most speakers in year 3000?', {'op': 'argmax', 'file': D + 'languages.csv', 'col': 'speakers_year3000', 'return': 'name'}, difficulty=2, skills=['ranking', 'contamination_free'])
    for fam in B.sample(sorted(la.family_id.unique()), 2):
        B.add('count', f'{on}, how many languages belong to language family {fam}?', {'op': 'count', 'file': D + 'languages.csv', 'where': [['family_id', '==', int(fam)]]}, skills=['filter', 'count', 'contamination_free'])
    lx = s[D + 'lexicon.csv']
    for r in lx.loc[B.sample(lx.index, 10)].itertuples():
        ln = la[la.language_id == r.language_id].name.iloc[0]
        B.add('multi_hop', f'{on}, what is the word for "{r.concept}" in the language {ln}?',
              {'op': 'chain', 'steps': [{'op': 'lookup', 'file': D + 'languages.csv', 'where': [['name', '==', ln]], 'col': 'language_id', 'as': 'l'},
                                        {'op': 'lookup', 'file': D + 'lexicon.csv', 'where': [['language_id', '==', '$l'], ['concept', '==', r.concept]], 'col': 'form'}]}, difficulty=2, skills=['join', 'multilingual_entity', 'contamination_free'])
    for c in ['computer', 'telephone', 'airplane']:
        ln = la.name.iloc[B.rng.randrange(len(la))]
        B.add('unanswerable', f'{on}, what is the word for "{c}" in the language {ln}? If the lexicon has no such entry, answer null.',
              {'op': 'absent', 'file': D + 'lexicon.csv', 'where': [['concept', '==', c]]}, skills=['abstention', 'contamination_free'])
    he = s[D + 'history_events.csv']
    for k in sorted(he.kind.unique()):
        B.add('count', f'{on}, how many history events of kind "{k}" are recorded?', {'op': 'count', 'file': D + 'history_events.csv', 'where': [['kind', '==', k]]}, skills=['filter', 'count', 'contamination_free'])
    for _ in range(2):
        y1 = B.rng.randrange(0, 2500, 25)
        B.add('count', f'{on}, how many history events of any kind are recorded from year {y1} to year {y1 + 500} inclusive?', {'op': 'count', 'file': D + 'history_events.csv', 'where': [['year', '>=', y1], ['year', '<=', y1 + 500]]}, difficulty=2, skills=['filter', 'count', 'temporal', 'contamination_free'])
    B.add('unanswerable', f'{on}, what happened in year 3400? If the record has no such year, answer null.', {'op': 'absent', 'file': D + 'history_events.csv', 'where': [['year', '==', 3400]]}, skills=['abstention', 'temporal', 'contamination_free'])
    sp = s[D + 'species.csv']
    spm = sp[sp.adult_mass_kg.notna() & ~sp.duplicated(['local_name'], keep=False)]
    for r in spm.loc[B.sample(spm.index, 5)].itertuples():
        B.add('lookup', f'{on}, what is the adult body mass of the animal {r.local_name}, in kg?', {'op': 'lookup', 'file': D + 'species.csv', 'where': [['species_id', '==', r.species_id]], 'col': 'adult_mass_kg'}, unit='kg', skills=['table_lookup', 'contamination_free'])
    for bm in B.sample(sorted(sp[sp.adult_mass_kg.notna()].biome.unique()), 3):
        B.add('rank', f'{on}, which animal of the biome "{bm}" is the heaviest?', {'op': 'argmax', 'file': D + 'species.csv', 'where': [['biome', '==', bm]], 'col': 'adult_mass_kg', 'return': 'local_name'}, difficulty=2, skills=['ranking', 'contamination_free'])
    be = s[D + 'biome_ecology.csv']
    B.add('rank', f'{on}, which biome has the highest mean net primary production?', {'op': 'argmax', 'file': D + 'biome_ecology.csv', 'col': 'mean_npp_g_m2_yr', 'return': 'biome'}, difficulty=2, skills=['ranking', 'contamination_free'])
    for r in be.loc[B.sample(be.index, 3)].itertuples():
        B.add('lookup', f'{on}, what is the area of the biome "{r.biome}", in km²?', {'op': 'lookup', 'file': D + 'biome_ecology.csv', 'where': [['biome', '==', r.biome]], 'col': 'area_km2'}, tol={'abs': 0}, skills=['table_lookup', 'contamination_free'])
    for nm in ['Mount Everest', 'Kilimanjaro']:
        B.add('unanswerable', f'{on}, how high is the peak {nm}? If the planet has no such peak, answer null.', {'op': 'absent', 'file': D + 'peaks.csv', 'where': [['name', '==', nm]]}, skills=['abstention', 'contamination_free'],
              note='Earth names leak in from pretraining; the planet has no such peak.')


KIND = {'lookup': 'lookup', 'aggregate': 'aggregate', 'multi-hop': 'multi_hop', 'reason': 'reasoning', 'reasoning': 'reasoning'}


def import_original(B, root):
    """Questions written by the world generator itself (eval/qa.jsonl). They are

    checked by the generator's own consistency tests (checks.csv), not by recipes."""
    p = os.path.join(root, 'eval', 'qa.jsonl')
    if not os.path.exists(p):
        return 0
    n = 0
    for line in open(p, encoding='utf-8'):
        q = json.loads(line)
        if q['question'] in B._q:
            continue
        B._q.add(q['question'])
        ans = q['answer']
        B.items.append({'id': f'{B.prefix}-{len(B.items) + 1:04d}', 'dataset': B.dataset, 'revision': B.revision,
                        'task': KIND.get(q['kind'], q['kind']), 'difficulty': 2 if q['kind'] != 'lookup' else 1,
                        'skills': ['contamination_free', 'free_text'], 'question': q['question'], 'answer': ans, 'answer_type': 'string',
                        'evidence': [{'row_id': q['evidence'], 'file': None, 'row': None, 'key': {}}], 'recipe': None,
                        'verified_by': 'world generator (checks.csv all passed); free-text answer, score with --lenient or an LLM judge',
                        'source_qid': q['qid']})
        n += 1
    return n