"""Prepare grouped human datasets and explicitly marked synthetic training inputs.""" import collections import argparse import csv import hashlib import json import math from pathlib import Path import random from huggingface_hub import hf_hub_download ROOT = Path(__file__).resolve().parent DATA = ROOT / 'data' SEED = 20261004 MORALS = ['care','equality','proportionality','loyalty','authority','purity','thin_morality','non_moral'] SENSES = ['vision','hearing','smell','taste','touch','interoception'] MORAL_SEEDS = { 'care': ["Leaving injured people without help is cruel.", "We should protect children from being hurt.", "She stayed with the sick neighbor so he would not suffer alone.", "Hurting a helpless animal is wrong.", "The shelter gives vulnerable families a safe place to sleep.", "They should provide clean water to people who are suffering.", "I oppose that policy because it exposes patients to avoidable harm.", "Please be gentle with people who are struggling.", "He comforted the frightened child instead of mocking her.", "Our first responsibility is to prevent unnecessary suffering."], 'equality': ["Everyone should have equal access to education.", "The same rights should apply regardless of someone's race.", "It is unfair to deny women the opportunities given to men.", "Each person deserves an equal voice in the decision.", "Treating one ethnic group as less worthy is wrong.", "The rule should protect rich and poor people equally.", "We must end discrimination against disabled applicants.", "No family should be excluded because of its religion.", "Equal rights belong to all citizens.", "I object to a system that gives one group privileges denied to another."], 'proportionality': ["People who contribute more should receive a larger share of the reward.", "A punishment should be proportional to the offense.", "The bonus should reflect the work each employee actually did.", "Taking credit for someone else's effort is cheating.", "It is unfair to get paid for work you never performed.", "Those who kept their commitments deserve the promised compensation.", "Rewards should match merit rather than personal connections.", "The penalty is far too severe for such a minor violation.", "She earned that position through her qualifications.", "Someone who did twice the work deserves more than someone who did none."], 'loyalty': ["Abandoning your teammates for personal gain is a betrayal.", "We should stand by our community when times are hard.", "He betrayed the friends who had trusted him.", "I will not turn my back on the group that supported me.", "We owe loyalty to our family.", "Selling out your own team is shameful.", "She defended her community even when it cost her something.", "Sticking together matters more than chasing individual advantage.", "I respect people who remain faithful to their commitments to their group.", "They deserted their allies as soon as the situation became difficult."], 'authority': ["We should respect the legitimate authority of the court.", "Ignoring a lawful order undermines the institution.", "The leader has a duty to uphold the rules fairly.", "Disrespecting our elders violates a valued tradition.", "Officials should not abuse the powers entrusted to them.", "A commander must be accountable for how that authority is used.", "The established rules deserve respect even when they are inconvenient.", "Overriding the elected council without permission is an abuse of authority.", "We should honor the responsibilities that come with leadership.", "That official is undermining the institution he was appointed to serve."], 'purity': ["Desecrating a sacred place is wrong.", "We should preserve the sanctity of this ceremony.", "Treating a holy object as rubbish is a violation of what it represents.", "I regard that practice as spiritually degrading.", "The ritual must remain untainted by profane acts.", "They defiled the place that our community holds sacred.", "This tradition calls on us to keep our bodies spiritually pure.", "It is shameful to corrupt something meant to be sacred.", "We have a duty to protect the holiness of that site.", "That conduct violates our ideals of moral purity."], 'thin_morality': ["That was simply wrong, whatever excuse you offer.", "We ought to do the right thing.", "I cannot support behavior I consider morally unacceptable.", "That choice was unethical.", "Being a decent person matters.", "There is no moral justification for that decision.", "I think this is a question of right and wrong.", "You should act according to your conscience.", "That is a morally good decision.", "What they did was bad, and they should acknowledge it."], 'non_moral': ["The bus arrives at six.", "I saved the spreadsheet in the project folder.", "The weather forecast lists rain tomorrow.", "This desk is one meter wide.", "The package contains three cables.", "I am reading a book about astronomy.", "We met at the station on Tuesday.", "The application opens a new window.", "My coffee is on the kitchen counter.", "The next chapter begins on page forty."], } # Different literal scenes, not just framing variants of one sensation. SENSORY_SEEDS = { 'vision': [('glow','The lantern cast a warm glow across the wall.'),('striped','A striped scarf lay beside the window.'),('sparkled','Sunlight sparkled on the lake.'),('silhouette','Her silhouette appeared against the bright sky.'),('crimson','The leaves turned crimson in autumn.'),('blur','Without my glasses the sign was a blur.'),('shadow','A long shadow crossed the floor.'),('glitter','Tiny flecks of glitter reflected the light.'),('shimmer','I noticed a shimmer on the water.'),('bright','The screen was too bright to look at comfortably.')], 'hearing': [('rattle','A loose panel made a rattle whenever the train moved.'),('whisper','I heard a whisper from the other side of the room.'),('clang','The dropped pan landed with a clang.'),('humming','The engine was humming softly.'),('crackle','We listened to the crackle of the fire.'),('echo','My footsteps produced an echo in the hallway.'),('chime','A chime sounded when the door opened.'),('buzz','There was a faint buzz coming from the speaker.'),('thunder','The thunder was loud enough to wake me.'),('melody','She played a gentle melody on the flute.')], 'smell': [('aroma','The aroma of fresh bread filled the bakery.'),('musty','The old cupboard smelled musty.'),('scent','The scent of lavender drifted through the room.'),('reek','There was a reek of spoiled fish near the bin.'),('fragrance','I noticed the fragrance of roses in the garden.'),('smoky','The air smelled smoky after the fire.'),('odor','A chemical odor lingered in the corridor.'),('perfume','Her perfume smelled like citrus.'),('pungent','The onions released a pungent smell.'),('whiff','I caught a whiff of freshly brewed coffee.')], 'taste': [('sour','The lemon juice tasted sour.'),('bitter','The medicine left a bitter taste in my mouth.'),('sweet','The ripe peach tasted sweet.'),('salty','The soup was too salty for me.'),('tang','The yogurt had a sharp tang on my tongue.'),('savory','The broth tasted rich and savory.'),('aftertaste','The drink left a metallic aftertaste.'),('tart','The berries tasted tart.'),('flavor','I could taste the vanilla flavor in the custard.'),('sugary','The icing tasted sugary.')], 'touch': [('rough','The stone felt rough against my palm.'),('silky','The scarf felt silky when I ran my fingers over it.'),('scratchy','The wool felt scratchy against my neck.'),('sticky','The spilled syrup felt sticky on my fingers.'),('smooth','The polished handle felt smooth in my hand.'),('prickly','The cactus felt prickly against my skin.'),('cold','The metal rail felt cold under my fingers.'),('pressure','I felt pressure where the strap pressed against my shoulder.'),('soft','The blanket felt soft against my cheek.'),('tingle','The brush caused a tingle on the surface of my skin.')], 'interoception': [('hunger','I felt hunger as my empty stomach began to growl.'),('thirst','My thirst grew after hours without water.'),('nausea','A wave of nausea rose from my stomach.'),('heartbeat','I felt my heartbeat pounding inside my chest.'),('breathless','I felt breathless after climbing the stairs.'),('fullness','I noticed uncomfortable fullness in my stomach after dinner.'),('dizzy','I felt dizzy when I stood up too quickly.'),('cramp','A cramp tightened inside my abdomen.'),('queasy','My stomach felt queasy during the boat ride.'),('fatigue','I felt fatigue throughout my body after the long hike.')], } def digest(s): return hashlib.sha256(s.encode()).hexdigest() def normalized(s): return ' '.join(s.casefold().split()) def write_json(path,obj): path.write_text(json.dumps(obj,indent=2,ensure_ascii=False)+'\n',encoding='utf-8') def jsonl(path,rows): path.write_text(''.join(json.dumps(r,ensure_ascii=False)+'\n' for r in rows),encoding='utf-8') def grouped_split(rows, require_coverage=False): groups = sorted({r['group'] for r in rows}) a,b = int(len(groups)*.8),int(len(groups)*.9) rng=random.Random(SEED) group_support={} if require_coverage: for r in rows: counts=group_support.setdefault(r['group'],[0]*len(r['targets'])) for i,v in enumerate(r['targets']): counts[i]+=int(v>=.5) for attempt in range(10000): rng.shuffle(groups) if not require_coverage: break support=[[sum(group_support[g][i] for g in part) for i in range(len(rows[0]['targets']))] for part in [groups[a:b],groups[b:]]] if min(min(s) for s in support)>=3: break else: raise RuntimeError('Could not construct grouped split with label coverage') assignment = {g: 'train' if i=.5 for r in part) for i,n in enumerate(meta['labels'])} for s,part in splits.items()} if task=='open-sensations': meta['split_method']+='; deterministic rejection sampling until every label has at least 3 positives in validation and test, before any model training' meta['files_sha256']={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in folder.glob('*.jsonl')} write_json(folder/'data_manifest.json',meta) print(task,meta['sizes'],meta['positive_supports'],flush=True) if __name__=='__main__': main()