## TCR-GPT: Integrating Autoregressive Model and Reinforcement Learning for T-Cell Receptor Repertoires Generation

## Yicheng Lin, Dandan Zhang, Yun Liu

School Of Basic Medical Sciences, Fudan University linyc20@fudan.edu.cn, zhangdandan3@hotmail.com, yliu39@fudan.edu.cn

## Abstract

T-cell receptors (TCRs) play a crucial role in the immune system by recognizing and binding to specific antigens presented by infected or cancerous cells. Understanding the sequence patterns of TCRs is essential for developing targeted immune therapies and designing effective vaccines. Language models, such as auto-regressive transformers, offer a powerful solution to this problem by learning the probability distributions of TCR repertoires, enabling the generation of new TCR sequences that inherit the underlying patterns of the repertoire. We introduce TCR-GPT, a probabilistic model built on a decoder-only transformer architecture, designed to uncover and replicate sequence patterns in TCR repertoires. TCR-GPT demonstrates an accuracy of 0.953 in inferring sequence probability distributions measured by Pearson correlation coefficient. Furthermore, by leveraging Reinforcement Learning(RL), we adapted the distribution of TCR sequences to generate TCRs capable of recognizing specific peptides, offering significant potential for advancing targeted immune therapies and vaccine development. With the efficacy of RL, fine-tuned pretrained TCR-GPT models demonstrated the ability to produce TCR repertoires likely to bind specific peptides, illustrating RL's efficiency in enhancing the model's adaptability to the probability distributions of biologically relevant TCR sequences.

## Introduction

T-cell receptors (TCRs) are integral components of the immune system, playing a crucial role in recognizing and responding to antigens. Each TCR is composed of unique sequences of amino acids, enabling T cells to identify specific pathogens and infected cells. The diversity and specificity of TCR sequences are vital for the adaptive immune response, allowing the immune system to target a vast array of antigens with precision (Singh, N. K., et al. 2017; van der Merwe, P. A., and O. Dushek 2011).Understanding the repertoire of TCR sequences is essential for advancing immunological research and developing targeted therapies.

Text-generation models, inspired by natural language processing techniques (Chung, Junyoung, et al. 2014; Hochreiter, Sepp, and J¨rgen Schmidhuber 1997; Vaswani, Ashish, u et al. 2017), can potentially offer a transformative approach to this task. By building a probability distribution over TCR sequences, and even more, tailoring this distribution to generate TCR sequences of specific desired functionality, text- generation models can not only enhance our understanding of TCR diversity but also has practical applications in designing vaccines and immunotherapies.

In the realm of auto-regressive text generation, decoderonly transformers have become a cornerstone technology. This architecture processes input sequences to generate text in an auto-regressive manner, predicting the next token in a sequence based on the tokens it has previously generated. At each step, the model takes the current sequence of tokens as input, processes it through multiple layers of self-attention and feed-forward networks, and produces a probability distribution over the next possible tokens. The model then samples from this distribution to select the next token, appends it to the input sequence, and repeats the process until the desired output length is achieved or a stopping condition is met. Decoder-only transformers like GPT (Generative Pretrained Transformer) (Brown, Tom B., et al. 2020; Radford, Alec, et al. 2018, 2019) have demonstrated remarkable performance in various natural language processing tasks, from completing sentences and paragraphs to generating entire articles or dialogues, thus setting new benchmarks for text generation capabilities.

Reinforcement Learning (RL) involves training agents to maximize long-term rewards by interacting with complex environments. This method has been applied across diverse fields such as game playing (Souchleris, Sidiropoulos, and Papakostas 2023), robotics (Zhang and Mo 2021), drug discovery (Bilodeau et al. 2022; Du et al. 2022; Fromer and Coley 2023; Luukkonen et al. 2023; Tang, Ewalt, and Ng 2021), and more. Reinforcement learning has also emerged as an effective alternative training approach to enhance the performance of generative models, offering adaptable goals via its reward function, unlike the fixed distribution modeling objectives found in both supervised and unsupervised learning (Cao et al. 2023).

