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.0.tar.gz (15.3 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.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sympathyai-0.1.0.tar.gz
  • Upload date:
  • Size: 15.3 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.0.tar.gz
Algorithm Hash digest
SHA256 29681dd939ddc978359ea963fa6bdd2c087b9e48926fb7f34fb064d72c6bd65d
MD5 0834dfcb55a68e2ceb528e99544a09b8
BLAKE2b-256 d6501c4275fa6af57608e5cba579b7a4cd2809e0bdb4b5658b879241e95227c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sympathyai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0db9ba5bf093acd28bbf09910e9b2ac8ee357129fd04db1db2b0248b5a27d8bb
MD5 688ca4ee7208842c4ef379d86a163d81
BLAKE2b-256 473d32595c54e21715be7e834640e3f886f16f6644907eb708a30d76aae932ff

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