Download scripts/common.py from Januka2009/INVESTIGA-ES: direct link, hf CLI and curl.
- Browser
- Download file 4.63 kB
-
https://huggingface.co/datasets/Januka2009/INVESTIGA-ES/resolve/main/scripts/common.py
- Command line
-
hf download hf://datasets/Januka2009/INVESTIGA-ES/scripts/common.py
-
curl -L -o common.py https://huggingface.co/datasets/Januka2009/INVESTIGA-ES/resolve/main/scripts/common.py
4.63 kB
| """Shared deterministic I/O; never writes to the upstream snapshot.""" | |
| import hashlib, json, re, unicodedata | |
| from pathlib import Path | |
| import pyarrow as pa | |
| import pyarrow.parquet as pq | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATE = '2026-10-29' | |
| BASELINE = '0cd1e4f55e73c83d11eed1935ec32252eb9dac71' | |
| DOMAINS = ['social_sciences','health','economics_business','stem','agriculture_rural_development','environment_sustainability','education','humanities'] | |
| DOMAIN_MAP = dict(zip(['sociales','salud','economia','stem','agro_desarrollo','ambiente_sostenibilidad','educacion','humanidades'], DOMAINS)) | |
| FAMILIES = ['research_question','question_framework','search_strategy','boolean_query','source_appraisal','evidence_selection','evidence_synthesis','grounded_qa','unsupported_claim','reference_verification','study_comparison','contradiction_detection','literature_review','conceptual_framework','methodological_design','quantitative_methods','qualitative_methods','mixed_methods','experimental_design','impact_evaluation','causal_inference','indicator_design','operationalization','sampling','statistical_interpretation','table_analysis','results_interpretation','methodological_critique','peer_review','limitations','ethics_reproducibility','research_plan','research_workflow','tool_use','search_select_synthesize','evidence_based_decision'] | |
| def norm(s): | |
| s = ''.join(c for c in unicodedata.normalize('NFKD',s.lower()) if not unicodedata.combining(c)) | |
| return ' '.join(re.findall(r'\w+', s)) | |
| def digest(s): return hashlib.sha256(s.encode() if isinstance(s,str) else s).hexdigest() | |
| def dump(path, obj): | |
| p = Path(path); p.parent.mkdir(parents=True,exist_ok=True) | |
| p.write_text(json.dumps(obj,ensure_ascii=False,indent=2,allow_nan=False)+'\n') | |
| def load(path): return json.loads(Path(path).read_text()) | |
| def write_rows(path, rows): | |
| p=Path(path);p.parent.mkdir(parents=True,exist_ok=True) | |
| pq.write_table(pa.Table.from_pylist(rows),p,compression='zstd',write_page_index=True) | |
| def read_rows(path): return pq.read_table(path).to_pylist() | |
| def all_data(): | |
| return [(p.parent.name,p.stem,r) for p in sorted((ROOT/'data').glob('*/*.parquet')) for r in read_rows(p)] | |
| def inputs(r,c): | |
| if c=='sft': return '\n'.join(m['content'] for m in r['messages'] if m['role']=='user') | |
| return r[{'rag':'query','agentic':'objective','benchmark':'prompt'}[c]] | |
| def outputs(r,c): | |
| if c=='sft':return '\n'.join(m['content'] for m in r['messages'] if m['role']=='assistant') | |
| return r.get('reference_answer',r.get('expected_artifact','')) | |
| def text(r,c): return inputs(r,c)+'\n'+outputs(r,c) | |
| def pii_flags(s): | |
| patterns={'email':r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b', | |
| 'secret':r'\b(?:hf_[A-Za-z0-9]{20,}|sk-[A-Za-z0-9_-]{20,}|AKIA[A-Z0-9]{16})\b', | |
| 'phone':r'(?<!\d)\+\d[\d ()-]{9,}\d\b'} | |
| return [k for k,p in patterns.items() if re.search(p,s)] | |
| def family(task): | |
| t=norm(task) | |
| if any(x in t for x in ['critique','correccion','diagnostico','evaluacion metodologica']):return 'methodological_critique' | |
| if 'manuscrito' in t:return 'peer_review' | |
| if any(x in t for x in ['ethic','etica','reproducibilidad']):return 'ethics_reproducibility' | |
| if any(x in t for x in ['problem','question','hipotesis']):return 'research_question' | |
| if any(x in t for x in ['evidence','evidencia','revision sistematica']):return 'evidence_synthesis' | |
| if any(x in t for x in ['mixed','mixto']):return 'mixed_methods' | |
| if any(x in t for x in ['qualitative','cualitativ','categorias','iconograf','corpus','redes culturales']):return 'qualitative_methods' | |
| if any(x in t for x in ['sampling','muestra','encuesta']):return 'sampling' | |
| if any(x in t for x in ['measurement','variables','instrumento']):return 'operationalization' | |
| if any(x in t for x in ['results','interpretacion']):return 'results_interpretation' | |
| if any(x in t for x in ['impacto','implementacion']):return 'impact_evaluation' | |
| if 'causal' in t:return 'causal_inference' | |
| if 'experimental' in t:return 'experimental_design' | |
| if any(x in t for x in ['diseno','design','decision']):return 'methodological_design' | |
| return 'quantitative_methods' | |
| def template_signatures(c,r): | |
| """Conservative observed structures, beyond self-declared family metadata.""" | |
| signatures=set();words=re.sub(r'\b\d+(?: \d+)*\b','#',norm(inputs(r,c))).split() | |
| if len(words)>=24:signatures.add('prompt_prefix12:'+' '.join(words[:12])) | |
| answer=outputs(r,c).splitlines()[0] | |
| if c=='sft' and answer.isupper() and len(norm(answer).split())<=12: | |
| signatures.add('uppercase_heading:'+norm(answer)) | |
| return signatures | |