In this study, we introduce TCR-GPT, a probabilistic model based on a decoder-only transformer architecture designed to capture underlying sequence patterns in TCR repertoires and hence generate TCR sequences based on the learned probability distribution. And through reinforcement learning, we tailored the distribution of TCR sequences to generate TCRs that can recognize specific peptides, which holds great promise for advancing targeted immune therapy and vaccine design. TCR-GPT demonstrates greater ac- curacy in inferring sequence probability distributions compared to existing models, with average performance 0.953 as measured by the correlation coefficient. We further verified that TCR-GPT can efficiently adapt to different TCR sub-repertoires and provide learnable features for TCR sequences. After that, we demonstrate the effectiveness of RL in fine-tuning pretrained TCR-GPT models to generate TCR repertoires likely to bind specific peptides. Using PanPep (Gao, Yicheng, et al. 2023), a robust peptide-TCR binder prediction tool, we iteratively refine TCR-GPT through RL to generate peptide-specific TCR repertoires, showcasing RL's efficiency in significantly enhancing the model's ability to adapt to the underlying probability distribution of biologically relevant TCR sequences.

## Related work

Traditional methods for modeling TCR sequence patterns calculate the probability of a TCR sequence as the product of the selection factor and the generation probability, which are inferred separately from the processes of TCR selection and generation. A notable example of this approach is soNNia (Isacchini, G., et al. 2021).

Trials have also been conducted using variational autoencoders (VAEs) parameterized by deep neural networks to model TCR repertoires (Davidsen, K., et al. 2019). However, it requires TCR sequences to be padded to a fixed length, which can introduce noise into the original data and obscure valuable information about the diversity of sequence lengths.

Inspired by natural language processing and autoregressive text generation models, TCRpeg (Jiang, Y., and S. C. Li 2023) employs an auto-regressive framework to infer the probability of TCR sequences in an end-to-end manner. TCRpeg utilizes a deep autoregressive architecture with gated recurrent unit (GRU) layers (Chung, Junyoung, et al. 2014)to effectively model the probability of TCR sequences, offering a streamlined alternative to the above trials.

Transformer models, introduced by Vaswani et al. in 2017, have revolutionized the field of natural language processing (NLP) (Vaswani, Ashish, et al. 2017). Unlike previous sequence-to-sequence models that relied heavily on recurrent neural networks (RNNs) (Chung, Junyoung, et al. 2014; Hochreiter, Sepp, and J¨rgen Schmidhuber 1997; u Schulman, John, et al. 2017)and convolutional neural networks (CNNs) (O'Shea and Nash 2015), transformers leverage self-attention mechanisms to process input data in parallel, allowing for greater efficiency and scalability. The core innovation of the transformer architecture is its ability to capture long-range dependencies within the data, which is crucial for understanding and generating coherent text. A notable example that combines transformer and autoregressive models is the GPT (Generative Pre-trained Transformer) series (Brown, Tom B., et al. 2020; Radford, Alec, et al. 2018, 2019). These models generate text by predicting each word or token based on the preceding sequence, utilizing the attention mechanism inherent in transformer decoders to create coherent and contextually relevant text.

Reinforcement learning has demonstrated its efficacy as a robust method for training generative models, especially in NLP tasks (Cao et al. 2023). Reinforcement Learning with Human Feedback (RLHF) (Bai et al. 2022; Shi et al. 2018; Gao, Meyer, and Gurevych 2020; Kreutzer, Riezler, and Lawrence 2020; Ouyang et al. 2022) is a representative technique where reinforcement learning is used to fine-tune language models based on human-provided feedback. In the context of large language models (LLMs) like GPT, RLHF helps improve the model's performance by aligning its outputs with human preferences, leading to more contextually appropriate responses.

## Methods

## Autoregressive generative transformer for TCR sequences

Given the critical role of the CDR3β chain in TCR antigen recognition (Singh, N. K., et al. 2017; van der Merwe, P. A., and O. Dushek 2011), we utilized the CDR3β sequence as a representation of the entire TCR. We developed an autoregressive model, TCR-GPT, to estimate the probability of a TCR sequence x as p ( x | θ ) , where θ represents the parameters of a decoder-only transformer model. This probability p ( x | θ ) is computed by the autoregressive likelihood, which involves calculating the product of conditional probabilities over sequential residues of length L :

$$p \left ( { \mathbf x } | \theta \right ) = p \left ( { x _ { 1 } } | \theta \right ) \prod _ { i = 2 } ^ { L } p \left ( { x _ { i } } | { x _ { 1 } }, { x _ { 2 } }, \dots, { x _ { i - 1 } } ; \theta } \right ) \quad ( 1 )$$

