Tutorial
1. Prepare devices
2. Clone repository and run Docker containers
2-1. Clone repository
cd /path/to/your/working_dir git clone https://github.com/yuakagi/Watcher.git
2-2. Configure settings
2-3. Run Docker containers
cd Watcher docker compose up -d
docker exec -it watcher-pytorch python3 /code/mnt/path/to/script.py
import watcher
3. Upload clinical records to database
Warning
Please note that this Python package performs only minimal data cleaning on preprocessing (e.g., dropping records with missing critical fields, removing duplicates).
Therefore, it is important to pre-clean your data before uploading (e.g., normalizing laboratory test results and units, mapping medical codes, etc.).
Note
You can use any medical coding system (e.g., ICD-10, LOINC, ATC, or custom codes like sequential numbers). What matters is the consistency of coding.
The database is exposed on the port ${POSTGRES_PORT}, which you configure in the .env file.
You can connect directly to this database using external SQL clients for inspection or manual queries if needed.
watcher.db.init_db_with_csv().4. Create dataset
Note
If you plan to fine-tune the model later using an update dataset, please set the argument update_period appropriately when creating the dataset.
Warning
Some parameters of
watcher.preprocess.create_dataset()(e.g., max_sequence_length, etc.) determines the model’s hyperparameters.Please pay attention to these settings.
watcher.preprocess.create_dataset().watcher.preprocess.get_patient_ids().5. Pretrain models
watcher.training.train_watcher().6. Perform simulations
watcher.models.Simulator.simulate().watcher.preprocess.get_patient_ids() for model evaluation if you need them.7. [OPTIONAL] Fine-tune models
watcher.training.train_watcher().8. [OPTIONAL] Simulator demo with GUI
9. [OPTIONAL] Use Simulation API
Note
This API is designed to be used as the simulator backend in our digital-twin EHR system (https://github.com/yuakagi/TwinEHR)
Please use this API in combination with digital-twin EHR together with this AI
docker exec -it watcher-pytorch gunicorn api_launcher:app --bind 0.0.0.0:63425 --workers 1