Download code/audit_question_standalone_flags.py from dfdu233/MeningiomaBench: direct link, hf CLI and curl.
- Browser
- Download file 3.82 kB
-
https://huggingface.co/datasets/dfdu233/MeningiomaBench/resolve/main/code/audit_question_standalone_flags.py
- Command line
-
hf download hf://datasets/dfdu233/MeningiomaBench/code/audit_question_standalone_flags.py
-
curl -L -o audit_question_standalone_flags.py https://huggingface.co/datasets/dfdu233/MeningiomaBench/resolve/main/code/audit_question_standalone_flags.py
3.82 kB
| """Screen question-only study references; flags are not ambiguity or gold labels.""" | |
| from collections import Counter, defaultdict | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import re | |
| FILES = ('development.jsonl', 'sealed_test.jsonl', 'miriad_source_qa_development.jsonl', | |
| 'miriad_source_qa_sealed_test.jsonl', 'miriad_source_qa_legacy_exploratory.jsonl') | |
| PATTERNS = { | |
| 'explicit_cross_item_reference': r'\b(?:same study|same cohort|aforementioned study|previously mentioned study|above[- ]mentioned study|previous question)\b', | |
| 'study_deictic_reference': r'\b(?:this study|the study|present study|current study|this series|the series|this case report|the discussion|this cohort|the cohort)\b', | |
| } | |
| def main(): | |
| root = Path(__file__).resolve().parent.parent | |
| groups = defaultdict(Counter); cases = []; seen = set(); hashes = {} | |
| for name in FILES: | |
| path = root / 'data' / name; hashes[name] = hashlib.sha256(path.read_bytes()).hexdigest() | |
| track = 'public_source_openqa' if name.startswith('miriad_') else 'known_study_contrast' | |
| for row in map(json.loads, path.open()): | |
| assert row['id'] not in seen; seen.add(row['id']) | |
| question = row['question']; title = row.get('article_title') or row.get('paper_title') or '' | |
| flags = [key for key, pattern in PATTERNS.items() if re.search(pattern, question, re.I)] | |
| title_match = len(title) >= 15 and ' '.join(title.lower().split()) in ' '.join(question.lower().split()) | |
| # A topic-like title substring does not identify an article. | |
| explicit_identity = bool(row.get('study_identifier_visible_to_all_readers')) and title_match | |
| group = groups[track + ':' + row['split']] | |
| group.update(questions=1, literal_title_text_match=int(title_match), | |
| declared_study_identifier_confirmed_in_question=int(explicit_identity), deictic_flag=int(bool(flags)), | |
| flagged_without_explicit_study_identifier=int(bool(flags) and not explicit_identity), | |
| cross_item_flag_without_explicit_study_identifier=int('explicit_cross_item_reference' in flags and not explicit_identity)) | |
| if flags:cases.append({'id': row['id'], 'track': track, 'split': row['split'], 'flags': flags, | |
| 'literal_article_title_text_in_question': title_match, | |
| 'declared_study_identifier_confirmed_in_question': explicit_identity, 'ambiguity_adjudicated': False}) | |
| assert len(seen) == 1857 | |
| report = {'scope': 'Question-only deterministic presupposition/reference screen over existing1857silver questions. Historical test questions were already exposed; this is not a new untouched-test audit.', | |
| 'input_sha256': hashes, 'patterns': PATTERNS, 'distinct_questions': len(seen), 'groups': groups, | |
| 'flagged_cases': cases, 'limits': 'A study reference can be resolved by conditions or other context; a flag is not proof of ambiguity. Short topic-like article titles can occur as ordinary clinical phrases, so literal title matches alone do not establish study identity or a retrieval shortcut. Explicit study identity is confirmed only for the declared known-study task here. No unflagged-item quality or clinical-answer validity claim. No filtering, rewriting, split changes or reader reruns.', | |
| 'expert_ambiguity_reviews': 0, 'new_model_or_network_calls': 0, 'new_confirmation_questions_read': 0} | |
| path = root / 'results/reproduction/question_standalone_reference_flags1857.json' | |
| text = json.dumps(report, indent=2) + '\n' | |
| assert not path.exists() or path.read_text() == text | |
| path.write_text(text) | |
| print(json.dumps({'questions': len(seen), 'groups': groups, 'flagged_cases': len(cases), 'adjudicated_ambiguity_labels': 0})) | |
| if __name__ == '__main__':main() | |