Our model employs a decoder-only transformer equipped with attention mechanisms to capture interactive relationships among residues, thereby formulating the autoregressive likelihood efficiently. After embedding layers transform the discrete representation of each amino acid in batches of TCR sequences into continuous vectors of dimensionality 32, a total of 8 attention heads, each with 6 selfattention layers, collectively capture the features. Specifically, let X ∈ [0 , 1 2 , , ..., 22] B × L denote a batch of B TCRs of maximum length L . Each element in X is an integer representing an amino acid (a total of 20 different amino acids), as well as special tokens such as &lt; SOS &gt; (Start of Sequence), &lt; EOS &gt; (End of Sequence), and padding token. After embedding, X is transformed to a continuous tensor E ∈ R B × × L d , where each vector of dimension d = 32 represents the embedding of a single token. The multi-head attention layers, along with the linear layers after multi-head feature concatenation then transform E to features Z ∈ R B × × L d . These features are then processed by a position-wise feedforward network to output the probability distribution over all 20 possible amino acids at each position. The overall architecture of TCR-GPT is depicted in Figure 1A. We set the negative log likelihood as the loss function as the following:

$$L = - \sum _ { n = 1 } ^ { N } \sum _ { i = 1 } ^ { L } l o g p _ { i } \\ \dots \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot$$

N is the batch size and p i is the output probability of the model on the right amino acid in i -th amino acid position.

Figure 1: (A) The overall architecture of TCR-GPT. (B) Main workflow of peptide-specific RL for TCR-GPT.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-aeaeaaca-aa78-491b-a9ca-5239863b9d53.jpg)

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-ca800eb4-1de8-4f83-befb-174b78ed2514.jpg)

We trained the model on a dataset containing 50 million TCRs collected from a large cohort of 743 individuals, as described by Emerson et al (Emerson, R. O., et al. 2019).

acid. This approach can be summarized by the following formula:

## Jensen-Shannon Divergence

We use Jensen-Shannon divergence ( D js ( r , r i j ) ) to measure the ability of the trained model to distinguish two subrepertoires r i and r j , which is formulated as:

$$D _ { j s } ( r ^ { i }, r ^ { j } ) & = \frac { 1 } { 2 } K L ( P ^ { i } _ { i n f e r } | | M ) + \frac { 1 } { 2 } K L ( P ^ { j } _ { i n f e r } | | M ) \quad \stackrel { \text{aow} } { \text{seq} } \\ \cdot \quad \pi i \quad \cdot \pi i \quad \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot \cdot$$

where P i infer and P j infer are probabilities computed from TCR-GPT trained on sub-repertoires r i and r j , M = 1 2 ( P i infer + P j infer ) , and KL P ( || Q ) denotes the KullbackLeibler divergence. A higher D js ( r , r i j ) indicates greater discrepancy between sub-repertoires.

For the scenario where we utilize Jensen-Shannon divergence to assess the difference of the inferred likelihood from the model P infer ( x ) and the observed frequencies P data ( x ) , we simply calculate D js ( P infer , P data ) as the following:

$$D _ { j s } ( P _ { i n f e r }, P _ { d a t a } ) = \frac { 1 } { 2 } K L ( P _ { i n f e r } ( { \mathbf x } ) | | M ) \quad ( 4 ) \quad \text{ see} \\ + \frac { 1 } { 2 } K L ( P _ { d a t a } ( { \mathbf x } ) | | M ) \quad ( 4 ) \quad \text{ see} \\ \quad \text{ is} \quad.$$

where M = 1 2 ( P infer ( x ) + P data ( x )) .

## Using TCR-GPT to generate TCR sequences

With the TCR-GPT model trained, we employed a straightforward sampling method to generate new TCR sequences. Initially, we input the start token ( &lt; SOS &gt; ) into the model and then sampled the amino acid for the next position from the resulting probability distribution. This sampled amino acid was appended to the previous tokens, and the process was repeated iteratively to generate each subsequent amino

$$A _ { t } = P ( A | A _ { 0 \colon t - 1 } ; \theta )$$

Here, A t represents the amino acid token at position t , and θ denotes the parameters of the TCR-GPT model. The generation process concludes when the &lt; EOS &gt; (End Of Sequence) token is generated. At this point, all the generated amino acids are collected to form the complete TCR sequence.

## Using the features from TCR-GPT for classification tasks

Upon training the TCR-GPT model, the features produced by the multi-head attention module can encode valuable information from the sequence input. We developed an additional classification network that utilizes these features for a downstream classification task. Specifically, let X ∈ [0 , 1 2 , , ..., 22] B × L represent a batch of B TCRs with a maximum length of L . The features extracted from the multihead attention module are denoted as Z ∈ R B × × L d , where the feature of the amino acid at each position in the L -length sequence is a d -dimensional tensor. We then flattened the feature Z to Z flatten ∈ R B × q , where each TCR sequence is represented as a q -dimensional tensor. We constructed a fully connected neural network for each classification task, which consists of three linear layers that can be formulated as follows:

