{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-academic-writing-semantic-consistency-auditor-36ae3060532f","title":"Semantic Consistency Auditor for Clinical Notes","summary":"Evaluate semantic consistency between AI-generated clinical notes and expert gold standards using BERTScore and COMET algorithms. The tool produces structured results with explicit assumptions, deliverables, and risks.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-academic-writing-semantic-consistency-auditor-36ae3060532f","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-academic-writing-semantic-consistency-auditor-36ae3060532f","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-academic-writing-semantic-consistency-auditor-36ae3060532f.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-academic-writing-semantic-consistency-auditor-36ae3060532f\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure Python 3.10+ is installed and dependencies are installed via `pip install -r requirements.txt` before running the script. Edit the in-file `CONFIG` block if the script uses fixed settings.","instructions":"---\nname: semantic-consistency-auditor\ndescription: Use semantic consistency auditor for academic writing workflows that need structured execution, explicit assumptions, and clear output boundaries.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# Skill: Semantic Consistency Auditor\n\n**ID:** 212  \n**Name:** semantic-consistency-auditor  \n**Description:** Introduces BERTScore and COMET algorithms to evaluate the semantic consistency between AI-generated clinical notes and expert gold standards from the \"semantic entailment\" level.\n\n## When to Use\n\n- Use this skill when the task needs Use semantic consistency auditor for academic writing workflows that need structured execution, explicit assumptions, and clear output boundaries.\n- Use this skill for academic writing tasks that require explicit assumptions, bounded scope, and a reproducible output format.\n- Use this skill when you need a documented fallback path for missing inputs, execution errors, or partial evidence.\n\n## Key Features\n\n- Scope-focused workflow aligned to: Use semantic consistency auditor for academic writing workflows that need structured execution, explicit assumptions, and clear output boundaries.\n- Packaged executable path(s): `scripts\/main.py`.\n- Reference material available in `references\/` for task-specific guidance.\n- Structured execution path designed to keep outputs consistent and reviewable.\n\n## Dependencies\n\nSee `## Prerequisites` above for related details.\n\n- `Python`: `3.10+`. Repository baseline for current packaged skills.\n- `bert_score`: `unspecified`. Declared in `requirements.txt`.\n- `comet`: `unspecified`. Declared in `requirements.txt`.\n- `dataclasses`: `unspecified`. Declared in `requirements.txt`.\n- `numpy`: `unspecified`. Declared in `requirements.txt`.\n- `torch`: `unspecified`. Declared in `requirements.txt`.\n- `yaml`: `unspecified`. Declared in `requirements.txt`.\n\n## Example Usage\n\nSee `## Usage` above for related details.\n\n```bash\ncd \"20260318\/scientific-skills\/Academic Writing\/semantic-consistency-auditor\"\npython -m py_compile scripts\/main.py\npython scripts\/main.py --help\n```\n\nExample run plan:\n1. Confirm the user input, output path, and any required config values.\n2. Edit the in-file `CONFIG` block or documented parameters if the script uses fixed settings.\n3. Run `python scripts\/main.py` with the validated inputs.\n4. Review the generated output and return the final artifact with any assumptions called out.\n\n## Implementation Details\n\nSee `## Workflow` above for related details.\n\n- Execution model: validate the request, choose the packaged workflow, and produce a bounded deliverable.\n- Input controls: confirm the source files, scope limits, output format, and acceptance criteria before running any script.\n- Primary implementation surface: `scripts\/main.py`.\n- Reference guidance: `references\/` contains supporting rules, prompts, or checklists.\n- Parameters to clarify first: input path, output path, scope filters, thresholds, and any domain-specific constraints.\n- Output discipline: keep results reproducible, identify assumptions explicitly, and avoid undocumented side effects.\n\n## Quick Check\n\nUse this command to verify that the packaged script entry point can be parsed before deeper execution.\n\n```bash\npython -m py_compile scripts\/main.py\n```\n\n## Audit-Ready Commands\n\nUse these concrete commands for validation. They are intentionally self-contained and avoid placeholder paths.\n\n```bash\npython -m py_compile scripts\/main.py\npython scripts\/main.py --help\n```\n\n## Workflow\n\n1. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.\n2. Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.\n3. Use the packaged script path or the documented reasoning path with only the inputs that are actually available.\n4. Return a structured result that separates assumptions, deliverables, risks, and unresolved items.\n5. If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.\n\n## Overview\n\nSemantic Consistency Auditor is a medical AI evaluation tool used to assess the semantic consistency between AI-generated clinical notes and expert-written gold standards from a semantic level. This tool is not limited to traditional string matching or bag-of-words models, but uses deep learning models to understand semantic entailment relationships, capable of identifying expressions with different wording but similar meaning.\n\n## Algorithms\n\n### 1. BERTScore\nBERTScore uses pre-trained BERT model contextual embeddings to calculate similarity between candidate text and reference text:\n- **Precision**: How much semantics in the candidate text is covered by the reference text\n- **Recall**: How much semantics in the reference text is covered by the candidate text\n- **F1 Score**: Harmonic mean of Precision and Recall\n\n### 2. COMET (Cross-lingual Optimized Metric for Evaluation of Translation)\nCOMET is a neural network-based evaluation metric originally used for machine translation evaluation, applicable to semantic entailment tasks:\n- Uses XLM-RoBERTa encoder to capture deep semantics\n- Outputs semantic consistency scores between 0-1\n- Gives high scores to semantically equivalent but differently expressed text\n\n## Installation\n\n```text\n\n# Create virtual environment (recommended)\npython -m venv venv\nsource venv\/bin\/activate  # Linux\/Mac\n\n# Or venv\\Scripts\\activate  # Windows\n\n# Install dependencies\npip install bertscore comet-ml transformers torch\n```\n\n## Configuration\n\nConfigure in `~\/.openclaw\/skills\/semantic-consistency-auditor\/config.yaml`:\n\n```yaml\n\n# BERTScore Configuration\nbertscore:\n  model: \"microsoft\/deberta-xlarge-mnli\"  # Or \"bert-base-chinese\" for Chinese\n  lang: \"zh\"  # Language code: zh, en, etc.\n  rescale_with_baseline: true\n  device: \"auto\"  # auto, cpu, cuda\n\n# COMET Configuration\ncomet:\n  model: \"Unbabel\/wmt22-comet-da\"  # COMET model\n  batch_size: 8\n  device: \"auto\"\n\n# Evaluation Thresholds\nthresholds:\n  bertscore_f1: 0.85\n  comet_score: 0.75\n  semantic_consistency: 0.80  # Comprehensive score threshold\n```\n\n## Usage\n\n### Command Line\n\n```text\n\n# Evaluate single case pair\npython scripts\/main.py \\\n  --ai-generated \"Patient presented with fever for 3 days, highest temperature 39\u00b0C, accompanied by cough.\" \\\n  --gold-standard \"Patient chief complaint of fever for 3 days, highest temperature 39\u00b0C, accompanied by cough symptoms.\" \\\n  --output results.json\n\n# Batch evaluation from JSON file\npython scripts\/main.py \\\n  --input-file batch_cases.json \\\n  --output results.json \\\n  --format detailed\n\n# Use specific model\npython scripts\/main.py \\\n  --ai-generated \"...\" \\\n  --gold-standard \"...\" \\\n  --bert-model \"bert-base-chinese\" \\\n  --comet-model \"Unbabel\/wmt20-comet-da\"\n```\n\n### Python API\n\n```python\nfrom semantic_consistency_auditor import SemanticConsistencyAuditor\n\n# Initialize evaluator\nauditor = SemanticConsistencyAuditor(\n    bert_model=\"microsoft\/deberta-xlarge-mnli\",\n    comet_model=\"Unbabel\/wmt22-comet-da\",\n    lang=\"zh\"\n)\n\n# Evaluate single case\nresult = auditor.evaluate(\n    ai_text=\"Patient presented with fever for 3 days...\",\n    gold_text=\"Patient chief complaint of fever for 3 days...\"\n)\n\nprint(f\"BERTScore F1: {result['bertscore']['f1']:.4f}\")\nprint(f\"COMET Score: {result['comet']['score']:.4f}\")\nprint(f\"Consistency: {result['consistency']:.4f}\")\nprint(f\"Passed: {result['passed']}\")\n\n# Batch evaluation\nresults = auditor.evaluate_batch([\n    {\"ai\": \"...\", \"gold\": \"...\"},\n    {\"ai\": \"...\", \"gold\": \"...\"}\n])\n```\n\n## Input Format\n\n### Single Case (Command Line)\n\nPass text directly through `--ai-generated` and `--gold-standard` parameters.\n\n### Batch Evaluation File (JSON)\n\n```json\n[\n  {\n    \"case_id\": \"CASE001\",\n    \"ai_generated\": \"Patient presented with fever for 3 days, highest temperature 39\u00b0C, accompanied by cough.\",\n    \"gold_standard\": \"Patient chief complaint of fever for 3 days, highest temperature 39\u00b0C, accompanied by cough symptoms.\",\n    \"metadata\": {\n      \"department\": \"Respiratory\",\n      \"disease_type\": \"Upper respiratory infection\"\n    }\n  },\n  {\n    \"case_id\": \"CASE002\",\n    \"ai_generated\": \"...\",\n    \"gold_standard\": \"...\"\n  }\n]\n```\n\n## Output Format\n\n### Summary Mode\n\n```json\n{\n  \"overall\": {\n    \"total_cases\": 100,\n    \"passed_cases\": 85,\n    \"pass_rate\": 0.85,\n    \"avg_bertscore_f1\": 0.8923,\n    \"avg_comet_score\": 0.8234,\n    \"avg_consistency\": 0.8579\n  },\n  \"thresholds\": {\n    \"bertscore_f1\": 0.85,\n    \"comet_score\": 0.75,\n    \"semantic_consistency\": 0.80\n  }\n}\n```\n\n### Detailed Mode\n\n```json\n{\n  \"cases\": [\n    {\n      \"case_id\": \"CASE001\",\n      \"ai_generated\": \"Patient presented with fever for 3 days...\",\n      \"gold_standard\": \"Patient chief complaint of fever for 3 days...\",\n      \"metrics\": {\n        \"bertscore\": {\n          \"precision\": 0.9123,\n          \"recall\": 0.8934,\n          \"f1\": 0.9028\n        },\n        \"comet\": {\n          \"score\": 0.8234,\n          \"system_score\": 0.8156\n        },\n        \"semantic_consistency\": 0.8631\n      },\n      \"passed\": true,\n      \"details\": {\n        \"semantic_gaps\": [],\n        \"matched_concepts\": [\"fever for 3 days\", \"temperature 39\u00b0C\", \"cough\"]\n      }\n    }\n  ],\n  \"summary\": { ... }\n}\n```\n\n## Error Handling\n\n- If required inputs are missing, state exactly which fields are missing and request only the minimum additional information.\n- If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.\n- If `scripts\/main.py` fails, report the failure point, summarize what still can be completed safely, and provide a manual fallback.\n- Do not fabricate files, citations, data, search results, or execution outcomes.\n\n## Performance Notes\n\n- **BERTScore**: First run will download model (approximately 400MB-1GB)\n- **COMET**: First run will download model (approximately 500MB-1.5GB)\n- **GPU Acceleration**: Significantly improves evaluation speed in CUDA environment\n- **Batch Processing**: Recommended for batch evaluation to fully utilize GPU parallel capability\n\n## References\n\n1. Zhang et al. \"BERTScore: Evaluating Text Generation with BERT\" ICLR 2020\n2. Rei et al. \"COMET: A Neural Framework for MT Evaluation\" EMNLP 2020\n3. Medical Record Standardization Evaluation Guidelines (National Health Commission)\n\n## Changelog\n\n- **v1.0.0** (2026-02-06): Initial version, supports dual-algorithm evaluation with BERTScore and COMET\n\n## Prerequisites\n\n```text\n\n# Python dependencies\npip install -r requirements.txt\n```\n\n## Evaluation Criteria\n\n### Success Metrics\n- [ ] Successfully executes main functionality\n- [ ] Output meets quality standards\n- [ ] Handles edge cases gracefully\n- [ ] Performance is acceptable\n\n### Test Cases\n1. **Basic Functionality**: Standard input \u2192 Expected output\n2. **Edge Case**: Invalid input \u2192 Graceful error handling\n3. **Performance**: Large dataset \u2192 Acceptable processing time\n\n## Output Requirements\n\nEvery final response should make these items explicit when they are relevant:\n\n- Objective or requested deliverable\n- Inputs used and assumptions introduced\n- Workflow or decision path\n- Core result, recommendation, or artifact\n- Constraints, risks, caveats, or validation needs\n- Unresolved items and next-step checks\n\n## Input Validation\n\nThis skill accepts requests that match the documented purpose of `semantic-consistency-auditor` and include enough context to complete the workflow safely.\n\nDo not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:\n\n> `semantic-consistency-auditor` only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.\n\n## References\n\n- [references\/audit-reference.md](references\/audit-reference.md) - Supported scope, audit commands, and fallback boundaries\n\n## Response Template\n\nUse the following fixed structure for non-trivial requests:\n\n1. Objective\n2. Inputs Received\n3. Assumptions\n4. Workflow\n5. Deliverable\n6. Risks and Limits\n7. Next Checks\n\nIf the request is simple, you may compress the structure, but still keep assumptions and limits explicit when they affect correctness.\n","use_cases":["Assessing the semantic accuracy of AI-generated clinical notes against expert-written gold standards.","Validating the consistency of AI outputs in medical research workflows."],"limitations":[],"compatibility":[],"setup_tip":"```text\n\n# Create virtual environment (recommended)\npython -m venv venv\nsource venv\/bin\/activate  # Linux\/Mac\n\n# Or venv\\Scripts\\activate  # Windows\n\n# Install dependencies\npip install bertscore comet-ml transformers torch\n```","sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/scientific-skills\/Academic%20Writing\/semantic-consistency-auditor\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T10:44:53.000000Z","updated_at":"2026-11-24T07:14:40.000000Z","seo_title":"Semantic Consistency Auditor for Clinical Notes","seo_description":"Evaluate semantic consistency between AI-generated clinical notes and expert gold standards using BERTScore and COMET algorithms.","seo_keywords":["clinical note evaluation","AI-generated note validation","semantic consistency check","BERTScore for medical notes","COMET for clinical analysis"]}}