Skip to main content

MEDS Random Task Sampler

Python 3.11+ License: MIT

Model-independent generation of query-based task rows from MEDS datasets.

The package provides two separate workflows:

  • random_sample: random (code, duration) specifications paired with random patient contexts; and
  • dense_grid: explicit code x duration grids at sampled patient prediction times.

These names describe how rows are sampled, not how a downstream model must use them. For example, either output could be used for training, validation, benchmarking, probing, or analysis.

Both workflows follow payalchandak/EveryQuery@9bd85a1. The package owns the shared task schema, code-source resolution, future-occurrence labeling, death and censoring semantics, deterministic seeds, and atomic output writes. It does not depend on Hydra or a model framework.

Random task samples

from meds_random_task_sampler import RandomTaskSamplerConfig, sample_random_tasks

config = RandomTaskSamplerConfig(
    num_queries=1024,
    num_contexts_per_query=1,
    min_prediction_times_per_subject=50,
    query_codes="/path/to/MEDS",  # resolves metadata/codes.parquet
    min_duration=1,
    max_duration=731,
    duration_distribution="log-uniform",
)

result = sample_random_tasks(
    data_dir="/path/to/MEDS",
    output_dir="/path/to/random_tasks",
    split="train",
    config=config,
)

Output is partitioned under random_tasks/{split}/*.parquet; restartable intermediate artifacts use the sibling random_tasks_artifacts/{split}/ directory. Machine-readable summary statistics are written to random_tasks_artifacts/{split}/_summary.json.

Dense task grids

from meds_random_task_sampler import (
    TaskGridGeneratorConfig,
    generate_task_grid,
)

config = TaskGridGeneratorConfig(
    prediction_times_per_subject=1,
    min_context_per_subject=50,
    query_codes=["CODE_A", "CODE_B"],
    durations=[30, 90, 180, 365, 731],
    write_unique_prediction_times=True,
    censored_rows="keep",  # or "drop" for current EveryQuery evaluation behavior
)

result = generate_task_grid(
    data_dir="/path/to/MEDS",
    output_dir="/path/to/task_grid",
    split="held_out",
    input_shard="0",
    config=config,
)

Grid rows are written to task_grid/{split}/{shard}.parquet. Optional unique prediction times use the sibling task_grid_unique/ root and per-shard summaries use task_grid_summary/. Nullable/censored labels are retained by default; use censored_rows="drop" to reproduce current EveryQuery evaluation output.

See DESIGN.md for the behavioral contract and planned EveryQuery adapter boundary.

Development

uv sync --group dev
uv run pytest -v
uv run pre-commit run --all-files

This repository retains the McDermottHealthAI/MHAL-template project structure.

Download files

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

Source Distribution

meds_random_task_sampler-0.1.0.tar.gz (132.7 kB view details)

Uploaded Source

Built Distribution

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

meds_random_task_sampler-0.1.0-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meds_random_task_sampler-0.1.0.tar.gz
  • Upload date:
  • Size: 132.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for meds_random_task_sampler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 598e269d8a201879c11db185fb4ec3cb9f922b4f4faa02dd4e7ce139533c7865
MD5 ea33bb0dc4e50dc85cdde103663ebd5c
BLAKE2b-256 b18df05de0843d180a575c6c6a6015ae5043bbc0e270da0e71d6530d638a5148

See more details on using hashes here.

Provenance

The following attestation bundles were made for meds_random_task_sampler-0.1.0.tar.gz:

Publisher: python-build.yaml on florian6973/meds-random-task-sampler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for meds_random_task_sampler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1d64d519ca30a5bd383f2dbefe7551289b496470256801a8f430179b992e699
MD5 156672207e37183506cca41d32b40cce
BLAKE2b-256 5ada1b28bd1b375d46354733fe8a70272807e05b46391ce7da898dcb9f989676

See more details on using hashes here.

Provenance

The following attestation bundles were made for meds_random_task_sampler-0.1.0-py3-none-any.whl:

Publisher: python-build.yaml on florian6973/meds-random-task-sampler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

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