A MEDS PyTorch Dataset, leveraging a on-the-fly retrieval strategy for flexible, efficient data loading.
Project description
Clinical Zero-Shot Labeler
A tool for adapting ACES (Automated Cohort and Event Selection) task schemas to zero-shot labeling of clinical sequences.
Overview
The Clinical Zero-Shot Labeler extends ACES task schemas, originally designed for cohort extraction and binary classification tasks, to work with generative models. This allows you to:
- Use existing ACES task definitions for generative tasks
- Control sequence generation using ACES predicates and windows
- Extract labels from generated sequences using ACES criteria
By leveraging the ACES schema, you can define complex clinical tasks like:
- ICU mortality prediction
- Lab value forecasting
- Treatment response prediction
- Readmission risk assessment
All without needing to modify code or retrain models, and maintaining compatibility with existing ACES configurations.
About ACES
ACES (Automated Cohort and Event Selection) is a framework for defining clinical tasks through a structured YAML schema. Originally designed for:
- Cohort extraction from clinical data
- Binary classification task definition
- Temporal relationship specification
- Event sequence validation
This library extends ACES to work with generative models by:
- Converting ACES predicates into generation stopping criteria
- Using ACES windows to control sequence length and timing
- Applying ACES labeling logic to generated sequences
Installation
git clone git@github.com:Oufattole/clinical-zeroshot-labeler.git
cd clinical-zeroshot-labeler
pip install -e .[tests,dev]
Quick Start
- Define your task in a YAML file:
predicates:
icu_admission:
code: event_type//ICU_ADMISSION
death:
code: event_type//DEATH
discharge:
code: event_type//DISCHARGE
death_or_discharge:
expr: or(death, discharge)
trigger: icu_admission
windows:
observation:
start:
end: trigger + 24h
start_inclusive: true
end_inclusive: true
has:
_ANY_EVENT: (1, None)
index_timestamp: end
outcome:
start: observation.end
end: start -> death_or_discharge
start_inclusive: false
end_inclusive: true
has: {}
label: death
- Create task configuration:
from clinical_zeroshot_labeler import create_zero_shot_task
# Map token IDs to predicate codes
token_map = {
0: "event_type//ICU_ADMISSION",
1: "event_type//DEATH",
2: "event_type//DISCHARGE",
}
# Create task config
task_config = create_zero_shot_task(
yaml_path="icu_mortality.yaml", token_to_code_map=token_map
)
- Generate sequences and get labels:
# Generate sequences
outputs, lengths = generate_with_task(
model=model, prompts=prompts, task_config=task_config, temperature=0.7
)
# Get labels
labeler = task_config.get_task_labeler()
labels, unknown = labeler(trajectory_batch)
Task Configuration
ACES Tasks are defined through YAML files with two main components:
Predicates
Define events and conditions to match:
predicates:
# Simple event
icu_admission:
code: event_type//ICU_ADMISSION
# Event with numeric criteria
high_glucose:
code: GLUCOSE
value_min: 180
value_max:
# Composite predicate
any_critical:
expr: or(high_glucose, low_bp)
Windows
Define temporal relationships and constraints:
windows:
# Observation window
observation:
start: # Start of record
end: trigger + 24h
start_inclusive: true
end_inclusive: true
has:
_ANY_EVENT: (1, None)
# Prediction window
outcome:
start: observation.end
end: start -> death_or_discharge
start_inclusive: false
end_inclusive: true
has: {}
label: death
Generation Control
The configuration automatically handles:
- EOS tokens based on ACES task predicates in the prediction window
- Edge cases such as
end_inclusiveare also handled.
- Edge cases such as
- Time-based stopping based on the ACES task predicates and prediction window end time
- Sequence length limits, that are separately added by users. If a sequence length limit is imposed and generation does not complete by that sequence limit, an unknown label is returned.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clinical_zeroshot_labeler-0.0.1.tar.gz.
File metadata
- Download URL: clinical_zeroshot_labeler-0.0.1.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37e190c93602b09dbad7be6629df4f53644ee5f916644f1efabad2cc3fbb1046
|
|
| MD5 |
1b60c1ff57ec7b17a77f48be99516cc6
|
|
| BLAKE2b-256 |
1a50937f56db399ffc22153d7263c785faf71355db900b79976247a203a4ec30
|
Provenance
The following attestation bundles were made for clinical_zeroshot_labeler-0.0.1.tar.gz:
Publisher:
publish-to-pypi.yml on Oufattole/clinical-zeroshot-labeler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clinical_zeroshot_labeler-0.0.1.tar.gz -
Subject digest:
37e190c93602b09dbad7be6629df4f53644ee5f916644f1efabad2cc3fbb1046 - Sigstore transparency entry: 156462030
- Sigstore integration time:
-
Permalink:
Oufattole/clinical-zeroshot-labeler@1bdbdece4b69b155b77e03e081331f37a8331e5a -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/Oufattole
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@1bdbdece4b69b155b77e03e081331f37a8331e5a -
Trigger Event:
push
-
Statement type:
File details
Details for the file clinical_zeroshot_labeler-0.0.1-py3-none-any.whl.
File metadata
- Download URL: clinical_zeroshot_labeler-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81491e0183f9a4f54a158319cd92683e071f6585d90dd3e198e77456c0a5b24b
|
|
| MD5 |
9f5671d813a0d7ff174f8ed4c4cd4817
|
|
| BLAKE2b-256 |
fb02198f3568beb3096d4cf7215b89b6fbda05f2b6f1323190a0c9bd355d0211
|
Provenance
The following attestation bundles were made for clinical_zeroshot_labeler-0.0.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on Oufattole/clinical-zeroshot-labeler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clinical_zeroshot_labeler-0.0.1-py3-none-any.whl -
Subject digest:
81491e0183f9a4f54a158319cd92683e071f6585d90dd3e198e77456c0a5b24b - Sigstore transparency entry: 156462034
- Sigstore integration time:
-
Permalink:
Oufattole/clinical-zeroshot-labeler@1bdbdece4b69b155b77e03e081331f37a8331e5a -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/Oufattole
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@1bdbdece4b69b155b77e03e081331f37a8331e5a -
Trigger Event:
push
-
Statement type: