经 AI Skill Hub 精选评估,双重织者 获评「推荐使用」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。
双重织者 是一款基于 Python 开发的开源工具,专注于 EHR、LLM、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
双重织者 是一款基于 Python 开发的开源工具,专注于 EHR、LLM、Python 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一:pip 安装(推荐)
pip install twinweaver
# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install twinweaver
# 方式三:从源码安装(获取最新功能)
git clone https://github.com/MendenLab/TwinWeaver
cd TwinWeaver
pip install -e .
# 验证安装
python -c "import twinweaver; print('安装成功')"
# 命令行使用
twinweaver --help
# 基本用法
twinweaver input_file -o output_file
# Python 代码中调用
import twinweaver
# 示例
result = twinweaver.process("input")
print(result)
# twinweaver 配置文件示例(config.yml) app: name: "twinweaver" debug: false log_level: "INFO" # 运行时指定配置文件 twinweaver --config config.yml # 或通过环境变量配置 export TWINWEAVER_API_KEY="your-key" export TWINWEAVER_OUTPUT_DIR="./output"
<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/MendenLab/TwinWeaver/refs/heads/main/docs/images/candidate_dark_bg_jpg.jpg"> <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/MendenLab/TwinWeaver/refs/heads/main/docs/images/candidate_jpg.jpg"> <img alt="TwinWeaver Logo" src="https://raw.githubusercontent.com/MendenLab/TwinWeaver/refs/heads/main/docs/images/candidate_jpg.jpg" width="40%" title="Title"> </picture> </p>
TwinWeaver is a longitudinal framework for LLM-based Patient Digital Twins. It serializes longitudinal patient histories into text, enabling unified event prediction as well as forecasting with large language models (LLMs). This framework transforms structured patient history—including demographics, labs, treatments, and genetics—into a single, human-readable text prompt, enabling LLMs to jointly forecast continuous biomarkers and predict discrete clinical events, initially presented in our preprint "TwinWeaver: An LLM-Based Foundation Model Framework for Pan-Cancer Digital Twins.".
This project is a collaboration between Roche and Helmholtz Munich, as part of the Munich School of Data Science (MUDS) program.
TwinWeaver addresses the challenge of modeling sparse, multi-modal clinical time series by leveraging the generative capabilities of LLMs.
dm = DataManager(config=config) dm.load_indication_data(df_events=df_events, df_constant=df_constant, df_constant_description=df_constant_description) dm.process_indication_data() dm.setup_unique_mapping_of_events() dm.setup_hold_out_sets(validation_split=0.1, test_split=0.1) dm.infer_var_types()
pandas, numpy, transformers, scikit-learnThe following sections will explain the tutorials/examples and afterwards the quick start guide.
To install the package:
pip install twinweaver
1. Clone the repository and install dependencies:
git clone https://github.com/MendenLab/TwinWeaver
cd twinweaver
pip install -e .
pip install -r examples/requirements.txt
pip install pre-commit pytest pytest-cov
pip install -r docs/requirements.txt
2. Install pre-commit hooks: We use pre-commit to ensure code formatting and quality checks run before you commit.
pip install pre-commit
pre-commit install
The documentation is built with mkdocs. To preview it locally:
mkdocs serve
The examples/ directory provides comprehensive tutorials to help you get up and running.
These notebooks cover the primary workflows for most users:
examples/data_preprocessing/raw_data_preprocessing.ipynbdf_events, df_constant, df_constant_description), including handling death events and other time-to-event outcomes.examples/01_data_preparation_for_training.ipynbexamples/02_inference_prompt_preparation.ipynbexamples/03_end_to_end_llm_finetuning.ipynbpip install twinweaver[fine-tuning-example] (torch CUDA version might need to be adapted to your system)For users needing custom behavior or specific integrations:
examples/advanced/pretraining/prepare_pretraining_data.pyexamples/advanced/pretraining/end_to_end_llm_training_with_pretrain.ipynbpip install twinweaver[fine-tuning-example].examples/advanced/custom_splitting/inference_individual_splitters.py: Example script for inference using individual splitters.examples/advanced/custom_splitting/training_individual_splitters.ipynb: Notebook demonstrating training data generation with individual splitters.examples/advanced/custom_splitting/training_custom_split_events.ipynb: Notebook showing how to customize split events and forecast different event categories.examples/advanced/custom_splitting/training_forecasting_splitter_only.ipynb: Forecasting-only example showing training data generation using only the DataSplitterForecasting (no event splitter).examples/advanced/custom_splitting/training_forecasting_qa.ipynb: Demonstrates the Forecasting QA mode, which bins continuous target values into discrete categories for classification-style prediction, and compares all three forecasting modes ("forecasting", "forecasting_qa", "both").examples/advanced/custom_output/customizing_text_generation.ipynbexamples/advanced/custom_output/custom_summarized_row.ipynbset_custom_summarized_row_fn(). Includes minimal and advanced examples, plus error handling guidance.examples/advanced/tte_inference/tte_probability_inference.ipynbexamples/integrations/meds_data_import.ipynbHere's a minimal example to get you started with TwinWeaver:
```python import pandas as pd
from twinweaver import ( DataManager, Config, DataSplitterForecasting, DataSplitterEvents, ConverterInstruction, DataSplitter, )
config = Config()
data_splitter = DataSplitter(data_splitter_events, data_splitter_forecasting)
1. Text Serialization: Transforms multi-modal inputs (diagnoses, laboratory measurements, genetic mutation panels) into a structured textual representation of longitudinal patient trajectories. 2. Unified Task Support: Time-Series Forecasting: Forecasting frequently measured values such as blood biomarkers or vital signs. Landmark Event Prediction: Predicting patient event status (e.g., survival, disease progression) at future time points using a landmarking framework. 3. Flexible Horizon: Supports sampling split times and prediction horizons to avoid overfitting to specific canonical time points.
1. Create a New Branch: Always create a new branch for your feature or fix.
git checkout -b feature/my-new-feature
2. Make Changes: Implement your feature or fix. 3. Run Tests & Linting: Ensure your code passes all tests and pre-commit hooks. 4. Submit a Merge Request: Push your branch to the repository. Open a Merge Request (Pull Request) against the main branch. * Describe your changes clearly in the MR description.
TwinWeaver supports two primary data formats, each serving a distinct stage in the model training pipeline:
1. Pretraining Data: Purpose: Continued Pretraining (CPT) to adapt a general-purpose LLM to the clinical domain. Format: A narrative-style serialization of the entire patient history. It does not contain specific questions or answers but rather presents the patient's chronological journey as a continuous text. Goal: Enables the model to learn medical terminology, clinical relationships, and temporal dynamics in an unsupervised manner (next-token prediction). Converter: twinweaver.pretrain.converter_manual_template.ConverterPretrain
2. Instruction Data: Purpose: Supervised Fine-Tuning (SFT) to teach the model to perform specific clinical tasks. Format: Structured into "Input" (Prompt) and "Target" (Completion) pairs. Input: Patient history up to a specific time point + a list of specific questions (e.g., "Forecast the next 3 weeks of hemoglobin values"). Target: The ground truth answers to those questions. Goal: Optimizes the model for specific downstream applications like forecasting and risk stratification. Converter: twinweaver.instruction.converter_manual_instruction.ConverterInstruction
Further details at https://mendenlab.github.io/TwinWeaver/framework/.
TwinWeaver 是一个用于建模稀疏多模态临床时间序列的框架,利用大语言模型(LLMs)的生成能力来解决这一挑战。
TwinWeaver 需要 Python 3.8 或更高版本,核心依赖项包括 `pandas`、`numpy`、`transformers` 和 `scikit-learn`。
安装 TwinWeaver 可以使用 pip:`pip install twinweaver`。开发环境设置包括克隆仓库、安装依赖项和安装预提交钩子等步骤。
TwinWeaver 提供了多个教程和示例,帮助用户快速上手。核心教程包括原始数据预处理、预训练数据转换等。
配置文件包括 MCP、环境变量和关键参数等。初始化配置文件使用 `Config()` 函数。
TwinWeaver 提供了一个易用的接口,用于数据划分和预测等任务。数据划分器使用 `DataSplitter` 类实现。
TwinWeaver 的核心组件包括文本序列化和统一任务支持。文本序列化将多模态输入转换为结构化的文本表示,用于描述患者的长期轨迹。统一任务支持包括时间序列预测等功能。
高质量的医疗数据处理工具
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ Apache 2.0 — 宽松开源协议,可商用,需保留版权声明和 NOTICE 文件,含专利授权条款。
AI Skill Hub 点评:双重织者 的核心功能完整,质量良好。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | TwinWeaver |
| 原始描述 | 开源AI工具:A library for converting EHR data into LLM ingestible text.。⭐16 · Python |
| Topics | EHRLLMPython |
| GitHub | https://github.com/MendenLab/TwinWeaver |
| License | Apache-2.0 |
| 语言 | Python |
收录时间:2026-06-07 · 更新时间:2026-06-08 · License:Apache-2.0 · AI Skill Hub 不对第三方内容的准确性作法律背书。