$$Z _ { 0 } = Z _ { f l a t t e n }$$

$$Z _ { l } = \sigma ( W _ { l } Z _ { l - 1 } + b _ { l - 1 } ), l \in \{ 1, 2 \} \quad \ \ ( 7 )$$

$$P = s o f t m a x ( W _ { 3 } Z _ { 2 } + b _ { 3 } )$$

here, W l and b l represent the parameters of the l -th layer of the fully connected neural network, and σ denotes the activation function. The final layer, combined with the softmax operation, produces the predicted probability distribution of the classes.

## Fine-tuning TCR-GPT with RL to generate peptide-specific TCR repertoires

To generate TCR repertoires capable of binding to specific peptides, we employ peptide-specific RL to integrate knowledge from high-performance peptide-TCR binding predictors into our pretrained TCR-GPT model. PanPep (Gao, Yicheng, et al. 2023), a versatile and robust model for evaluating peptide-TCR binding affinity, leverages meta-learning and neural Turing machine concepts to achieve superior performance in both few-shot and zero-shot scenarios. We adopt PanPep as the reward model in our reinforcement learning framework. During the reinforcement learning iteration, PanPep rates the generated TCR sequences from TCR-GPT based on their binding affinity to the given peptide.

Specifically, with given peptide denoted as s , let the reward for the generated TCR sequences from the TCR-GPT model be denoted as F R ( s X , ) . Here, PanPep serves as the reward function F R for the generated TCR sequences. We constructed another transformer network parameterized by φ k at the k -th iteration as the critic V φ k , which shares the same architecture as the TCR-GPT model (the actor in this scenario). However, the critic's output is a single value representing the predicted return for each TCR sequence entry. Using PPO (Schulman, John, et al. 2017)as the reinforcement learning algorithm, we formulate the objective function as

$$& L \left ( s, X, \theta _ { k }, \theta \right ) \\ & = \min ( \frac { p _ { \theta } ( X | s ) } { p _ { \theta _ { k } } ( X | s ) } A ^ { p _ { \theta _ { k } } } \left ( s, \, X \right ), g ( \epsilon, A ^ { p _ { \theta _ { k } } } \left ( s, \, X \right ) ) ) \right ) \quad ( 9 ) \quad \text{$\text{$\text{$fetch}$} }$$

where

$$g ( \epsilon, A ) = \begin{cases} \begin{array} { c c } ( 1 + \epsilon ) A, & A \geq 0 \\ ( 1 - \epsilon ) A, & A < 0 \end{array} \end{cases} \quad ( 1 0 ) \quad \begin{array} { c } \mathbb { T } \\ \mathbb { a } \end{array}$$

$$A ^ { p _ { \theta _ { k } } } ( s, \, \mathbf X ) = F _ { R } ( s, \mathbf X ) - V ^ { \varphi _ { k } } ( \mathbf X ) \quad ( 1 1 )$$

The advantage A p θ ( s , X ) is the difference between reward F R ( s X , ) and the value V φ k ( X ) , the predicted reward of TCR sequence X by the critic network parameterized by φ in the k -th iteration. ϵ is a hyperparameter that we set at 0.2 as used in the previous paper (Schulman, John, et al. 2017). At k -th iteration, we update the parameters θ of TCRGPT, and the parameters φ of the crtic in the following formula:

$$\theta _ { k + 1 } = \arg \max _ { \theta } \frac { 1 } { | D _ { k } | } \sum _ { X \in D _ { k } } L \left ( s, X, \theta _ { k }, \theta \right ) \quad ( 1 2 ) \quad \text{rec} [ \text{Re} ]$$

$$\varphi _ { k + 1 } = \underset { \varphi } { \arg \min } \frac { 1 } { | D _ { k } | } \sum _ { X \in D _ { k } } \left [ V ^ { \varphi k } ( \mathbf X ) - F _ { R } ( s, \mathbf X ) \right ] ^ { 2 } \ ( 1 3 ) \quad \text{$\text{$\text{CD}$}$}.$$

Where D k is a batch of TCR sequences collected using TCR-GPT model during the k -th iteration. The peptidespecific RL workflow can be visualized in Figure 1B.

## Experiments

## TCR-GPT infers the probability distribution of TCR repertoires with high accuracy

