Repository navigation
Conversation
Currently verified equivalence up to preprocessing
…fication Lab top datasets and classification
…fication Lab top datasets and classification
…fication Add usage documentation
…fication Lab top datasets and classification
…fication Lab top datasets and classification
…fication Measure LabTOP numeric-token uncertainty against normalized prediction Error
Replace test_labtop.py and the old test_hirid.py with four test files built on one shared set of invented HiRID-shaped admissions: - tests/core/labtop_test_utils.py: three invented admissions, written as raw-stage HiRID files or built directly as Patients, a tiny offline tokenizer and the expected LabTOP serialization of patient 1. - test_labtop_task.py: preprocess, collation, test prompts. - test_labtop_model.py: forward pass, loss, gradients, generation, entropy. - test_labtop_evaluation.py: parsing, metrics vs LabTOP's formula, per-item report, sparse items, uncertainty, evaluate. - test_hirid.py: real HIRIDDataset loading, matched against the fixtures. All cases from the previous test_labtop.py are kept in the new files.
Consolidate LabTOP/HiRID tests around the four pipeline steps
…into LabTOP_Datasets_and_Classification
…fication Lab top datasets and classification Add mock and `.set_task(...)` usage
# Conflicts: # pyhealth/models/__init__.py # pyhealth/tasks/__init__.py
# Conflicts: # docs/api/datasets.rst
Test CoverageTotal: 88.24% (57714 / 65407 lines)
|
|
/review |
| print(f"{stage}: {completed}/{total} patients", flush=True) | ||
|
|
||
|
|
||
| def train(model, train_loader, valid_loader, epochs, device, accumulation_steps): |
There was a problem hiding this comment.
[medium] Training loop and patient reader have no tests
train() holds the model-selection logic the docs describe: gradient accumulation grouping, validation-loss tracking, early stopping after 10 epochs, and restoring best_state. iter_patient_batches() also has nontrivial logic, including frames.pop((patient_id,)), which raises KeyError if a patient has no events. None of this is tested; the tests cover only evaluate(). Add a small test with a tiny model and a synthetic loader that checks the restored weights come from the best validation epoch and that accumulation groups behave as described. Add one for iter_patient_batches on the synthetic HiRID root.
| .. code-block:: python | ||
|
|
||
| import torch | ||
| from examples.hirid_lab_value_prediction_labtop import evaluate, train |
There was a problem hiding this comment.
[low] API snippet imports train and evaluate from the examples package
The page presents from examples.hirid_lab_value_prediction_labtop import evaluate, train as the way to call the training and evaluation functions. That import only works from a repository checkout, not from an installed package. Say that explicitly, or point the reader to the example file.
| """ | ||
| prompts = [torch.tensor(row["prompt_tokens"] + row["lab_tokens"][:row["value_start"]]) | ||
| for row in rows] | ||
| previous = [torch.tensor(row["previous_value_tokens"], dtype=torch.long) for row in rows] |
There was a problem hiding this comment.
[low] Previous-value prompt fields are computed and never used
make_inference_dataset() builds previous_value_tokens and mean_previous_values for every prompt (lines 249-250). collate_labtop_prompts() returns them, but evaluate() discards them with prompts, labels, _, _ and LabTOP never reads them. Either remove the fields and their tests, or document what they are for.
| from .base_model import BaseModel | ||
|
|
||
|
|
||
| class LabTOP(BaseModel): |
There was a problem hiding this comment.
[low] LabTOP sits outside the BaseModel dataset contract
LabTOP calls super().init(dataset=None), and forward takes three tensors and returns loss and logits. It does not use feature_keys, label_keys, or the logit and y_prob outputs that BaseModel describes. It can only be trained by the example's own loop. Say so in the class docstring so users do not expect Trainer compatibility.
| We have tried to expedite the ablation study by conducting the ablation study | ||
| directly in LabTOP paper's repo. the reason behind this was to expedite the study | ||
| while the LabTOP integration to pyhealth was still in in progress. Unfortunately, | ||
| this too was inconclusive. We have found that the original work's code has an |
There was a problem hiding this comment.
[low] Unverifiable research narrative about upstream code
The README says the upstream LabTOP repository has an off-by-one error and that the ablation was inconclusive. These claims about third-party code cannot be checked from this PR, and they read as a project log rather than run instructions. Keep the how-to material and move the findings out of the library README, or cite a verifiable source.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It adds a HiRID raw-stage dataset loader, a LabTOP task and processor, a GPT-2 based LabTOP model, and a metrics module. It also adds an example script, docs, and synthetic fixtures with tests.
It looks ready to merge. The new classes subclass the existing base classes without changing them. The edits to the three init.py files only register the new components. Coverage meets the bar. The whole repository is at 88.24%, against the 60% minimum. Each added or modified file is above 80%: hirid.py 100%, metrics/labtop.py 98.6%, models/labtop.py 94.9%, and tasks/labtop.py 96.6%. The dataset docs cite PhysioNet and the LabTOP paper, and the docs match the code.
Optional suggestions:
- Tests for the example script: train() and iter_patient_batches() in the example script have no direct tests, and train() does the best-epoch restore and early stopping. A small test with a tiny model would guard that behavior.
- Python version: the example uses itertools.batched, which needs Python 3.12 or later. Please confirm this matches the project's supported versions.
- Unused prompt fields: previous_value_tokens and mean_previous_values are computed in make_inference_dataset but never used by the evaluation. Either document why they are kept or remove them.
- Docs import path: the model docs import train and evaluate from the examples package. This only works from the repository root, so you could say that in the docs.
- README narrative: the account of the off-by-one error in the upstream LabTOP code is hard for readers to verify. A shorter, factual note with a link to the upstream issue or commit would be clearer.
- PR description: it has a few broken sentences, such as the "latter metrics..." fragment. A quick edit would make it clearer.
Reviewed commit a3e0870
Contributor: Zhou, Sandy shuhan10@illinois.edu
Tran, Hunter Minh huntert3@illinois.edu
Alamidi, Badea alamidi2@illinois.edu
Contribution Type: New Dataset | New Task | New Model
Description: Added support for the HiRID dataset with pharma and admission
records. Includes the full LabTOP pipeline of ingesting data, preprocessing, model training, validation, testing, and error reporting.
latter metrics are reported alongside the ablation findings for the provided run: it correlates an uncertainty metric, per prediction, against the per-prediction mean absolute error. The intention is to test if there is a clear positive relationship
This implementation prioritizes a perfect simulation of filtering and preprocessing the input dataset, as that is the core feature of the paper. the training and evaluations that follow leverage an off-the-shelf HuggingFace GPT2 model and a pre-trained tokenzier for generation
Paper: https://proceedings.mlr.press/v287/im25a.html
Files to Review:
/datasets/hirid.py- Main dataset implementation/models/labtop.py- LabTOP model (GPT-2 wrapper a la paper impl)/tasks/labtop.py- preprocessing and inference task/metrics/labtop.py- postprocessor after evaluation. reports NMAE,SMAPE,MAE, Spearman correlation (ablation)/examples/hirid_lab_value_prediction_labtop.py- uses all of the above for the labtop pipelinetest_hirid.py, test_labtop_task.py, test_labtop_model.py, test_labtop_evaluation.py- Test cases (divided into the main components