TCRT5-FT-TCRDB完整指南:从安装到生成CDR3β序列的终极教程

TCRT5-FT-TCRDB完整指南:从安装到生成CDR3β序列的终极教程

TCRT5-FT-TCRDB完整指南:从安装到生成CDR3β序列的终极教程

【免费下载链接】tcrt5_ft_tcrdb项目地址: https://ai.gitcode.com/hf_mirrors/dkarthikeyan1/tcrt5_ft_tcrdb

TCRT5-FT-TCRDB是一款基于T5架构的seq2seq模型,专为条件生成T细胞受体(TCR)序列而设计,能够根据目标肽-MHC(pMHC)生成CDR3β序列。本教程将帮助新手用户快速掌握该模型的安装与使用方法,轻松实现CDR3β序列的生成。

模型简介:TCRT5-FT-TCRDB是什么?

TCRT5-FT-TCRDB是在T5架构基础上构建的transformers模型, operationalized by the associated HuggingFace abstraction。它基于dkarthikeyan1/tcrt5_pre_tcrdb模型进行微调,主要用于在给定pMHC的条件下自动生成CDR3β序列,也可用于无条件生成CDR3β序列。该模型在学术研究中具有重要应用价值,但不适用于临床环境。

快速安装:3步完成环境配置

步骤1:安装Python环境

确保你的系统中已安装Python 3.6及以上版本。如果尚未安装,可从Python官方网站下载并安装。

步骤2:安装依赖库

使用pip命令安装所需的依赖库,包括transformers等:

pip install transformers

步骤3:克隆项目仓库

通过以下命令克隆项目仓库到本地:

git clone https://gitcode.com/hf_mirrors/dkarthikeyan1/tcrt5_ft_tcrdb

入门指南:生成CDR3β序列的2种方法

方法1:条件生成CDR3β序列

条件生成需要提供pMHC作为输入,以下是具体步骤和代码示例:

首先,导入必要的库并加载模型和分词器:

import re from transformers import T5Tokenizer, T5ForConditionalGeneration tokenizer = T5Tokenizer.from_pretrained('dkarthikeyan1/tcrt5_ft_tcrdb') tcrt5 = T5ForConditionalGeneration.from_pretrained("dkarthikeyan1/tcrt5_ft_tcrdb")

然后,定义pMHC输入并进行编码:

pmhc = "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]" encoded_pmhc = tokenizer(pmhc, return_tensors='pt')

接着,设置生成参数并生成CDR3β序列:

num_tcrs = 10 # 要生成的TCR数量 num_beams = 30 # 探索的beam数量(推荐为TCR数量的3倍) outputs = tcrt5.generate(**encoded_pmhc, max_new_tokens=25, num_return_sequences=num_tcrs, num_beams=num_beams, return_dict_in_generate=True)

最后,提取并处理生成的CDR3β序列:

cdr3b_sequences = [re.sub(r'\[.*\]', '', x) for x in tokenizer.batch_decode(outputs['sequences'], skip_special_tokens=True)]

生成的CDR3β序列示例如下: ['CASSLGTGGTDTQYF', 'CASSPGTGGTDTQYF', 'CASSLGQGGTEAFF', 'CASSVGTGGTDTQYF', 'CASSLGTGGSYEQYF', 'CASSPGQGGTEAFF', 'CASSSGTGGTDTQYF', 'CASSLGGGGTDTQYF', 'CASSLGGGSYEQYF', 'CASSLGTGGNQPQHF']

方法2:无条件生成CDR3β序列

无条件生成不需要提供pMHC输入,直接生成CDR3β序列,代码示例如下:

导入库并加载模型和分词器(同上),然后设置生成参数并生成序列:

num_tcrs = 10 num_beams = 30 unconditional_outputs = tcrt5.generate(max_new_tokens=25, num_return_sequences=num_tcrs, num_beams=num_beams, return_dict_in_generate=True) uncond_cdr3b_sequences = [re.sub(r'\[.*\]', '', x) for x in tokenizer.batch_decode(unconditional_outputs['sequences'], skip_special_tokens=True)]

高级技巧:提升生成效果的实用建议

选择合适的解码策略

对于条件生成,使用beam search解码方法可获得较好的性能,但序列多样性会有所降低。如果需要生成更多样化的序列,可以尝试其他解码策略,如ancestral sampling等,相关方法可参考HuggingFace生成策略文档和如何生成文档。

调整生成参数

通过调整num_beams、max_new_tokens等参数,可以影响生成序列的质量和数量。一般来说,增加num_beams可以提高序列的准确性,但会增加计算时间;max_new_tokens则控制生成序列的长度。

模型局限性与注意事项

TCRT5-FT-TCRDB模型存在一些已知的局限性,例如其预测倾向于采样高V(D)J重组概率的序列(如OLGA计算的结果),可以通过使用ancestral sampling等替代解码方法来减轻这种偏差。此外,模型未在肽和MHC序列结合亲和力低的情况下进行测试,因此在使用时需注意输入pMHC的合理性。

训练数据与过程简介

训练数据

TCRT5在约1400万条来自TCRdb的TCR序列以及约74万条来自IEDB的肽-伪序列对上进行预训练。微调则使用了来自VDJdb、IEDB、McPAS的约33万对TCR:肽-伪序列对以及来自MIRA的半合成示例。

训练过程

预训练采用了掩码语言建模(MLM):类似于T5论文中的跨度重建,对序列中15%的部分进行掩码,然后训练模型重建被掩码的序列。微调则使用规范的交叉熵损失,在肽-伪序列->CDR3β的源:目标对上进行。

引用与致谢

如果在研究中使用了TCRT5-FT-TCRDB模型,请引用以下文献:

@Article{Karthikeyan2025_tcrtranslate, author={Karthikeyan, Dhuvarakesh and Bennett, Sarah N. and Reynolds, Amy G. and Vincent, Benjamin G. and Rubinsteyn, Alex}, title={Conditional generation of real antigen-specific T cell receptor sequences}, journal={Nature Machine Intelligence}, year={2025}, month={Sep}, day={08}, abstract={Despite recent advances in T cell receptor (TCR) engineering, designing functional TCRs against arbitrary targets remains challenging due to complex rules governing cross-reactivity and limited paired data. Here we present TCR-TRANSLATE, a sequence-to-sequence framework that adapts low-resource machine translation techniques to generate antigen-specific TCR sequences against unseen epitopes. By evaluating 12 model variants of the BART and T5 model architectures, we identified key factors affecting performance and utility, revealing discordances between these objectives. Our flagship model, TCRT5, outperforms existing approaches on computational benchmarks, prioritizing functionally relevant sequences at higher ranks. Most significantly, we experimentally validated a computationally designed TCR against Wilms' tumour antigen, a therapeutically relevant target in leukaemia, excluded from our training and validation sets. Although the identified TCR shows cross-reactivity with pathogen-derived peptides, highlighting limitations in specificity, our work represents the successful computational design of a functional TCR construct against a non-viral epitope from the target sequence alone. Our findings establish a foundation for computational TCR design and reveal current limitations in data availability and methodology, providing a framework for accelerating personalized immunotherapy by reducing the search space for novel targets.}, issn={2522-5839}, doi={10.1038/s42256-025-01096-6}, url={https://doi.org/10.1038/s42256-025-01096-6} }

感谢所有为TCRT5模型开发和训练提供数据支持的机构和研究人员。

【免费下载链接】tcrt5_ft_tcrdb项目地址: https://ai.gitcode.com/hf_mirrors/dkarthikeyan1/tcrt5_ft_tcrdb

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考