cotorra 26.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael C. Burkhart, et al.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,579 @@
1
+ Metadata-Version: 2.4
2
+ Name: cotorra
3
+ Version: 26.6.0
4
+ Summary: configurable trainer for generative event models
5
+ Author-email: "Michael C. Burkhart" <burkh4rt@uchicago.edu>, Luke Solo <lsolo@uchicago.edu>, Inhyeok Lee <ihlee@uchicago.edu>, S'Khaja Charles <skhaja@uchicago.edu>, "Brett K. Beaulieu-Jones" <beaulieujones@uchicago.edu>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/bbj-lab/cotorra
8
+ Keywords: model training,generative event models,configurable training
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Natural Language :: English
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE.md
16
+ Requires-Dist: accelerate
17
+ Requires-Dist: datasets
18
+ Requires-Dist: huggingface-hub
19
+ Requires-Dist: lightgbm
20
+ Requires-Dist: numpy
21
+ Requires-Dist: omegaconf
22
+ Requires-Dist: opacus
23
+ Requires-Dist: optuna
24
+ Requires-Dist: polars
25
+ Requires-Dist: rich
26
+ Requires-Dist: scikit-learn
27
+ Requires-Dist: torch
28
+ Requires-Dist: torchaudio
29
+ Requires-Dist: torchvision
30
+ Requires-Dist: tqdm
31
+ Requires-Dist: transformers
32
+ Requires-Dist: typer
33
+ Requires-Dist: xgboost
34
+ Requires-Dist: wandb
35
+ Provides-Extra: all
36
+ Requires-Dist: cotorra[dev,gen]; extra == "all"
37
+ Provides-Extra: dev
38
+ Requires-Dist: pip; extra == "dev"
39
+ Requires-Dist: ruff; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ <p align="center">
43
+ <img src="https://raw.githubusercontent.com/burkh4rt/cotorra/master/img/cotorra.png" width="400" style="display: block;
44
+ margin: 0 auto; -webkit-mask-image: radial-gradient(
45
+ ellipse at center,
46
+ rgba(0,0,0,1) 50%,
47
+ rgba(0,0,0,0) 100%
48
+ );
49
+ mask-image: radial-gradient(
50
+ ellipse at center,
51
+ rgba(0,0,0,1) 50%,
52
+ rgba(0,0,0,0) 100%
53
+ );"/>
54
+ </p>
55
+
56
+ # Cotorra: a configurable trainer
57
+
58
+ [![DOI](https://raw.githubusercontent.com/burkh4rt/cotorra/master/img/1193885071.svg)](https://doi.org/10.5281/zenodo.20414127)
59
+ [![SWH](https://archive.softwareheritage.org/badge/origin/https://github.com/bbj-lab/cotorra/)](https://archive.softwareheritage.org/browse/origin/?origin_url=https://github.com/bbj-lab/cotorra)
60
+
61
+ > ๐Ÿฆœ the wild parakeet of Chicago's south side
62
+
63
+ ## About
64
+
65
+ This repo provides a configurable trainer for generative event models on
66
+ tokenized timelines. _Cotorra_ is a Spanish term for a small-to-medium sized
67
+ parrot, particularly the Monk parakeet. Monk parakeets were introduced to the
68
+ south side of Chicago, where they have flourished. [^1] It benefits from previous
69
+ experience training foundation models on tokenized electronic health records.
70
+ [^2] [^3] [^4] [^5]
71
+
72
+ ## Installation
73
+
74
+ You can download and install this package as follows:
75
+
76
+ ```sh
77
+ git clone git@github.com:bbj-lab/cotorra.git
78
+ cd cotorra
79
+ python -m venv .venv
80
+ . .venv/bin/activate
81
+ pip install -e ".[gen]" \
82
+ --index-url https://download.pytorch.org/whl/cu128 \
83
+ --extra-index-url https://pypi.org/simple
84
+ ```
85
+
86
+ ## Context
87
+
88
+ Suppose you have a dataset of tokenized timelines `tokens_times.parquet` as a
89
+ parquet table with columns:
90
+
91
+ - `subject_id`
92
+ - `tokens` โ€” the integer token sequence for the subject's timeline.
93
+ - `times` โ€” a parallel list of timestamps, one per token, indicating when each
94
+ event occurred.
95
+
96
+ The table will look something like this:
97
+
98
+ ```
99
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
100
+ โ”‚ subject_id โ”† tokens โ”† times โ”‚
101
+ โ”‚ --- โ”† --- โ”† --- โ”‚
102
+ โ”‚ str โ”† list[u32] โ”† list[datetime[ฮผs]] โ”‚
103
+ โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ก
104
+ โ”‚ 20002103 โ”† [20, 350, โ€ฆ 21] โ”† [2116-05-08 02:45:00, 2116-05-โ€ฆ โ”‚
105
+ โ”‚ 20008372 โ”† [20, 350, โ€ฆ 21] โ”† [2110-10-30 13:03:00, 2110-10-โ€ฆ โ”‚
106
+ โ”‚ โ€ฆ โ”† โ€ฆ โ”† โ€ฆ โ”‚
107
+ โ”‚ 29994865 โ”† [20, 364, โ€ฆ 21] โ”† [2111-01-28 21:49:00, 2111-01-โ€ฆ โ”‚
108
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
109
+ ```
110
+
111
+ You also have a `tokenizer.yaml`, a plain yaml file that contains information
112
+ about the configuration, learned vocabulary, and bins. This file is sufficient to
113
+ reconstitute the tokenizer object. We only need this file to contain a lookup
114
+ table:
115
+
116
+ ```yaml
117
+ lookup:
118
+ UNK: 0
119
+ ADMN//direct: 1
120
+ ADMN//ed: 2
121
+ ADMN//elective: 3
122
+ AGE//age_Q0: 4
123
+ ...
124
+ ```
125
+
126
+ Finally, we need `subject_splits.parquet` which is a table listing out all
127
+ subject_id's and their corresponding split assignment (with splits: `train`,
128
+ `tuning`, and `held_out`). This table may include additional demographic
129
+ information provided as pass-through-columns to
130
+ [cocoa](https://github.com/bbj-lab/cocoa).
131
+
132
+ ```
133
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
134
+ โ”‚ subject_id โ”† split โ”‚
135
+ โ”‚ --- โ”† --- โ”‚
136
+ โ”‚ str โ”† str โ”‚
137
+ โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ก
138
+ โ”‚ 21081215 โ”† train โ”‚
139
+ โ”‚ 20302177 โ”† train โ”‚
140
+ โ”‚ โ€ฆ โ”† โ€ฆ โ”‚
141
+ โ”‚ 28150003 โ”† held_out โ”‚
142
+ โ”‚ 22151813 โ”† held_out โ”‚
143
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
144
+ ```
145
+
146
+ For extraction and scoring workflows, we also need split-specific inference
147
+ tables in the same `processed_data_home` directory:
148
+
149
+ - `train_for_inference.parquet`
150
+ - `tuning_for_inference.parquet`
151
+ - `held_out_for_inference.parquet`
152
+
153
+ These tables are expected to include at least:
154
+
155
+ - `tokens_past` (the model context used for extraction/scoring)
156
+ - `s_elapsed_past` (if using `time_based_rope`)
157
+ - token-specific label columns such as `<TOKEN>_past` and `<TOKEN>_future` used
158
+ by generative and representation-based scoring.
159
+
160
+ The `cocoa winnow` command provides these.
161
+
162
+ <!-- prettier-ignore-start -->
163
+ > [!TIP]
164
+ > For getting your data to this point, check out our configurable
165
+ > collator / tokenizer: [โ˜•๏ธ cocoa](https://github.com/bbj-lab/cocoa)
166
+ <!-- prettier-ignore-end -->
167
+
168
+ Given these things, we want to train a model to predict the next token in a
169
+ subject's timeline given their complete history or context up to this point. This
170
+ package is designed to do that in a configurable way.
171
+
172
+ ## Configuration
173
+
174
+ This library can be extensively customized through yaml configuration files. Each
175
+ command has its own default config under `src/cotorra/config/`, which you can
176
+ override by passing a config file via the appropriate CLI flag. Any value can
177
+ also be overridden programmatically via `**kwargs` which are merged on top of the
178
+ YAML config via OmegaConf.
179
+
180
+ ### Training configuration ([example](src/cotorra/config/training.yaml))
181
+
182
+ Used by `cotorra train` and `cotorra tune`.
183
+
184
+ - **model**:
185
+ - **model_name**: Name or path of the HuggingFace model (e.g.,
186
+ `meta-llama/Llama-3.2-1B`).
187
+ - **model_args**: Model architecture parameters passed directly to
188
+ HuggingFace's
189
+ [`AutoConfig`](https://huggingface.co/docs/transformers/en/model_doc/auto).
190
+
191
+ _Note: The bundled config defines reusable model presets under
192
+ `model_presets`._
193
+
194
+ - **max_seq_len**: Maximum sequence length for model input.
195
+ - **n_epochs**: Number of epochs (handled in the dataloader, not the trainer).
196
+ - **run_name**: Name for the current run (referenced by `wandb` and
197
+ `training_args`).
198
+ - **tokens_of_interest**: List of special tokens to upweight during training
199
+ (referenced by loss config). Supports patterns specified with fnmatch.
200
+ - **wandb**:
201
+ - **project**: Weights & Biases project name for experiment tracking.
202
+ - **run_name**: Name for the current run.
203
+ - **custom_loss**: Boolean flag to enable custom loss functions (default:
204
+ `false`).
205
+ - **quantile_token_loss** _(optional)_: Upweights loss on quantile boundary
206
+ tokens.
207
+ - **qt_weight**: Weight multiplier for quantile tokens.
208
+ - **label_weighted_loss** _(optional)_: Upweights loss on specific tokens of
209
+ clinical interest.
210
+ - **tokens_of_interest**: List of token labels to upweight. Supports patterns
211
+ specified with fnmatch.
212
+ - **toi_weight**: Weight multiplier applied to those tokens.
213
+ - **time_based_rope** _(optional)_: Enables time-aware rotary position
214
+ embeddings.
215
+ - **sec_per_pos_id**: Number of seconds represented by one position id
216
+ increment.
217
+ - **training_args**: Arguments passed to HuggingFace's
218
+ [`TrainingArguments`](https://huggingface.co/docs/transformers/en/main_classes/trainer#transformers.TrainingArguments).
219
+ - **tuning_args**: Arguments passed to HuggingFace's
220
+ [`hyperparameter_search`](https://huggingface.co/docs/transformers/hpo_train?backends=Optuna)
221
+ when `cotorra tune` is called.
222
+
223
+ #### Model presets
224
+
225
+ We offer the following presents
226
+
227
+ | designator | base model | # params w/ ~1340-token vocab |
228
+ | -------------- | ------------------------- | ----------------------------- |
229
+ | `llama_32` | `meta-llama/Llama-3.2-1B` | ~76.9M |
230
+ | `llama_32_mid` | `meta-llama/Llama-3.2-1B` | ~8.2M |
231
+ | `qwen_3` | `Qwen/Qwen3-1.7B-Base` | ~74.1M |
232
+ | `qwen_3_mid` | `Qwen/Qwen3-1.7B-Base` | ~8.4M |
233
+ | `gemma_3` | `google/gemma-3-1b-pt` | ~75.7M |
234
+ | `gemma_3_mid` | `google/gemma-3-1b-pt` | ~7.8M |
235
+
236
+ Use the `model` key to select one of these presets and then override any
237
+ individual `model_args` entries as needed.
238
+
239
+ <!-- prettier-ignore-start -->
240
+ > [!TIP]
241
+ > Training supports the `--resume-from-checkpoint` (`-r`) flag. When set,
242
+ > `cotorra train` will attempt to resume from the latest HuggingFace checkpoint
243
+ > saved under `--output-home`. If no checkpoint is found (or resumption fails),
244
+ > it automatically falls back to training from scratch โ€” so the flag is safe to
245
+ > pass unconditionally in scripts. Use `save_steps` in `training_args` in the
246
+ > [training.yaml](src/cotorra/config/training.yaml) file to control the frequency
247
+ > of checkpointing.
248
+ <!-- prettier-ignore-end -->
249
+
250
+ #### Differential privacy
251
+
252
+ We wrap [opacus](https://opacus.ai) to support training with differential privacy
253
+ (see `train-private` below). The following relevant parameters can be modified in
254
+ the configuration:
255
+
256
+ ```
257
+ privacy_parameters:
258
+ noise_multiplier: !!float 1.0
259
+ max_grad_norm: !!float 1.0
260
+ ```
261
+
262
+ ### Extraction configuration ([example](src/cotorra/config/extraction.yaml))
263
+
264
+ Used by `cotorra extract`.
265
+
266
+ - **max_seq_len**: Maximum sequence length.
267
+ - **time_based_rope** _(optional)_: Enables time-aware position ids during
268
+ extraction (must match the setting used at training time).
269
+ - **sec_per_pos_id**: Number of seconds represented by one position id
270
+ increment.
271
+ - **extract**:
272
+ - **max_len**: Maximum input length (tokens) during extraction.
273
+ - **batch_size**: Batch size for inference.
274
+ - **shard_size** _(optional)_: Number of samples per output parquet shard. Omit
275
+ to write a single file per split.
276
+
277
+ ### Scoring configuration ([example](src/cotorra/config/scoring.yaml))
278
+
279
+ Used by `cotorra generative-score` and `cotorra rep-based-score`.
280
+
281
+ - **run_name**: Name for the current run, used to label output files.
282
+ - **tokens_of_interest**: List of token-based outcomes of interest. Supports
283
+ patterns specified with fnmatch. (Referenced by target tokens.)
284
+ - **score**:
285
+ - **max_len**: Maximum input length (tokens) during scoring.
286
+ - **n_samp**: Number of Monte Carlo samples per input per trajectory type.
287
+ - **target_tokens**: Token-based outcomes of interest to score. Supports
288
+ patterns specified with fnmatch.
289
+ - **end_tokens**: Tokens that naturally terminate a generated sequence (e.g.
290
+ `EOS`).
291
+ - **suppressed_tokens**: Tokens to suppress via logit bias during generation
292
+ (e.g. `PAD`).
293
+ - **trunc_id**: Token id forced after the time horizon is exceeded.
294
+ - **max_time**: Maximum time horizon in minutes.
295
+ - **batch_size**: Batch size for inference.
296
+
297
+ ## Usage
298
+
299
+ We provide a CLI:
300
+
301
+ ```
302
+ Usage: cotorra [OPTIONS] COMMAND [ARGS]...
303
+
304
+ Configurable training for generative event models (vXX.X.X)
305
+
306
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
307
+ โ”‚ --install-completion Install completion for the current shell. โ”‚
308
+ โ”‚ --show-completion Show completion for the current shell, to โ”‚
309
+ โ”‚ copy it or customize the installation. โ”‚
310
+ โ”‚ --help -h Show this message and exit. โ”‚
311
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
312
+ โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
313
+ โ”‚ train Train a model on tokenized data. For tokenization, โ”‚
314
+ โ”‚ consult the cocoa package. โ”‚
315
+ โ”‚ train-private Train a model with differential privacy on tokenized โ”‚
316
+ โ”‚ data. โ”‚
317
+ โ”‚ tune Run hyperparameter tuning while training a model. โ”‚
318
+ โ”‚ extract Extract representations from a trained model. โ”‚
319
+ โ”‚ generative-score Generate SCORE/REACH metrics from a trained model and โ”‚
320
+ โ”‚ save them to parquet. โ”‚
321
+ โ”‚ rep-based-score Generate rep-based scores for the token-based outcomes of โ”‚
322
+ โ”‚ interest. โ”‚
323
+ โ”‚ Note: this requires that features have already been โ”‚
324
+ โ”‚ extracted and saved โ”‚
325
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
326
+ ```
327
+
328
+ with commands:
329
+
330
+ - `cotorra train`
331
+
332
+ ```
333
+ Usage: cotorra train [OPTIONS]
334
+
335
+ Train a model on tokenized data. For tokenization, consult the cocoa package.
336
+
337
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
338
+ โ”‚ --training-config -t PATH Training configuration file โ”‚
339
+ โ”‚ (overrides default) โ”‚
340
+ โ”‚ * --processed-data-home -p TEXT Processed data directory โ”‚
341
+ โ”‚ (overrides config) โ”‚
342
+ โ”‚ [required] โ”‚
343
+ โ”‚ * --output-home -o TEXT Output directory for trained โ”‚
344
+ โ”‚ models โ”‚
345
+ โ”‚ [required] โ”‚
346
+ โ”‚ --resume-from-checkpoint -r Try to resume training from the โ”‚
347
+ โ”‚ latest checkpoint in โ”‚
348
+ โ”‚ --output-home. โ”‚
349
+ โ”‚ --verbose -v Verbose logging โ”‚
350
+ โ”‚ --help -h Show this message and exit. โ”‚
351
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
352
+ ```
353
+
354
+ - `cotorra tune`
355
+
356
+ ```
357
+ Usage: cotorra tune [OPTIONS]
358
+
359
+ Run hyperparameter tuning while training a model.
360
+
361
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
362
+ โ”‚ --training-config -t PATH Training configuration file โ”‚
363
+ โ”‚ (overrides default) โ”‚
364
+ โ”‚ * --processed-data-home -p TEXT Processed data directory (overrides โ”‚
365
+ โ”‚ config) โ”‚
366
+ โ”‚ [required] โ”‚
367
+ โ”‚ * --output-home -o TEXT Output directory for trained models โ”‚
368
+ โ”‚ [required] โ”‚
369
+ โ”‚ --verbose -v Verbose logging โ”‚
370
+ โ”‚ --help -h Show this message and exit. โ”‚
371
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
372
+ ```
373
+
374
+ - `cotorra generative-score`
375
+
376
+ ```
377
+ Usage: cotorra generative-score [OPTIONS]
378
+
379
+ Generate SCORE/REACH metrics from a trained model and save them to parquet.
380
+
381
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
382
+ โ”‚ --scoring-config -s PATH Scoring configuration file โ”‚
383
+ โ”‚ (overrides default) โ”‚
384
+ โ”‚ * --processed-data-home -p TEXT Processed data directory [required] โ”‚
385
+ โ”‚ * --model-home -m TEXT Directory of the trained model to โ”‚
386
+ โ”‚ score with โ”‚
387
+ โ”‚ [required] โ”‚
388
+ โ”‚ --output-home -o TEXT Output directory for scores, โ”‚
389
+ โ”‚ defaults to processed-data-home โ”‚
390
+ โ”‚ --verbose -v Verbose logging โ”‚
391
+ โ”‚ --help -h Show this message and exit. โ”‚
392
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
393
+ ```
394
+
395
+ - `cotorra extract`
396
+
397
+ ```
398
+ Usage: cotorra extract [OPTIONS]
399
+
400
+ Extract representations from a trained model.
401
+
402
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
403
+ โ”‚ --extraction-config -e PATH Extraction configuration file โ”‚
404
+ โ”‚ (overrides default) โ”‚
405
+ โ”‚ * --processed-data-home -p TEXT Processed data directory [required] โ”‚
406
+ โ”‚ * --model-home -m TEXT Directory of the trained model to โ”‚
407
+ โ”‚ extract from โ”‚
408
+ โ”‚ [required] โ”‚
409
+ โ”‚ --output-home -o TEXT Output directory for extracted โ”‚
410
+ โ”‚ features, defaults to โ”‚
411
+ โ”‚ processed-data-home โ”‚
412
+ โ”‚ --all-times -a Extract features for all time steps โ”‚
413
+ โ”‚ (instead of just the final one)? โ”‚
414
+ โ”‚ --help -h Show this message and exit. โ”‚
415
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
416
+ ```
417
+
418
+ - `cotorra rep-based-score` (note: you need to run `extract` first)
419
+
420
+ ```
421
+ Usage: cotorra rep-based-score [OPTIONS]
422
+
423
+ Generate rep-based scores for the token-based outcomes of interest. Note:
424
+ this requires that features have already been extracted and saved
425
+
426
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
427
+ โ”‚ --scoring-config -s PATH Scoring configuration โ”‚
428
+ โ”‚ file (overrides โ”‚
429
+ โ”‚ default) โ”‚
430
+ โ”‚ * --processed-data-hoโ€ฆ -p TEXT Processed data โ”‚
431
+ โ”‚ directory โ”‚
432
+ โ”‚ [required] โ”‚
433
+ โ”‚ * --model-home -m TEXT Directory of the โ”‚
434
+ โ”‚ trained model to โ”‚
435
+ โ”‚ score with โ”‚
436
+ โ”‚ [required] โ”‚
437
+ โ”‚ --output-home -o TEXT Output directory for โ”‚
438
+ โ”‚ scores, defaults to โ”‚
439
+ โ”‚ processed-data-home โ”‚
440
+ โ”‚ [default: None] โ”‚
441
+ โ”‚ --estimator -e [k-NN|lightGBM|logi Estimator to use for โ”‚
442
+ โ”‚ stic|logistic-z|log rep-based scoring โ”‚
443
+ โ”‚ istic-CV|logistic-C [default: lightGBM] โ”‚
444
+ โ”‚ V-z|XGBoost] โ”‚
445
+ โ”‚ --verbose -v Verbose logging โ”‚
446
+ โ”‚ --help -h Show this message and โ”‚
447
+ โ”‚ exit. โ”‚
448
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
449
+ ```
450
+
451
+ - `cotorra train-private`
452
+
453
+ ```
454
+ Usage: cotorra train-private [OPTIONS]
455
+
456
+ Train a model with differential privacy on tokenized data.
457
+
458
+ โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
459
+ โ”‚ --training-config -t PATH Training configuration file โ”‚
460
+ โ”‚ (overrides default) โ”‚
461
+ โ”‚ * --processed-data-home -p TEXT Processed data directory โ”‚
462
+ โ”‚ (overrides config) โ”‚
463
+ โ”‚ [required] โ”‚
464
+ โ”‚ * --output-home -o TEXT Output directory for trained โ”‚
465
+ โ”‚ models โ”‚
466
+ โ”‚ [required] โ”‚
467
+ โ”‚ --noise-multiplier -n FLOAT Noise multiplier (overrides โ”‚
468
+ โ”‚ configuration) โ”‚
469
+ โ”‚ --max-grad-norm -m FLOAT Max grad norm (overrides โ”‚
470
+ โ”‚ configuration) โ”‚
471
+ โ”‚ --verbose -v Verbose logging โ”‚
472
+ โ”‚ --help -h Show this message and exit. โ”‚
473
+ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
474
+ ```
475
+
476
+ [^1]:
477
+ L. Gersony, "The Quiet Victory of Chicagoโ€™s Monk Parakeets," _The Chicago
478
+ Maroon_, 23 January 2022,
479
+ https://chicagomaroon.com/28830/grey-city/quiet-protest-chicagos-monk-parakeets/
480
+
481
+ [^2]:
482
+ M. Burkhart, B. Ramadan, Z. Liao, K. Chhikara, J. Rojas, W. Parker, & B.
483
+ Beaulieu-Jones, Foundation models for electronic health records:
484
+ representation dynamics and transferability,
485
+ [arXiv:2504.10422](https://doi.org/10.48550/arXiv.2504.10422)
486
+
487
+ [^3]:
488
+ M. Burkhart, B. Ramadan, L. Solo, W. Parker, & B. Beaulieu-Jones,
489
+ [Quantifying surprise in clinical care: Detecting highly informative events in electronic health records with foundation models](https://doi.org/10.1142/9789819824755_0013),
490
+ Pacific Symposium on Biocomputing 31 (2026), 173โ€“188
491
+
492
+ [^4]:
493
+ L. Solo, M. McDermott, W. Parker, B. Ramadan, M. Burkhart, & B.
494
+ Beaulieu-Jones, Efficient generative prediction for EHR foundation models:
495
+ the SCOPE and REACH estimators,
496
+ [arXiv:2602.03730](https://doi.org/10.48550/arXiv.2602.03730)
497
+
498
+ [^5]:
499
+ I. Lee, L. Solo, M. Burkhart, B. Ramadan, W. Parker, & B. Beaulieu-Jones,
500
+ Representation before training: a fixed-budget benchmark for generative
501
+ medical event models,
502
+ [arXiv:2604.16775](https://doi.org/10.48550/arXiv.2604.16775)
503
+
504
+ <!--
505
+
506
+ Run in tmux:
507
+ ```
508
+ tmux new -s co || tmux a -t co
509
+ ```
510
+
511
+ Format:
512
+ ```sh
513
+ ruff format .
514
+ ruff check . --fix
515
+ ```
516
+
517
+ Send to bbj-lab1:
518
+ ```
519
+ rsync -avht \
520
+ --delete \
521
+ --exclude "processed" \
522
+ --exclude "data-raw" \
523
+ --exclude "output" \
524
+ --exclude "wandb" \
525
+ --exclude ".venv" \
526
+ --exclude ".idea" \
527
+ ~/Documents/chicago/cotorra \
528
+ bbj-lab1:~
529
+ ```
530
+
531
+ ```
532
+ for d in data-raw processed; do ln -s /mnt/bbj-lab/users/burkh4rt/$d $d; done
533
+ ds='mimic-icu'
534
+ cotorra train \
535
+ --training-config src/cotorra/config/training.yaml \
536
+ --processed-data-home processed/mimic-icu \
537
+ --output-home output/test \
538
+ --resume-from-checkpoint \
539
+ --verbose
540
+ ```
541
+
542
+ Send to randi:
543
+ ```
544
+ for d in data-raw processed; do
545
+ ln -s /gpfs/data/bbj-lab/users/burkh4rt/$d $d
546
+ done
547
+ ```
548
+ ```
549
+ rsync -avh \
550
+ --exclude "output" \
551
+ --exclude "processed" \
552
+ --exclude "data-raw" \
553
+ --exclude "logs" \
554
+ --exclude "wandb" \
555
+ --exclude ".venv/" \
556
+ --exclude ".idea/" \
557
+ ~/Documents/chicago/cotorra \
558
+ randi:/gpfs/data/bbj-lab/users/burkh4rt
559
+ ```
560
+
561
+ ```
562
+ srun -p gpuq \
563
+ --gres=gpu:1 \
564
+ --time=8:00:00 \
565
+ --job-name=adhoc \
566
+ --pty bash -i
567
+ . .venv/bin/activate
568
+ ```
569
+
570
+ Send to pypi:
571
+ ```
572
+ rm -rf dist
573
+ python3 -m pip install --upgrade build
574
+ python3 -m build
575
+ python3 -m pip install --upgrade twine
576
+ python3 -m twine upload --repository pypi dist/*
577
+ ```
578
+
579
+ -->