Generative modeling for protein engineering is key to solving fundamental problems in synthetic biology, medicine, and material science. Machine learning has enabled us to generate useful protein sequences on a variety of scales. Generative models are machine learning methods which seek to model the distribution underlying the data, allowing for the generation of novel samples with similar properties to those on which the model was trained. Generative models of proteins can learn biologically meaningful representations helpful for a variety of downstream tasks. Furthermore, they can learn to generate protein sequences that have not been observed before and to assign higher probability to protein sequences that satisfy desired criteria. In this package, common deep generative models for protein sequences, such as variational autoencoder (VAE), generative adversarial networks (GAN), and autoregressive models are available. In the VAE and GAN, the Word2vec is used for embedding. The transformer encoder is applied to protein sequences for the autoregressive model.
The first step in molecular machine learning is to convert the molecular data into a numerical format suitable for the machine learning models. As an example of a raw representation is the sparse or one-hot encoding. Here, each amino acid is encoded as a vector, where a bit is set according to an index using the known amino acids. The naive way of representing a word in vector form is one hot representation but it is a very ineffective way for representing a huge corpus. In a more effective way, we need some semantic similarities to nearby points, thus creating the representation bring beneficial information about the word actual meaning, called word embedding models. In natural language processing, often large, one-hot encoded vectors are transformed into smaller dimension vectors, by finding word relations based on proximity or positions of similar words using the contexts of nearby neighbors. The Word2vec is one of the most common word embedding models that gives low-dimensional dense vector (word embedding) of the term (words and phrases). The Word2vec has also been applied to amino acids as a basis for traditional machine learning methods.
The generative adversarial network (GAN) is able to mimic any distribution of data in any domain containing images, music, speech, and prose. The GAN is an example of a network that use unsupervised learning to train two models in parallel. The network is forced to efficiently represent the training data, making it more effective at generating data similar to the training data. The GAN is made up of a discriminator and a generator that compete in a two-player minimax game. The generator generates a simulated example given as its input from a specified distribution. The objective of the generator is to produce an output that is so close to real that it confuses the discriminator in being able to differentiate the fake data from the real data. Both the generated examples and authentic ones are fed to the discriminator network, whose job is to distinguish between the fake and the real data. Generative adversarial nets can be extended to a conditional model if both the generator and discriminator are conditioned on some extra information, such as class labels or data from other views. The conditional GAN (CGAN) is based on vanilla GAN with additional conditional input to generator and discriminator. This extracts features based on the modelling of the conditional input. The auxiliary classifier GAN (ACGAN) is an extension of CGAN that adds conditional input only to the generator.
The autoencoder is the unsupervised neural network approach to learn how to encode data efficiently in a latent space. In the autoencoder, an encoder maps data from the input space to the latent space and a decoder is used to reconstruct the input data from the encoded latent data. The variational autoencoder (VAE) is a class of autoencoder where the encoder module is used to learn the parameter of a distribution and the decoder is used to generate examples from samples drawn from the learned distribution. The VAE does not allow us to constrain the generated sample to have a particular characteristic, but one may want to draw samples with the desired feature. A question then arises on how to endow the model to create targeted samples rather than completely random ones. The conditional variational autoencoder (CAVE) is designed to generate desired samples by including additional conditioning information.
Language models learn the syntactic order of a language from a given set of examples as probability values to predict a sequence of words. A language model is an indispensable ingredient in many advanced natural language processing (NLP) tasks such as text summarization, machine translation, and language generation. The language modeling is a typical self-supervised objective, for it does not require any labels. Language models developed for NLP tasks have evolved from statistical language models to neural language models. Approaches such as n-gram and hidden Markov models have become the primary ingredient in developing statistical language models. In contrast, various deep learning neural networks build neural language models. In the autoregressive (AR) language modeling, models are tasked with generating subsequent tokens based on previously generated tokens. Thus the autoregressive generative model predicts the next amino acid in a protein given the amino acid sequence up to that point. The autoregressive model generates proteins one amino acid at a time. For one step of generation, it takes a context sequence of amino acids as input and outputs a probability distribution over amino acids. We sample from that distribution and then update the context sequence with the sampled amino acid. This process repeats until a protein of desired length has been generated.
The Transformer architecture demonstrates impressive text generation capabilities. This perspective is adapted to protein engineering by training the autoregressive language model with the Transformer encoder on amino acid sequences. Compared to conventional sequential models such as RNN, the Transformer is a new architecture that is more effective in modeling long-term dependence in temporal sequences, where all tokens will be equally considered during the attention operation. And it is more efficient in training while eliminating sequential dependencies from previous tokens. The Transformer models can generally overcome the inherent limitations of classic neural network architectures. For example, these models overcome the problem of speed inherent in RNN, LSTM, or GRU, which require sequential operations that are slow in nature. They can also overcome the long-term dependencies problem of CNN, which can never accurately handle long-range dependences in the text corpus. Unlike RNN, the Transformer cannot consider the order of the input data, by using not only tokens but also positions for embedding. Since the Transformer has a very powerful ability to model sequential data, it becomes the most popular backbone of NLP applications. The Transformer architecture is a nonrecurrent architecture with a series of attention-based blocks. Each block is composed of a multi-head attention layer and a position-wise feedforward layer with an add and normalize layer in between. These layers process input sequences simultaneously, in parallel, independently of sequential order.
The sequences of the PTEN are used to train the GAN. The input sequences must be aligned to have the same length. To train the model, we can use the function “fit_GAN” with aligned sequence data. To generate sequences, we can use the function “gen_GAN” with the trained model. It is expected that the model can rapidly generate highly diverse novel functional proteins within the allowed biological constraints of the sequence space. Note that the same dataset is used for training and validation here.
if (keras::is_keras_available() & reticulate::py_available()) {
library(GenProSeq)
data("example_PTEN")
# model parameters
length_seq <- 403
embedding_dim <- 8
latent_dim <- 4
epochs <- 20
batch_size <- 64
# GAN
GAN_result <- fit_GAN(prot_seq = example_PTEN,
length_seq = length_seq,
embedding_dim = embedding_dim,
latent_dim = latent_dim,
intermediate_generator_layers = list(
layer_dense(units = 16),
layer_dense(units = 128)),
intermediate_discriminator_layers = list(
layer_dense(units = 128, activation = "relu"),
layer_dense(units = 16, activation = "relu")),
prot_seq_val = example_PTEN,
epochs = epochs,
batch_size = batch_size)
}
## Loading required package: keras
## Loading required package: mclust
## Package 'mclust' version 6.1.1
## Type 'citation("mclust")' for citing this R package in publications.
## pre-processing...
## at least one of protein sequences may not be valid
## at least one of protein sequences may not be valid
## training...
## Epoch 1/20
## 2/2 - 0s - 346ms/epoch - 173ms/step
## 1/5 [=====>........................] - ETA: 5s2/2 - 0s - 24ms/epoch - 12ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 23ms/epoch - 12ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 23ms/epoch - 12ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 2s 125ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 0.645973
## generator (test) : loss 0.544711
## discriminator (train) : loss 0.498502
## discriminator (test) : loss 0.454473
##
## Epoch 2/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 123ms/step
## 11/11 - 0s - 35ms/epoch - 3ms/step
## generator (train) : loss 0.632747
## generator (test) : loss 0.578395
## discriminator (train) : loss 0.463927
## discriminator (test) : loss 0.423328
##
## Epoch 3/20
## 2/2 - 0s - 21ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 24ms/epoch - 12ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 23ms/epoch - 12ms/step
## 5/5 [==============================] - 1s 121ms/step
## 11/11 - 0s - 35ms/epoch - 3ms/step
## generator (train) : loss 0.730671
## generator (test) : loss 0.680259
## discriminator (train) : loss 0.400762
## discriminator (test) : loss 0.365411
##
## Epoch 4/20
## 2/2 - 0s - 23ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 115ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 0.944344
## generator (test) : loss 0.858590
## discriminator (train) : loss 0.328666
## discriminator (test) : loss 0.278352
##
## Epoch 5/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 127ms/step
## 11/11 - 0s - 32ms/epoch - 3ms/step
## generator (train) : loss 1.193401
## generator (test) : loss 1.088610
## discriminator (train) : loss 0.266882
## discriminator (test) : loss 0.228691
##
## Epoch 6/20
## 2/2 - 0s - 25ms/epoch - 12ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 126ms/step
## 11/11 - 0s - 39ms/epoch - 4ms/step
## generator (train) : loss 1.500216
## generator (test) : loss 1.393122
## discriminator (train) : loss 0.193705
## discriminator (test) : loss 0.184182
##
## Epoch 7/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 119ms/step
## 11/11 - 0s - 32ms/epoch - 3ms/step
## generator (train) : loss 1.667250
## generator (test) : loss 1.346127
## discriminator (train) : loss 0.168581
## discriminator (test) : loss 0.176267
##
## Epoch 8/20
## 2/2 - 0s - 21ms/epoch - 10ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 1s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 174ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 1.649596
## generator (test) : loss 1.311988
## discriminator (train) : loss 0.179195
## discriminator (test) : loss 0.170501
##
## Epoch 9/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 10ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 116ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 1.949501
## generator (test) : loss 1.815868
## discriminator (train) : loss 0.145829
## discriminator (test) : loss 0.106434
##
## Epoch 10/20
## 2/2 - 0s - 21ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 24ms/epoch - 12ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 120ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 2.387866
## generator (test) : loss 2.016907
## discriminator (train) : loss 0.100439
## discriminator (test) : loss 0.090028
##
## Epoch 11/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 21ms/epoch - 10ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 118ms/step
## 11/11 - 0s - 32ms/epoch - 3ms/step
## generator (train) : loss 2.699519
## generator (test) : loss 2.300249
## discriminator (train) : loss 0.079866
## discriminator (test) : loss 0.063679
##
## Epoch 12/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 23ms/epoch - 12ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 21ms/epoch - 10ms/step
## 5/5 [==============================] - 1s 118ms/step
## 11/11 - 0s - 32ms/epoch - 3ms/step
## generator (train) : loss 2.802233
## generator (test) : loss 2.268305
## discriminator (train) : loss 0.062274
## discriminator (test) : loss 0.066159
##
## Epoch 13/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 21ms/epoch - 10ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 116ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 2.616287
## generator (test) : loss 1.926414
## discriminator (train) : loss 0.073509
## discriminator (test) : loss 0.087814
##
## Epoch 14/20
## 2/2 - 0s - 21ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 21ms/epoch - 10ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 116ms/step
## 11/11 - 0s - 34ms/epoch - 3ms/step
## generator (train) : loss 2.374032
## generator (test) : loss 1.722667
## discriminator (train) : loss 0.100721
## discriminator (test) : loss 0.113332
##
## Epoch 15/20
## 2/2 - 0s - 21ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 25ms/epoch - 12ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 26ms/epoch - 13ms/step
## 5/5 [==============================] - 1s 128ms/step
## 11/11 - 0s - 36ms/epoch - 3ms/step
## generator (train) : loss 2.581904
## generator (test) : loss 2.120653
## discriminator (train) : loss 0.103841
## discriminator (test) : loss 0.070375
##
## Epoch 16/20
## 2/2 - 0s - 23ms/epoch - 12ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 24ms/epoch - 12ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 24ms/epoch - 12ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 24ms/epoch - 12ms/step
## 5/5 [==============================] - 1s 132ms/step
## 11/11 - 0s - 36ms/epoch - 3ms/step
## generator (train) : loss 3.510905
## generator (test) : loss 2.797484
## discriminator (train) : loss 0.051757
## discriminator (test) : loss 0.034445
##
## Epoch 17/20
## 2/2 - 0s - 21ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 23ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 120ms/step
## 11/11 - 0s - 31ms/epoch - 3ms/step
## generator (train) : loss 3.880668
## generator (test) : loss 2.228900
## discriminator (train) : loss 0.046128
## discriminator (test) : loss 0.078084
##
## Epoch 18/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 114ms/step
## 11/11 - 0s - 32ms/epoch - 3ms/step
## generator (train) : loss 3.523727
## generator (test) : loss 2.222724
## discriminator (train) : loss 0.095687
## discriminator (test) : loss 0.084016
##
## Epoch 19/20
## 2/2 - 0s - 22ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 21ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 120ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 3.851632
## generator (test) : loss 3.046238
## discriminator (train) : loss 0.062079
## discriminator (test) : loss 0.031998
##
## Epoch 20/20
## 2/2 - 0s - 21ms/epoch - 11ms/step
## 1/5 [=====>........................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 2/5 [===========>..................] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 3/5 [=================>............] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 4/5 [=======================>......] - ETA: 0s2/2 - 0s - 22ms/epoch - 11ms/step
## 5/5 [==============================] - 1s 118ms/step
## 11/11 - 0s - 33ms/epoch - 3ms/step
## generator (train) : loss 4.559467
## generator (test) : loss 4.125003
## discriminator (train) : loss 0.020309
## discriminator (test) : loss 0.010601
The model architecture of the generator is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
ttgsea::plot_model(GAN_result$generator)
}
The model architecture of the discriminator is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
ttgsea::plot_model(GAN_result$discriminator)
}
In a graphical manner, a sequence logo shows the probability of occurrence for each symbol at specific positions. Thus, the height of a symbol indicates the relative frequency of the symbol at that position. The sequence logo of the first 20 amino acids of the generated protein sequences is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
set.seed(1)
gen_prot_GAN <- gen_GAN(GAN_result, num_seq = 100)
if (require(ggseqlogo)) {
ggseqlogo::ggseqlogo(substr(gen_prot_GAN$gen_seq, 1, 20))
}
}
## generating...
## 4/4 - 0s - 74ms/epoch - 19ms/step
## post-processing...
## Loading required package: ggseqlogo
The sequence logo of the first 20 amino acids of the real protein sequences is shown below. Here, it is assumed that the conserved position is the first amino acid. The sequence logo is a visualization approach to graphically represent the sequence conservation.
if (keras::is_keras_available() & reticulate::py_available()) {
if (require(ggseqlogo)) {
ggseqlogo::ggseqlogo(substr(example_PTEN, 1, 20))
}
}
Consider the aligned sequences of the luxA for traing the CVAE with labels. Suppose that the label is the third amino acid of each sequence. Thus there are two class labels. Using the function “fit_VAE”, we build an encoder model that takes a protein sequence and projects it on the latent space and a decoder model that goes from the latent space back to the amino acid representation. And then, the function “gen_VAE” generates sequences with the desired labels. Note that the same dataset is used for training and validation.
if (keras::is_keras_available() & reticulate::py_available()) {
library(GenProSeq)
data("example_luxA")
label <- substr(example_luxA, 3, 3)
# model parameters
length_seq <- 360
embedding_dim <- 8
batch_size <- 128
epochs <- 20
# CVAE
VAE_result <- fit_VAE(prot_seq = example_luxA,
label = label,
length_seq = length_seq,
embedding_dim = embedding_dim,
embedding_args = list(iter = 20),
intermediate_encoder_layers = list(layer_dense(units = 128),
layer_dense(units = 16)),
intermediate_decoder_layers = list(layer_dense(units = 16),
layer_dense(units = 128)),
prot_seq_val = example_luxA,
label_val = label,
epochs = epochs,
batch_size = batch_size,
use_generator = FALSE,
optimizer = keras::optimizer_adam(clipnorm = 0.1),
callbacks = keras::callback_early_stopping(
monitor = "val_loss",
patience = 10,
restore_best_weights = TRUE))
}
## pre-processing...
## training...
## Train on 2283 samples, validate on 2283 samples
## Epoch 1/20
## 2283/2283 - 1s - loss: 4741925.4315 - val_loss: 1430.0370 - 794ms/epoch - 348us/sample
## Epoch 2/20
## 2283/2283 - 0s - loss: 1248.4903 - val_loss: 1090.2520 - 340ms/epoch - 149us/sample
## Epoch 3/20
## 2283/2283 - 0s - loss: 1114.4722 - val_loss: 1150.1742 - 296ms/epoch - 129us/sample
## Epoch 4/20
## 2283/2283 - 0s - loss: 1111.3191 - val_loss: 1291.5392 - 270ms/epoch - 118us/sample
## Epoch 5/20
## 2283/2283 - 0s - loss: 1181.7441 - val_loss: 1116.6480 - 288ms/epoch - 126us/sample
## Epoch 6/20
## 2283/2283 - 0s - loss: 1088.3500 - val_loss: 1117.3572 - 269ms/epoch - 118us/sample
## Epoch 7/20
## 2283/2283 - 0s - loss: 1048.8433 - val_loss: 1043.3196 - 286ms/epoch - 125us/sample
## Epoch 8/20
## 2283/2283 - 0s - loss: 1064.7819 - val_loss: 3084976.9964 - 290ms/epoch - 127us/sample
## Epoch 9/20
## 2283/2283 - 0s - loss: 1012.0275 - val_loss: 974.2669 - 266ms/epoch - 116us/sample
## Epoch 10/20
## 2283/2283 - 0s - loss: 969.9544 - val_loss: 1015.4909 - 260ms/epoch - 114us/sample
## Epoch 11/20
## 2283/2283 - 0s - loss: 961.5259 - val_loss: 970.1939 - 298ms/epoch - 131us/sample
## Epoch 12/20
## 2283/2283 - 0s - loss: 1047.8652 - val_loss: 3288.5806 - 296ms/epoch - 129us/sample
## Epoch 13/20
## 2283/2283 - 0s - loss: 996.4739 - val_loss: 953.7602 - 280ms/epoch - 123us/sample
## Epoch 14/20
## 2283/2283 - 0s - loss: 1011.6923 - val_loss: 991.2008 - 228ms/epoch - 100us/sample
## Epoch 15/20
## 2283/2283 - 0s - loss: 959.4751 - val_loss: 926.4635 - 262ms/epoch - 115us/sample
## Epoch 16/20
## 2283/2283 - 0s - loss: 924.0145 - val_loss: 902.1287 - 254ms/epoch - 111us/sample
## Epoch 17/20
## 2283/2283 - 0s - loss: 910.4960 - val_loss: 911.9224 - 255ms/epoch - 112us/sample
## Epoch 18/20
## 2283/2283 - 0s - loss: 1245.4503 - val_loss: 1086.2471 - 265ms/epoch - 116us/sample
## Epoch 19/20
## 2283/2283 - 0s - loss: 985.5094 - val_loss: 1070.1158 - 283ms/epoch - 124us/sample
## Epoch 20/20
## 2283/2283 - 0s - loss: 1538.7535 - val_loss: 933.0365 - 297ms/epoch - 130us/sample
The plot for model architecture of the CVAE is drawn below.
if (keras::is_keras_available() & reticulate::py_available()) {
VAExprs::plot_vae(VAE_result$model)
}
The sequence logo of the first 20 amino acids of the generated protein sequences with the label “I” is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
set.seed(1)
gen_prot_VAE <- gen_VAE(VAE_result, label = rep("I", 100), num_seq = 100)
if (require(ggseqlogo)) {
ggseqlogo::ggseqlogo(substr(gen_prot_VAE$gen_seq, 1, 20))
}
}
## generating...
## post-processing...
The sequence logo of the first 20 amino acids of the generated protein sequences with the label “L” is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
gen_prot_VAE <- gen_VAE(VAE_result, label = rep("L", 100), num_seq = 100)
if (require(ggseqlogo)) {
ggseqlogo::ggseqlogo(substr(gen_prot_VAE$gen_seq, 1, 20))
}
}
## generating...
## post-processing...
The sequence logo of the first 20 amino acids of the real protein sequences is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
if (require(ggseqlogo)) {
ggseqlogo::ggseqlogo(substr(example_luxA, 1, 20))
}
}
The SARS coronavirus 3C-like Protease is used to train the autoregressive language model with the Transformer. The same dataset is used for training and validation.
if (keras::is_keras_available() & reticulate::py_available()) {
library(GenProSeq)
prot_seq <- DeepPINCS::SARS_CoV2_3CL_Protease
# model parameters
length_seq <- 10
embedding_dim <- 16
num_heads <- 2
ff_dim <- 16
num_transformer_blocks <- 2
batch_size <- 32
epochs <- 100
# ART
ART_result <- fit_ART(prot_seq = prot_seq,
length_seq = length_seq,
embedding_dim = embedding_dim,
num_heads = num_heads,
ff_dim = ff_dim,
num_transformer_blocks = num_transformer_blocks,
layers = list(layer_dropout(rate = 0.1),
layer_dense(units = 32, activation = "relu"),
layer_dropout(rate = 0.1)),
prot_seq_val = prot_seq,
epochs = epochs,
batch_size = batch_size,
use_generator = FALSE,
callbacks = callback_early_stopping(
monitor = "val_loss",
patience = 50,
restore_best_weights = TRUE))
}
## pre-processing...
## training...
## Train on 296 samples, validate on 296 samples
## Epoch 1/100
## 296/296 - 1s - loss: 3.0322 - accuracy: 0.0541 - val_loss: 2.9696 - val_accuracy: 0.0811 - 1s/epoch - 5ms/sample
## Epoch 2/100
## 296/296 - 0s - loss: 2.9675 - accuracy: 0.0507 - val_loss: 2.9493 - val_accuracy: 0.0541 - 187ms/epoch - 633us/sample
## Epoch 3/100
## 296/296 - 0s - loss: 2.9533 - accuracy: 0.0777 - val_loss: 2.9296 - val_accuracy: 0.1115 - 167ms/epoch - 565us/sample
## Epoch 4/100
## 296/296 - 0s - loss: 2.9371 - accuracy: 0.1351 - val_loss: 2.9128 - val_accuracy: 0.1182 - 169ms/epoch - 570us/sample
## Epoch 5/100
## 296/296 - 0s - loss: 2.9147 - accuracy: 0.1216 - val_loss: 2.8920 - val_accuracy: 0.1182 - 175ms/epoch - 590us/sample
## Epoch 6/100
## 296/296 - 0s - loss: 2.9190 - accuracy: 0.0980 - val_loss: 2.8734 - val_accuracy: 0.1250 - 177ms/epoch - 598us/sample
## Epoch 7/100
## 296/296 - 0s - loss: 2.8924 - accuracy: 0.1250 - val_loss: 2.8528 - val_accuracy: 0.1453 - 178ms/epoch - 601us/sample
## Epoch 8/100
## 296/296 - 0s - loss: 2.8726 - accuracy: 0.1115 - val_loss: 2.8323 - val_accuracy: 0.1453 - 152ms/epoch - 513us/sample
## Epoch 9/100
## 296/296 - 0s - loss: 2.8646 - accuracy: 0.1318 - val_loss: 2.8065 - val_accuracy: 0.1419 - 117ms/epoch - 395us/sample
## Epoch 10/100
## 296/296 - 0s - loss: 2.8400 - accuracy: 0.1250 - val_loss: 2.7958 - val_accuracy: 0.1554 - 153ms/epoch - 516us/sample
## Epoch 11/100
## 296/296 - 0s - loss: 2.8069 - accuracy: 0.1419 - val_loss: 2.7559 - val_accuracy: 0.1554 - 158ms/epoch - 532us/sample
## Epoch 12/100
## 296/296 - 0s - loss: 2.8010 - accuracy: 0.1216 - val_loss: 2.7359 - val_accuracy: 0.1655 - 112ms/epoch - 378us/sample
## Epoch 13/100
## 296/296 - 0s - loss: 2.7718 - accuracy: 0.1588 - val_loss: 2.7196 - val_accuracy: 0.1757 - 175ms/epoch - 590us/sample
## Epoch 14/100
## 296/296 - 0s - loss: 2.7737 - accuracy: 0.1622 - val_loss: 2.6886 - val_accuracy: 0.1723 - 174ms/epoch - 589us/sample
## Epoch 15/100
## 296/296 - 0s - loss: 2.7674 - accuracy: 0.1385 - val_loss: 2.6646 - val_accuracy: 0.1926 - 164ms/epoch - 555us/sample
## Epoch 16/100
## 296/296 - 0s - loss: 2.7109 - accuracy: 0.2061 - val_loss: 2.6433 - val_accuracy: 0.1959 - 150ms/epoch - 507us/sample
## Epoch 17/100
## 296/296 - 0s - loss: 2.7076 - accuracy: 0.1655 - val_loss: 2.6197 - val_accuracy: 0.1858 - 112ms/epoch - 380us/sample
## Epoch 18/100
## 296/296 - 0s - loss: 2.6729 - accuracy: 0.1824 - val_loss: 2.5911 - val_accuracy: 0.1858 - 93ms/epoch - 316us/sample
## Epoch 19/100
## 296/296 - 0s - loss: 2.6907 - accuracy: 0.1554 - val_loss: 2.6063 - val_accuracy: 0.1959 - 95ms/epoch - 320us/sample
## Epoch 20/100
## 296/296 - 0s - loss: 2.6881 - accuracy: 0.1723 - val_loss: 2.5925 - val_accuracy: 0.1858 - 87ms/epoch - 293us/sample
## Epoch 21/100
## 296/296 - 0s - loss: 2.6308 - accuracy: 0.1757 - val_loss: 2.5325 - val_accuracy: 0.2297 - 89ms/epoch - 302us/sample
## Epoch 22/100
## 296/296 - 0s - loss: 2.5993 - accuracy: 0.2264 - val_loss: 2.5157 - val_accuracy: 0.2230 - 143ms/epoch - 483us/sample
## Epoch 23/100
## 296/296 - 0s - loss: 2.5839 - accuracy: 0.2128 - val_loss: 2.4695 - val_accuracy: 0.2230 - 156ms/epoch - 528us/sample
## Epoch 24/100
## 296/296 - 0s - loss: 2.5574 - accuracy: 0.1757 - val_loss: 2.4443 - val_accuracy: 0.2297 - 155ms/epoch - 523us/sample
## Epoch 25/100
## 296/296 - 0s - loss: 2.5211 - accuracy: 0.2297 - val_loss: 2.4773 - val_accuracy: 0.2432 - 136ms/epoch - 458us/sample
## Epoch 26/100
## 296/296 - 0s - loss: 2.5253 - accuracy: 0.2331 - val_loss: 2.4285 - val_accuracy: 0.2027 - 129ms/epoch - 437us/sample
## Epoch 27/100
## 296/296 - 0s - loss: 2.5060 - accuracy: 0.2061 - val_loss: 2.4130 - val_accuracy: 0.2432 - 155ms/epoch - 523us/sample
## Epoch 28/100
## 296/296 - 0s - loss: 2.4801 - accuracy: 0.2162 - val_loss: 2.3483 - val_accuracy: 0.2432 - 124ms/epoch - 420us/sample
## Epoch 29/100
## 296/296 - 0s - loss: 2.4633 - accuracy: 0.2365 - val_loss: 2.3546 - val_accuracy: 0.2432 - 100ms/epoch - 339us/sample
## Epoch 30/100
## 296/296 - 0s - loss: 2.4737 - accuracy: 0.2230 - val_loss: 2.3270 - val_accuracy: 0.2669 - 149ms/epoch - 504us/sample
## Epoch 31/100
## 296/296 - 0s - loss: 2.4345 - accuracy: 0.2331 - val_loss: 2.2783 - val_accuracy: 0.2770 - 176ms/epoch - 594us/sample
## Epoch 32/100
## 296/296 - 0s - loss: 2.3977 - accuracy: 0.2297 - val_loss: 2.2494 - val_accuracy: 0.2939 - 171ms/epoch - 576us/sample
## Epoch 33/100
## 296/296 - 0s - loss: 2.3676 - accuracy: 0.2736 - val_loss: 2.2275 - val_accuracy: 0.3108 - 171ms/epoch - 577us/sample
## Epoch 34/100
## 296/296 - 0s - loss: 2.3776 - accuracy: 0.2297 - val_loss: 2.1823 - val_accuracy: 0.3446 - 172ms/epoch - 582us/sample
## Epoch 35/100
## 296/296 - 0s - loss: 2.3165 - accuracy: 0.2399 - val_loss: 2.1998 - val_accuracy: 0.3209 - 145ms/epoch - 491us/sample
## Epoch 36/100
## 296/296 - 0s - loss: 2.3676 - accuracy: 0.2703 - val_loss: 2.1714 - val_accuracy: 0.3514 - 160ms/epoch - 541us/sample
## Epoch 37/100
## 296/296 - 0s - loss: 2.3457 - accuracy: 0.2399 - val_loss: 2.1641 - val_accuracy: 0.3514 - 176ms/epoch - 593us/sample
## Epoch 38/100
## 296/296 - 0s - loss: 2.2610 - accuracy: 0.2973 - val_loss: 2.1312 - val_accuracy: 0.3480 - 169ms/epoch - 571us/sample
## Epoch 39/100
## 296/296 - 0s - loss: 2.2754 - accuracy: 0.3209 - val_loss: 2.0868 - val_accuracy: 0.3919 - 169ms/epoch - 572us/sample
## Epoch 40/100
## 296/296 - 0s - loss: 2.2505 - accuracy: 0.2905 - val_loss: 2.0759 - val_accuracy: 0.3682 - 172ms/epoch - 581us/sample
## Epoch 41/100
## 296/296 - 0s - loss: 2.2473 - accuracy: 0.2872 - val_loss: 2.0482 - val_accuracy: 0.3750 - 174ms/epoch - 587us/sample
## Epoch 42/100
## 296/296 - 0s - loss: 2.1957 - accuracy: 0.2872 - val_loss: 2.0231 - val_accuracy: 0.3851 - 172ms/epoch - 582us/sample
## Epoch 43/100
## 296/296 - 0s - loss: 2.1672 - accuracy: 0.3007 - val_loss: 1.9897 - val_accuracy: 0.4020 - 134ms/epoch - 452us/sample
## Epoch 44/100
## 296/296 - 0s - loss: 2.1662 - accuracy: 0.3007 - val_loss: 1.9751 - val_accuracy: 0.3885 - 161ms/epoch - 544us/sample
## Epoch 45/100
## 296/296 - 0s - loss: 2.2032 - accuracy: 0.3074 - val_loss: 1.9964 - val_accuracy: 0.3818 - 140ms/epoch - 473us/sample
## Epoch 46/100
## 296/296 - 0s - loss: 2.1339 - accuracy: 0.3074 - val_loss: 1.9163 - val_accuracy: 0.4088 - 141ms/epoch - 475us/sample
## Epoch 47/100
## 296/296 - 0s - loss: 2.1033 - accuracy: 0.3446 - val_loss: 1.8866 - val_accuracy: 0.4358 - 165ms/epoch - 557us/sample
## Epoch 48/100
## 296/296 - 0s - loss: 2.1026 - accuracy: 0.3649 - val_loss: 1.8905 - val_accuracy: 0.4257 - 163ms/epoch - 550us/sample
## Epoch 49/100
## 296/296 - 0s - loss: 2.0998 - accuracy: 0.3176 - val_loss: 1.8779 - val_accuracy: 0.4223 - 170ms/epoch - 573us/sample
## Epoch 50/100
## 296/296 - 0s - loss: 2.0679 - accuracy: 0.3345 - val_loss: 1.8682 - val_accuracy: 0.4257 - 171ms/epoch - 579us/sample
## Epoch 51/100
## 296/296 - 0s - loss: 2.0703 - accuracy: 0.3446 - val_loss: 1.8380 - val_accuracy: 0.4291 - 171ms/epoch - 577us/sample
## Epoch 52/100
## 296/296 - 0s - loss: 2.0678 - accuracy: 0.3412 - val_loss: 1.8087 - val_accuracy: 0.4426 - 174ms/epoch - 589us/sample
## Epoch 53/100
## 296/296 - 0s - loss: 2.0161 - accuracy: 0.3851 - val_loss: 1.8263 - val_accuracy: 0.4459 - 169ms/epoch - 572us/sample
## Epoch 54/100
## 296/296 - 0s - loss: 1.9819 - accuracy: 0.3446 - val_loss: 1.7526 - val_accuracy: 0.4730 - 174ms/epoch - 586us/sample
## Epoch 55/100
## 296/296 - 0s - loss: 1.9723 - accuracy: 0.3480 - val_loss: 1.7488 - val_accuracy: 0.4358 - 174ms/epoch - 587us/sample
## Epoch 56/100
## 296/296 - 0s - loss: 1.9970 - accuracy: 0.3682 - val_loss: 1.7632 - val_accuracy: 0.4561 - 167ms/epoch - 565us/sample
## Epoch 57/100
## 296/296 - 0s - loss: 1.9586 - accuracy: 0.3851 - val_loss: 1.7131 - val_accuracy: 0.4797 - 177ms/epoch - 598us/sample
## Epoch 58/100
## 296/296 - 0s - loss: 1.9322 - accuracy: 0.3378 - val_loss: 1.6978 - val_accuracy: 0.4966 - 163ms/epoch - 552us/sample
## Epoch 59/100
## 296/296 - 0s - loss: 1.9357 - accuracy: 0.3986 - val_loss: 1.6470 - val_accuracy: 0.5101 - 232ms/epoch - 785us/sample
## Epoch 60/100
## 296/296 - 0s - loss: 1.8576 - accuracy: 0.4122 - val_loss: 1.6433 - val_accuracy: 0.5236 - 162ms/epoch - 547us/sample
## Epoch 61/100
## 296/296 - 0s - loss: 1.8804 - accuracy: 0.3750 - val_loss: 1.6392 - val_accuracy: 0.4966 - 163ms/epoch - 550us/sample
## Epoch 62/100
## 296/296 - 0s - loss: 1.8683 - accuracy: 0.4122 - val_loss: 1.6187 - val_accuracy: 0.5270 - 160ms/epoch - 542us/sample
## Epoch 63/100
## 296/296 - 0s - loss: 1.8851 - accuracy: 0.3581 - val_loss: 1.5980 - val_accuracy: 0.5473 - 171ms/epoch - 579us/sample
## Epoch 64/100
## 296/296 - 0s - loss: 1.8936 - accuracy: 0.3885 - val_loss: 1.6084 - val_accuracy: 0.5203 - 160ms/epoch - 540us/sample
## Epoch 65/100
## 296/296 - 0s - loss: 1.8149 - accuracy: 0.4155 - val_loss: 1.5709 - val_accuracy: 0.5169 - 171ms/epoch - 578us/sample
## Epoch 66/100
## 296/296 - 0s - loss: 1.8083 - accuracy: 0.4223 - val_loss: 1.5482 - val_accuracy: 0.5541 - 178ms/epoch - 600us/sample
## Epoch 67/100
## 296/296 - 0s - loss: 1.7825 - accuracy: 0.4223 - val_loss: 1.5476 - val_accuracy: 0.5270 - 173ms/epoch - 585us/sample
## Epoch 68/100
## 296/296 - 0s - loss: 1.8447 - accuracy: 0.3919 - val_loss: 1.5048 - val_accuracy: 0.5541 - 169ms/epoch - 571us/sample
## Epoch 69/100
## 296/296 - 0s - loss: 1.7822 - accuracy: 0.4324 - val_loss: 1.4760 - val_accuracy: 0.5676 - 170ms/epoch - 574us/sample
## Epoch 70/100
## 296/296 - 0s - loss: 1.6775 - accuracy: 0.4561 - val_loss: 1.4569 - val_accuracy: 0.5541 - 169ms/epoch - 572us/sample
## Epoch 71/100
## 296/296 - 0s - loss: 1.6824 - accuracy: 0.4764 - val_loss: 1.4404 - val_accuracy: 0.5574 - 162ms/epoch - 547us/sample
## Epoch 72/100
## 296/296 - 0s - loss: 1.7078 - accuracy: 0.4527 - val_loss: 1.4175 - val_accuracy: 0.5642 - 159ms/epoch - 538us/sample
## Epoch 73/100
## 296/296 - 0s - loss: 1.7386 - accuracy: 0.4696 - val_loss: 1.4172 - val_accuracy: 0.5541 - 135ms/epoch - 457us/sample
## Epoch 74/100
## 296/296 - 0s - loss: 1.7279 - accuracy: 0.4155 - val_loss: 1.4106 - val_accuracy: 0.5912 - 96ms/epoch - 325us/sample
## Epoch 75/100
## 296/296 - 0s - loss: 1.6684 - accuracy: 0.4426 - val_loss: 1.3692 - val_accuracy: 0.5845 - 156ms/epoch - 527us/sample
## Epoch 76/100
## 296/296 - 0s - loss: 1.6749 - accuracy: 0.4426 - val_loss: 1.3613 - val_accuracy: 0.6115 - 162ms/epoch - 548us/sample
## Epoch 77/100
## 296/296 - 0s - loss: 1.6020 - accuracy: 0.5304 - val_loss: 1.3297 - val_accuracy: 0.6182 - 116ms/epoch - 393us/sample
## Epoch 78/100
## 296/296 - 0s - loss: 1.6333 - accuracy: 0.4966 - val_loss: 1.3493 - val_accuracy: 0.6216 - 137ms/epoch - 464us/sample
## Epoch 79/100
## 296/296 - 0s - loss: 1.6423 - accuracy: 0.4358 - val_loss: 1.3517 - val_accuracy: 0.5777 - 144ms/epoch - 485us/sample
## Epoch 80/100
## 296/296 - 0s - loss: 1.6470 - accuracy: 0.4865 - val_loss: 1.3760 - val_accuracy: 0.5777 - 159ms/epoch - 537us/sample
## Epoch 81/100
## 296/296 - 0s - loss: 1.6268 - accuracy: 0.4831 - val_loss: 1.3372 - val_accuracy: 0.6216 - 160ms/epoch - 541us/sample
## Epoch 82/100
## 296/296 - 0s - loss: 1.6268 - accuracy: 0.4797 - val_loss: 1.3260 - val_accuracy: 0.5912 - 158ms/epoch - 534us/sample
## Epoch 83/100
## 296/296 - 0s - loss: 1.5746 - accuracy: 0.4730 - val_loss: 1.2759 - val_accuracy: 0.6115 - 168ms/epoch - 567us/sample
## Epoch 84/100
## 296/296 - 0s - loss: 1.5801 - accuracy: 0.4662 - val_loss: 1.2532 - val_accuracy: 0.6115 - 174ms/epoch - 587us/sample
## Epoch 85/100
## 296/296 - 0s - loss: 1.5438 - accuracy: 0.5135 - val_loss: 1.2436 - val_accuracy: 0.5811 - 169ms/epoch - 572us/sample
## Epoch 86/100
## 296/296 - 0s - loss: 1.6255 - accuracy: 0.4527 - val_loss: 1.2455 - val_accuracy: 0.6081 - 166ms/epoch - 562us/sample
## Epoch 87/100
## 296/296 - 0s - loss: 1.5252 - accuracy: 0.5034 - val_loss: 1.2238 - val_accuracy: 0.6284 - 174ms/epoch - 587us/sample
## Epoch 88/100
## 296/296 - 0s - loss: 1.5731 - accuracy: 0.4899 - val_loss: 1.2389 - val_accuracy: 0.6216 - 159ms/epoch - 539us/sample
## Epoch 89/100
## 296/296 - 0s - loss: 1.5285 - accuracy: 0.4932 - val_loss: 1.2028 - val_accuracy: 0.6284 - 156ms/epoch - 525us/sample
## Epoch 90/100
## 296/296 - 0s - loss: 1.6081 - accuracy: 0.4899 - val_loss: 1.1900 - val_accuracy: 0.6419 - 165ms/epoch - 559us/sample
## Epoch 91/100
## 296/296 - 0s - loss: 1.4698 - accuracy: 0.5000 - val_loss: 1.1503 - val_accuracy: 0.6419 - 171ms/epoch - 578us/sample
## Epoch 92/100
## 296/296 - 0s - loss: 1.5045 - accuracy: 0.4595 - val_loss: 1.1476 - val_accuracy: 0.6757 - 173ms/epoch - 584us/sample
## Epoch 93/100
## 296/296 - 0s - loss: 1.5420 - accuracy: 0.4932 - val_loss: 1.1453 - val_accuracy: 0.6520 - 177ms/epoch - 599us/sample
## Epoch 94/100
## 296/296 - 0s - loss: 1.4603 - accuracy: 0.5304 - val_loss: 1.1499 - val_accuracy: 0.6385 - 160ms/epoch - 541us/sample
## Epoch 95/100
## 296/296 - 0s - loss: 1.4750 - accuracy: 0.5270 - val_loss: 1.1515 - val_accuracy: 0.6791 - 131ms/epoch - 443us/sample
## Epoch 96/100
## 296/296 - 0s - loss: 1.4676 - accuracy: 0.5169 - val_loss: 1.1687 - val_accuracy: 0.6318 - 148ms/epoch - 500us/sample
## Epoch 97/100
## 296/296 - 0s - loss: 1.4876 - accuracy: 0.4764 - val_loss: 1.1128 - val_accuracy: 0.6723 - 174ms/epoch - 587us/sample
## Epoch 98/100
## 296/296 - 0s - loss: 1.4652 - accuracy: 0.5068 - val_loss: 1.1020 - val_accuracy: 0.6757 - 177ms/epoch - 597us/sample
## Epoch 99/100
## 296/296 - 0s - loss: 1.4218 - accuracy: 0.5405 - val_loss: 1.0660 - val_accuracy: 0.6824 - 177ms/epoch - 598us/sample
## Epoch 100/100
## 296/296 - 0s - loss: 1.4108 - accuracy: 0.5000 - val_loss: 1.0685 - val_accuracy: 0.6926 - 176ms/epoch - 594us/sample
The model architecture is shown below.
if (keras::is_keras_available() & reticulate::py_available()) {
ttgsea::plot_model(ART_result$model)
}
The learned autoregressive model generates new sequences of proteins. After the language model generates a conditional probability distribution over vocabulary for the given input sequence, we need to decide how to choose the next word or token from the distribution. The greedy search simply selects the token with the highest probability value as its next token. Rather than just considering the highest probable word, the top b words is taken as the next word in the beam search. Here b is also called the beam size which is itself a parameter. Now to compute the second word each of these b first words is fed and top b words are obtained again. The process continues till the end. In temperature sampling, we sample the token from the modified conditional probability distribution over the vocabulary for the given temperature value. In the top-k sampling, the k most likely next tokens are filtered and their probabilities are adjusted among only those k tokens. In a similar manner, the top-p sampling is another way to exclude very low probability tokens and it finds the smallest set of tokens that have summed probability at least p.
if (keras::is_keras_available() & reticulate::py_available()) {
set.seed(1)
seed_prot <- "SGFRKMAFPS"
print(gen_ART(ART_result, seed_prot, length_AA = 20, method = "greedy"))
print(substr(prot_seq, 1, 30))
print(gen_ART(ART_result, seed_prot, length_AA = 20, method = "beam", b = 5))
print(substr(prot_seq, 1, 30))
print(gen_ART(ART_result, seed_prot, length_AA = 20, method = "temperature", t = 0.1))
print(substr(prot_seq, 1, 30))
print(gen_ART(ART_result, seed_prot, length_AA = 20, method = "top_k", k = 3))
print(substr(prot_seq, 1, 30))
print(gen_ART(ART_result, seed_prot, length_AA = 20, method = "top_p", p = 0.75))
print(substr(prot_seq, 1, 30))
}
## generating...
## [1] "SGFRKMAFPSGCGQGQNGSVSYCLCGSPGM"
## [1] "SGFRKMAFPSGKVEGCMVQVTCGTTTLNGL"
## generating...
## [1] "SGFRKMAFPSGCGQGSGSGFQGSGQLGGSG"
## [1] "SGFRKMAFPSGKVEGCMVQVTCGTTTLNGL"
## generating...
## [1] "SGFRKMAFPSGCGQGSGSGFQGSGQLGGSG"
## [1] "SGFRKMAFPSGKVEGCMVQVTCGTTTLNGL"
## generating...
## [1] "SGFRKMAFPSPGCPGCSGFGSCGSQGQGQS"
## [1] "SGFRKMAFPSGKVEGCMVQVTCGTTTLNGL"
## generating...
## [1] "SGFRKMAFPSGGFEGKNVGSCGSMQGCLMV"
## [1] "SGFRKMAFPSGKVEGCMVQVTCGTTTLNGL"
We can compute pairwise similarities between the real and generated protein sequences. The function “stringsim” vary between 0 for strings that are not similar at all, to 1 for strings that are identical. One advantage of the string similarity over the string distance function is that similarities are easier to interpret because they are normalized.
if (keras::is_keras_available() & reticulate::py_available()) {
print(stringdist::stringsim(gen_ART(ART_result, seed_prot, length_AA = 20, method = "greedy"),
substr(prot_seq, 1, 30)))
print(stringdist::stringsim(gen_ART(ART_result, seed_prot, length_AA = 30, method = "greedy"),
substr(prot_seq, 1, 40)))
print(stringdist::stringsim(gen_ART(ART_result, seed_prot, length_AA = 40, method = "greedy"),
substr(prot_seq, 1, 50)))
print(stringdist::stringsim(gen_ART(ART_result, seed_prot, length_AA = 50, method = "greedy"),
substr(prot_seq, 1, 60)))
}
## generating...
## [1] 0.4666667
## generating...
## [1] 0.375
## generating...
## [1] 0.3
## generating...
## [1] 0.2666667
## R version 4.4.0 beta (2024-04-15 r86425)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggseqlogo_0.2 GenProSeq_1.8.0 mclust_6.1.1 keras_2.15.0
##
## loaded via a namespace (and not attached):
## [1] RColorBrewer_1.1-3 rstudioapi_0.16.0
## [3] jsonlite_1.8.8 magrittr_2.0.3
## [5] ggbeeswarm_0.7.2 farver_2.1.1
## [7] rmarkdown_2.26 zlibbioc_1.50.0
## [9] vctrs_0.6.5 DelayedMatrixStats_1.26.0
## [11] ttgsea_1.12.0 base64enc_0.1-3
## [13] PRROC_1.3.1 koRpus.lang.en_0.1-4
## [15] htmltools_0.5.8.1 S4Arrays_1.4.0
## [17] BiocNeighbors_1.22.0 SparseArray_1.4.0
## [19] sass_0.4.9 bslib_0.7.0
## [21] htmlwidgets_1.6.4 tokenizers_0.3.0
## [23] cachem_1.0.8 whisker_0.4.1
## [25] lifecycle_1.0.4 pkgconfig_2.0.3
## [27] rsvd_1.0.5 Matrix_1.7-0
## [29] R6_2.5.1 fastmap_1.1.1
## [31] GenomeInfoDbData_1.2.12 MatrixGenerics_1.16.0
## [33] digest_0.6.35 colorspace_2.1-0
## [35] S4Vectors_0.42.0 ps_1.7.6
## [37] scater_1.32.0 irlba_2.3.5.1
## [39] VAExprs_1.10.0 GenomicRanges_1.56.0
## [41] SnowballC_0.7.1 beachmat_2.20.0
## [43] labeling_0.4.3 fansi_1.0.6
## [45] tfruns_1.5.3 httr_1.4.7
## [47] abind_1.4-5 compiler_4.4.0
## [49] withr_3.0.0 BiocParallel_1.38.0
## [51] viridis_0.6.5 sylly_0.1-6
## [53] koRpus_0.13-8 highr_0.10
## [55] tensorflow_2.16.0 float_0.3-2
## [57] DelayedArray_0.30.0 CatEncoders_0.1.1
## [59] tools_4.4.0 chromote_0.2.0
## [61] vipor_0.4.7 beeswarm_0.4.0
## [63] word2vec_0.4.0 stopwords_2.3
## [65] sylly.en_0.1-3 webchem_1.3.0
## [67] glue_1.7.0 lgr_0.4.4
## [69] DiagrammeR_1.0.11 promises_1.3.0
## [71] grid_4.4.0 stringdist_0.9.12
## [73] generics_0.1.3 gtable_0.3.5
## [75] websocket_1.4.1 data.table_1.15.4
## [77] BiocSingular_1.20.0 ScaledMatrix_1.12.0
## [79] xml2_1.3.6 utf8_1.2.4
## [81] XVector_0.44.0 BiocGenerics_0.50.0
## [83] ggrepel_0.9.5 pillar_1.9.0
## [85] stringr_1.5.1 later_1.3.2
## [87] dplyr_1.1.4 lattice_0.22-6
## [89] tidyselect_1.2.1 SingleCellExperiment_1.26.0
## [91] tm_0.7-13 scuttle_1.14.0
## [93] knitr_1.46 gridExtra_2.3
## [95] NLP_0.2-1 IRanges_2.38.0
## [97] SummarizedExperiment_1.34.0 textstem_0.1.4
## [99] RhpcBLASctl_0.23-42 stats4_4.4.0
## [101] xfun_0.43 Biobase_2.64.0
## [103] matrixStats_1.3.0 visNetwork_2.1.2
## [105] stringi_1.8.3 UCSC.utils_1.0.0
## [107] yaml_2.3.8 rsparse_0.5.1
## [109] evaluate_0.23 codetools_0.2-20
## [111] data.tree_1.1.0 tibble_3.2.1
## [113] cli_3.6.2 matlab_1.0.4
## [115] reticulate_1.36.1 munsell_0.5.1
## [117] processx_3.8.4 jquerylib_0.1.4
## [119] Rcpp_1.0.12 GenomeInfoDb_1.40.0
## [121] DeepPINCS_1.12.0 mlapi_0.1.1
## [123] zeallot_0.1.0 png_0.1-8
## [125] parallel_4.4.0 ggplot2_3.5.1
## [127] sparseMatrixStats_1.16.0 viridisLite_0.4.2
## [129] slam_0.1-50 text2vec_0.6.4
## [131] scales_1.3.0 purrr_1.0.2
## [133] crayon_1.5.2 rlang_1.1.3
## [135] rvest_1.0.4
Barbosa, V. A. F., Santana, M. A., Andrade, M. K. S., Lima, R. C. F., & Santos, W. P. (2020). Deep Learning for Data Analytics: Foundations, Biomedical Applications, and Challenges. Academic Press.
Cinelli, L. P., Marins, M. A., da Silva, E. A. B., & Netto, S. L. (2021). Variational Methods for Machine Learning with Applications to Deep Networks. Springer.
Dash, S., Acharya, B. R., Mittal, M., Abraham, A., & Kelemen, A. (Eds.). (2020). Deep learning techniques for biomedical and health informatics. Springer.
Deepak, P., Chakraborty, T., & Long, C. (2021). Data Science for Fake News: Surveys and Perspectives. Springer.
Dong, G., & Pei, J. (2007). Sequence data mining. Springer.
Frazer, J., Notin, P., Dias, M., Gomez, A., Brock, K., Gal, Y., & Marks, D. (2020). Large-scale clinical interpretation of genetic variants using evolutionary data and deep learning. bioRxiv.
Gagniuc, P. A. (2021). Algorithms in Bioinformatics: Theory and Implementation. Wiley & Sons.
Hawkins-Hooker, A., Depardieu, F., Baur, S., Couairon, G., Chen, A., & Bikard, D. (2020). Generating functional protein variants with variational autoencoders. bioRxiv.
Hemanth, J., Bhatia, M., & Geman, O. (2020). Data Visualization and Knowledge Engineering: Spotting Data Points with Artificial Intelligence. Springer.
Lappin, S. (2021). Deep learning and linguistic representation. CRC Press.
Liebowitz, J. (Ed.). (2020). Data Analytics and AI. CRC Press.
Liu, Z., Lin, Y., & Sun, M. (2020). Representation learning for natural language processing. Springer.
Madani, A., McCann, B., Naik, N., Keskar, N. S., Anand, N., Eguchi, R. R., Huang, P., & Socher, R. (2020). Progen: Language modeling for protein generation. arXiv:2004.03497.
Pearson, R. K. (2018). Exploratory data analysis using R. CRC Press.
Pedrycz, W., & Chen, S. M. (Eds.). (2020). Deep Learning: Concepts and Architectures. Springer.
Peter, J. D., Fernandes, S. L., Thomaz, C. E., & Viriri, S. (Eds.). (2019). Computer aided intervention and diagnostics in clinical and medical images. Springer.
Repecka, D., et al. (2019). Expanding functional protein sequence space using generative adversarial networks. bioRxiv.
Suguna, S. K., Dhivya, M., & Paiva, S. (Eds.). (2021). Artificial Intelligence (AI): Recent Trends and Applications. CRC Press.
Sun, S., Mao, L., Dong, Z., & Wu, L. (2019). Multiview machine learning. Springer.
Wolkenhauer, O. (2020). Systems Medicine: Integrative, Qualitative and Computational Approaches. Academic Press.
Wu, Z., Johnston, K. E., Arnold, F. H., & Yang, K. K. (2021). Protein sequence design with deep generative models. arXiv:2104.04457.