To evaluate the performance of TCR-GPT, we first applied it to infer the probability distribution of TCRβ CDR3 sequences and compared its performance with two other algorithms, soNNia (Isacchini, G., et al. 2021)and TCRpeg (Jiang, Y., and S. C. Li 2023). We constructed a universal TCR repertoire by pooling the CDR3 sequences from a large cohort of 743 individuals (Emerson, R. O., et al. 2019). This comprehensive dataset provided a robust foundation for training and testing our model as well as the comparative algorithms. To assess the accuracy of these three methods, we randomly divided the universal repertoire into training and testing sets using a 50:50 ratio, the same strategy employed by TCRpeg. This approach ensured a fair and consistent comparison across the different models.

We measured the concordance between the inferred ( P infer ( x ) ) and the actual probability distributions ( P data ( x ) ) by Pearson correlation coefficients. TCR-GPT demonstrated greater concordance, achieving a Pearson correlation coefficient of r = 0 953 . , compared to soNNia ( r = 0 673 . ) and TCRpeg ( r = 0 932 . ) (Figure 2A-C). These results indicate that TCR-GPT has the highest accuracy among the three methods, as reflected by its closer alignment with the actual probability distributions.

In addition to Pearson correlation coefficients, we utilized the Jessen-Shannon divergency ( D js , Methods) to assess the difference between P infer ( x ) and P data ( x ) . The D js statistics provides a measure of divergence between two probability distributions, with a higher D js indicating a greater difference, and consequently lower model accuracy. The D js statistic further confirmed the higher accuracy of TCR-GPT, which had a D js value of 0.031. In contrast, soNNia and TCRpeg had D js values of 0.131 and 0.039, respectively. These results underscore the effectiveness of TCR-GPT in accurately inferring the probability distribution of TCRβ CDR3 sequences.

According to the comparisons above, we conclude that TCR-GPT outperformed soNNia and TCRpeg in both measures of accuracy, making it the most reliable method among the three for inferring the probability distribution of TCRβ CDR3 sequences. The superior performance of TCRGPT, as evidenced by both Pearson correlation coefficients and Jensen-Shannon divergence, highlights its potential as a powerful tool for TCR repertoire analysis.

## TCR-GPT captures specific features of TCR repertoires efficiently

We further investigated TCR-GPT's ability to learn the specific probability distributions of different TCR repertoires to compare their properties from a probabilistic perspective. CD4 and CD8 T cells have distinct roles in adaptive immunity across various tissues, which may be reflected by their

Figure 2: Performance comparison of TCR-GPT, soNNia and TCRpeg algorithms. A-C. The scatter plot of actual ( P data ) versus inferred probability ( P infer ) for soNNia (A), TCRpeg (B) and TCR-GPT (C) using test dataset from universal TCR repertoire. The corresponding Pearson correlation coefficients are displayed for each plot.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-3f546c7d-95f3-4832-9311-ed4d3babd5ac.jpg)

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-680ca7cd-cc1e-4e1c-a982-8dc59e1ac2da.jpg)

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-d28da622-f810-4cc5-9f5a-68abeb99710e.jpg)

unique TCR repertoires. Utilizing a dataset (Jiang, Y., and S. C. Li 2023; Seay, H. R., et al. 2016)comprising three different cell types (CD8 cytotoxic T lymphocytes(CD8+), CD4 T help cells(Tconv) and CD4 Treg cells(Treg)) collected from three tissues (spleen, pancreatic draining lymph modes [pLN] or inguinal 'irrelevant' lymph nodes [iLN]), we compared the discrepancy among these nine sub-repertoires.

We used TCR-GPT to construct a probabilistic generative model for each of these nine TCR sub-repertoires. For each sub-repertoire, we inferred its probability using nine models: one trained from its own TCR repertoire (denoted as P ) and eight from the remaining TCR repertoires (denoted as Qs ). To estimate the distance between each pair of sub-repertoires, we calculated the Jessen-Shannon divergency ( D js ) for P and each Q . The D js matrix revealed an interesting pattern: sub-repertoires of the same cell type were more similar to each other than to those from different cell types, and CD4 T cell subtypes exhibited greater simi- larity to each other than to CD8 T cells (Figure 3).

Given the fundamental role of the CDR3 sequence in determining T-cell function through antigen recognition (PMID: 28923982), these results suggest that the same cell subtypes with similar CDR3 repertoire performed analogous functions across different tissues.

Moreover, the higher similarity observed among CD4 T cell subtypes compared to CD8 T cells aligns with the distinct functional roles that CD4 and CD8 T cells play in the immune system. CD4 T cells are primarily involved in helper or regulator functions, facilitating the activation or inhibition and coordination of other immune cells, while CD8 T cells are chiefly responsible for cytotoxic activities, directly targeting and eliminating infected or malignant cells.

