Skip to main content

Structure-aware evaluation and alignment for LLM reasoning

Project description

SympathyAI

Structure-aware evaluation and alignment for LLM reasoning

Python 3.9+ License: MIT No dependencies


Motivation

Large language models optimised via likelihood maximisation produce fluent text — but fluency is not reasoning.

In clinical settings, a response can be grammatically perfect, statistically plausible, and still:

  • contradict itself internally,
  • ignore established diagnostic guidelines (DSM-5, NICE, AHA),
  • fail to link symptoms causally to a diagnosis.

SympathyAI introduces a sympathetic evaluation framework: a lightweight, composable set of structure-aware metrics that go beyond perplexity to measure whether a model response actually reasons correctly.

Inspired by François Chollet's critique of gradient-based optimisation as a sufficient proxy for intelligence.


Three-Line Quick Start

from sympathy import evaluate, rerank

# Score a single response
score = evaluate("Symptoms suggest MDD; DSM-5 criteria are met.", keywords=["depression", "DSM"])

# Select the best response from a candidate list
best = rerank(responses, keywords=["myocardial infarction", "ECG", "troponin"])

What SympathyAI Measures

Metric What it captures Fast heuristic LLM-judge
Coherence Internal consistency; absence of contradictions ✅ ✅
Guideline adherence Coverage of required clinical concepts ✅ —
Causal alignment Symptom → diagnosis linkage ✅ —

All three are combined into a single sympathetic score:

sympathetic_score = 0.4 × coherence + 0.4 × guideline + 0.2 × causality

Weights are configurable.


Benchmark Results

Evaluated on 5 curated clinical vignettes (MDD, MI, Pneumonia, GAD, T2DM). Each case has a clinically correct response and a plausible-but-flawed response.

Case Condition Good ↑ Poor ↓ Δ Re-rank ✓
MDD_001 Major Depressive Disorder 0.92 0.28 +0.64 ✅
MI_001 Myocardial Infarction 0.80 0.36 +0.44 ✅
PNE_001 Community-Acquired Pneumonia 0.80 0.40 +0.40 ✅
GAD_001 Generalised Anxiety Disorder 0.89 0.28 +0.61 ✅
DM2_001 Type 2 Diabetes Mellitus 0.88 0.36 +0.52 ✅

Re-ranking accuracy: 5/5 (100%) · Average score delta: +0.52

Re-ranking consistently selects the clinically correct response without any additional model training.


Installation

git clone https://github.com/your-username/sympathyAI.git
cd sympathyAI
pip install -e .

No external dependencies required for the heuristic pipeline.

For LLM-as-judge coherence scoring:

pip install -e ".[llm]"

Project Structure

sympathyAI/
│
├── sympathy/
│   ├── scoring/
│   │   ├── coherence.py      # Heuristic + LLM-as-judge coherence
│   │   ├── causality.py      # Symptom-to-diagnosis causal alignment
│   │   └── guidelines.py     # Clinical keyword coverage
│   │
│   ├── rerank/
│   │   └── reranker.py       # Composite scoring + re-ranking
│   │
│   ├── datasets/
│   │   └── clinical_cases.py # 5 curated clinical vignettes
│   │
│   └── evaluation/
│       └── evaluator.py      # Benchmark runner + table printer
│
├── examples/
│   └── clinical_demo.py      # End-to-end demonstration
│
└── tests/
    └── test_sympathy.py      # Full unit test suite

Run the Demo

python examples/clinical_demo.py

Expected output:

Response : Symptoms are consistent with major depressive disorder...
  Coherence  : 1.00
  Guideline  : 0.75
  Causality  : 1.00
  â–¶ Total    : 0.90

Re-ranking accuracy: 5/5 (100%)
Average score delta (good − poor): +0.523

Run Tests

pytest tests/test_sympathy.py -v

Roadmap

  • LLM-as-judge coherence scoring (GPT-4 meta-evaluation)
  • Clinical grounding with DSM-5 and NICE guidelines knowledge base
  • Contradiction detection via NLI models
  • Prompt perturbation robustness analysis
  • REST API / Python wrapper for integration into inference pipelines
  • Extended benchmark (50+ clinical cases with expert annotation)

Citation

If you use SympathyAI in your research, please cite:

@misc{sympathyai2025,
  title  = {Beyond Likelihood: Evaluating Structure-Aware Reasoning in Clinical Language Models},
  author = {[Authors]},
  year   = {2025},
  note   = {https://github.com/your-username/sympathyAI}
}

License

MIT — free to use, extend, and publish with.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sympathyai-0.1.1.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sympathyai-0.1.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file sympathyai-0.1.1.tar.gz.

File metadata

  • Download URL: sympathyai-0.1.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for sympathyai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 33d3009b69372cc9b3ba507d0b64723810eede28e68d7b35a64d7e7bce4058d1
MD5 08e68e8f332470b9abaaae2f5f7f51c2
BLAKE2b-256 8e23668518e565ea8d5beefe823b42799d2a1b9c640779178f6ca9abeaec1973

See more details on using hashes here.

File details

Details for the file sympathyai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sympathyai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for sympathyai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 618124216ebef88653581d6a8e3945e39ceb1c3db1059cdd57d919e3de81bac1
MD5 e59c24c63a10557ca7b48a833e64d9e7
BLAKE2b-256 b8b53a66487af5f27a3a44085d68f7d5a60a8ed8188bac770251736c4cd5b734

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page