This probabilistic comparison of TCR repertoires across different cell types and tissues enhances our understanding of the adaptive immune system's complexity. It provides insights into how specific TCR repertoires are tailored to meet the unique functional demands of different T cell subtypes in various tissue environments. Such knowledge is invaluable for advancing immunotherapy and vaccine development, where targeted manipulation of TCR repertoires could lead to more effective and precise treatments.

Figure 3: The heatmap of Jensen-Shannon divergence ( D js ) between pairwise sub-repertoire probability distribution inferred by TCR-GPT.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-a4198e65-88f9-4f2a-a34a-5486b5f8d2b1.jpg)

## Classification of cancer-associated TCRs and SARS-CoV-2 epitope-specific TCRs using features from TCR-GPT

During the process of TCR probability inference, TCR-GPT yields features for each TCR sequence. Unlike predefined embeddings, the features provided by TCR-GPT are generated in a learnable manner, allowing the model to adaptively capture the underlying patterns within the TCR sequences.

Figure 4: UMAP Visualization and Classification Performance of TCR-GPT. (A, B) UMAP plots of features learned by TCRGPT trained on caTCRs (A) and SARS-TCRs (B), along with motif logos of selected clustered TCR sequences. (C, D) Area under curve (AUC) for classifiers predicting caTCRs (C) and SARS-TCRs (D) trained with TCR-GPT.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-20e90d86-cfc7-4e47-8be6-9bd5d8c571ac.jpg)

To depict the features of TCR sequences, we evaluated cancer-associated TCRs (caTCRs) from Beshnova et al (Beshnova, D., et al. 2020)( N ∼ 43 000 , ) and SARS-CoV-2 epitope (YLQPRTFLL) specific TCRs (SARS-TCRs) from VDJdb database (Shugay, M., et al. 2018)( N = 683 ). We trained TCR-GPT using these two TCR repertoires separately to obtain the representative feature vectors of each sequence.

The Uniform Manifold Approximation and Projection (UMAP) dimensionality reduction applied to the feature space revealed explicit clusters in the 2D map (Figure 4A, B). Sequences within the same cluster shared a similar motifs, suggesting that the features generated by TCR-GPT could accurately represent the TCR sequences.

Figure 5: Binding percentage of generated TCRs with specific peptide sequences increases with the number of PPO gradient steps.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-3c38a2cd-3518-4ddb-ba51-4e83d40fbe92.jpg)

To further illustrate the effectiveness behind TCR-GPT's features of TCRs, we performed classification(Methods) of caTCRs and SARS-TCRs from control (negative) TCRs sampled from the universal TCR repertoire mentioned above. We extensively compared TCR-GPT with TCRpeg in both caTCR and SARS-TCR classification tasks. Using five-fold cross-validation, TCR-GPT exhibited more stable and accurate performance than TCRpeg in caTCRs classification task, achieving Aera Under the Curve (AUC) values of 0.895±0.005 for TCR-GPT and 0.863±0.012 for TCRpeg (Figure 4C).

The results from the SARS-TCR classification task also support the superior performance of TCR-GPT, with AUCs of 0.862±0.030 compared to 0.847±0.027 for TCRpeg (Figure 4D). The consistent performance of TCR-GPT across different classification tasks indicates its robustness and generalizability in modeling TCR sequences. The higher AUC values for TCR-GPT suggest that it can more effectively capture the relevant features that distinguish specific TCRs from the general repertoire, thereby enhancing its predictive accuracy.

Figure 6: Comparison of the percentage of TCRs generated from TCR-GPT overlapped with real TCRs binding to specific peptides, with and without RL fine-tuning.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.01156v1-figure-108a91d5-8cad-4d66-b1db-8799285a7744.jpg)

## Generating peptide-specific TCRs using TCR-GPT fine-tuned with RL

Using TCR-GPT trained with universal TCR sequences, we address a more practical scenario. For a specific peptide, we employ RL to fine-tune the learned distribution, adapting it from universal TCR sequences to those that can bind to the specific peptide(Methods). PanPep (Gao, Yicheng, et al. 2023)can output binding score ranges from 0 to 1 that indicate the binding probability of the given peptide and TCR. Based on this, we defined the binding percentage as the proportion of peptides generated by TCR-GPT with RL that have a binding score from PanPep exceeding threshold 0.5. RL demonstrated promising training efficiency, as evidenced by the significant increase in binding percentage of five tested peptides shown in Figure 5.

RLadjusts the distribution of learned TCR sequences, and it is crucial to ensure that the tuned model can generate TCR sequences similar to actual TCRs that bind to the target peptide. To verify this, we assess how many TCR sequences generated by the model-with and without RL-match real TCR sequences known to bind the target peptide. For each tested peptide, we compiled a set of known TCRs from IEDB (Vita et al. 2018) that can bind to it. We then used both models to generate 10,000 TCR sequences each and calculated the proportion of these sequences that matched the known TCRs. This process was repeated 100 times, with each proportion serving as a sample. we observed that the proportions of generated TCR sequences overlapped with real TCRs capable of binding to the given peptide were significantly higher for the TCR-GPT model fine-tuned with RL compared to the one without RL, as shown in Figure 6. This demonstrates that RL is capable of fine-tuning the TCR-GPT model to match the distribution of real TCRs specifically binding to the given peptide.

## Conclusion

Text-generation models, driven by advanced natural language processing (NLP) techniques, have the potential to transform our understanding and utilization of TCR diversity. In our research, we introduce TCR-GPT, a sophisticated probabilistic model based on a decoder-only transformer architecture. This model is designed to identify sequence patterns within TCR repertoires and generate TCR sequences from the learned probability distribution. By implementing RL, we tailored the TCR sequence distribution to produce repertoires capable of recognizing specific peptides. This advancement holds significant potential for revolutionizing targeted immune therapies and vaccine development, paving the way for practical and effective medical applications.

The limitations of this study primarily stem from the fact that TCR-GPT is a probabilistic model focused exclusively on the CDR3 region of the TCR beta chain, thereby excluding the full-length sequences of both the alpha and beta chains of TCR sequences. This narrowed focus restricts the comprehensiveness of the model in representing the complete TCR repertoire. Future research efforts will be directed towards collecting paired full-length TCR sequences and scaling up the model's parameters to accommodate the need for constructing a robust probability distribution of the fulllength TCRs. Despite these current limitations, we are confident in the potential of the TCR-GPT architecture to effectively address these challenges with an adequately sized dataset. Additionally, we believe that RL will continue to be a highly efficient method for fine-tuning the distribution to meet specific targets, thereby enhancing the applicability and precision of our model in practical scenarios.

## References

Bai, Y.; Jones, A.; Ndousse, K.; Askell, A.; Chen, A.; DasSarma, N.; Drain, D.; Fort, S.; Ganguli, D.; Henighan, T.; et al. 2022. Training a helpful and harmless assistant with reinforcement learning from human feedback. arXiv preprint arXiv:2204.05862 .

Beshnova, D., et al. 2020. De novo prediction of cancerassociated T cell receptors for noninvasive cancer detection. Science Translational Medicine , 12(557): eaaz3738.

Bilodeau, C.; Jin, W.; Jaakkola, T.; Barzilay, R.; and Jensen, K. F. 2022. Generative models for molecular discovery: Recent advances and challenges. Wiley Interdisciplinary Reviews: Computational Molecular Science , 12(5): e1608.

Brown, Tom B., et al. 2020. Language Models are Few-Shot Learners. arXiv e-prints , arXiv:2005.14165.

Cao, Y.; Yao, L.; McAuley, J.; and Sheng, Q. Z. 2023. Reinforcement learning for generative AI: A survey. arXiv preprint arXiv:2308.14328 .

Chung, Junyoung, et al. 2014. Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling. arXiv e-prints , arXiv:1412.3555.

Davidsen, K., et al. 2019. Deep generative models for T cell receptor protein sequences. eLife , 8: e46935.

Du, Y.; Fu, T.; Sun, J.; and Liu, S. 2022. Molgensurvey: A systematic survey in machine learning models for molecule design. arXiv preprint arXiv:2203.14500 .

Emerson, R. O., et al. 2019. Immunosequencing identifies signatures of cytomegalovirus exposure history and HLAmediated effects on the T cell repertoire. Nat Genet , 5: 659665.

Fromer, J. C.; and Coley, C. W. 2023. Computer-aided multiobjective optimization in small molecule discovery. Patterns , 4(2).

Gao, Y.; Meyer, C. M.; and Gurevych, I. 2020. Preferencebased interactive multi-document summarisation. Information Retrieval Journal , 23(6): 555-585.

Gao, Yicheng, et al. 2023. Pan-Peptide Meta Learning for Tcell receptor-antigen binding recognition. Nature Machine Intelligence , 5: 337-339.

Hochreiter, Sepp, and J¨ urgen Schmidhuber. 1997. Long Short-Term Memory. Neural Computation , 9(8): 17351780.

Isacchini, G., et al. 2021. Deep generative selection models of T and B cell receptor repertoires with soNNia. Proceedings of the National Academy of Sciences , 118(14): e2023141118.

Jiang, Y., and S. C. Li. 2023. Deep autoregressive generative models capture the intrinsics embedded in T-cell receptor repertoires. Brief Bioinform , 2.

Kreutzer, J.; Riezler, S.; and Lawrence, C. 2020. Offline reinforcement learning from human feedback in real-world sequence-to-sequence tasks. arXiv preprint arXiv:2011.02511 .

Luukkonen, S.; van den Maagdenberg, H. W.; Emmerich, M. T.; and van Westen, G. J. 2023. Artificial intelligence in multi-objective drug design. Current Opinion in Structural Biology , 79: 102537.

O'Shea, K.; and Nash, R. 2015. An Introduction to Convolutional Neural Networks. arXiv:1511.08458.

Ouyang, L.; Wu, J.; Jiang, X.; Almeida, D.; Wainwright, C.; Mishkin, P.; Zhang, C.; Agarwal, S.; Slama, K.; Ray, A.; et al. 2022. Training language models to follow instructions with human feedback. Advances in neural information processing systems , 35: 27730-27744.

Radford, Alec, et al. 2018. Improving Language Understanding by Generative Pre-Training.

Radford, Alec, et al. 2019. Language Models are Unsupervised Multitask Learners.

Schulman, John, et al. 2017. Proximal Policy Optimization Algorithms. arXiv e-prints , arXiv:1707.06347.

Seay, H. R., et al. 2016. Tissue distribution and clonal diversity of the T and B cell repertoire in type 1 diabetes. JCI insight , 1(20): e88242.

Shi, Z.; Chen, X.; Qiu, X.; and Huang, X. 2018. Toward diverse text generation with inverse reinforcement learning. arXiv preprint arXiv:1804.11258 .

Shugay, M., et al. 2018. VDJdb: a curated database of T-cell receptor sequences with known antigen specificity. Nucleic acids research , 46(D1): D419-D427.

Singh, N. K., et al. 2017. Emerging Concepts in TCR Specificity: Rationalizing and (Maybe) Predicting Outcomes. The Journal of Immunology , 199(7): 2203-2213.

Souchleris, K.; Sidiropoulos, G. K.; and Papakostas, G. A. 2023. Reinforcement Learning in Game Industry-Review, Prospects and Challenges. Applied Sciences , 13(4).

Tang, B.; Ewalt, J.; and Ng, H.-L. 2021. Generative AI models for drug discovery. In Biophysical and Computational Tools in Drug Discovery , 221-243. Springer.

van der Merwe, P. A., and O. Dushek. 2011. Mechanisms for T cell receptor triggering. Nat Rev Immunol , 11: 47-55.

Vaswani, Ashish, et al. 2017. Attention Is All You Need. arXiv e-prints , arXiv:1706.03762.

Vita, R.; Mahajan, S.; Overton, J. A.; Dhanda, S. K.; Martini, S.; Cantrell, J. R.; Wheeler, D. K.; Sette, A.; and Peters, B. 2018. The Immune Epitope Database (IEDB): 2018 update. Nucleic Acids Research , 47(D1): D339-D343.

Zhang, T.; and Mo, H. 2021. Reinforcement learning for robot research: A comprehensive review and open issues. International Journal of Advanced Robotic Systems , 18(3): 17298814211007305.
Yicheng Lin Dandan Zhang Yun Liu
TCR-GPT: Integrating Autoregressive Model and Reinforcement Learning for T-Cell Receptor Repertoires Generation
T-cell receptors (TCRs) play a crucial role in the immune system by
recognizing and binding to specific antigens presented by infected or cancerous
cells. Understanding the sequence patterns of TCRs is essential for developing
targeted immune therapies and designing effective vaccines. Language models,
such as auto-regressive transformers, offer a powerful solution to this problem
by learning the probability distributions of TCR repertoires, enabling the
generation of new TCR sequences that inherit the underlying patterns of the
repertoire. We introduce TCR-GPT, a probabilistic model built on a decoder-only
transformer architecture, designed to uncover and replicate sequence patterns
in TCR repertoires. TCR-GPT demonstrates an accuracy of 0.953 in inferring
sequence probability distributions measured by Pearson correlation coefficient.
Furthermore, by leveraging Reinforcement Learning(RL), we adapted the
distribution of TCR sequences to generate TCRs capable of recognizing specific
peptides, offering significant potential for advancing targeted immune
therapies and vaccine development. With the efficacy of RL, fine-tuned
pretrained TCR-GPT models demonstrated the ability to produce TCR repertoires
likely to bind specific peptides, illustrating RL's efficiency in enhancing the
model's adaptability to the probability distributions of biologically relevant
TCR sequences.