4.2.6 GRUClassifier - WangLabTHU/GPro GitHub Wiki

hcwang and qxdu edited on Aug 4, 2023, 1 version

AttnBiLSTM Model Architecture

GRUClassifier is a binary classifier based on the GRU architecture, which was used in paper [1]; Its most significant advantage is that there is no need to limit the length, only the batch_size parameter needs to be specified. In other words, the sequences within the training set can be completely unequal in length! An exemplary example is as follows[2].

All parameters should be defined during the initialization phase. We have encapsulated the source code, thus all predictive models have unified input and output parameters. There are two types of parameters, one should be defined during the initialization phase (Initialization), and the other should be defined during the training/sampling phase (Training/Predicting).

Initialization params

params description default value
batch_size training batch size 64
length sequential length of the training dataset None
model_name parameter that controls the saving path under "./checkpoints" GRUClassifier
epoch training epochs 200
patience earlystopping when the indicators no longer change 10
log_steps logging the output/criterias of the model every print_epoch epochs 10
save_steps saving the result of model every save_epoch epochs 20
exp_mode the processing mode for expression input direct

Training/Predicting params

params description default value flexible stage
dataset training dataset sequences path, fasta file None train()
labels training dataset expression path, txt file, each line an expression corresponding to dataset None train()
savepath final model saving path directory None train()
model_path model loading directory None predict()/predict_input()
data_path dataset to be predicted , fasta file None predict()
inputs data for predict_input, can be datapath, sequence list or onehot encoded data None predict_input()
mode input mode for predict_input, can be "path","data" or "onehot" "path" predict_input()

Caution: predict() function will directly generate samples in checkpoint path, but predict_input() will not generate the file automatically.

Demo

A demo for model training/predicting is described below:

from gpro.predictor.others.GRUClassifier import GRUClassifier_language

model = GRUClassifier_language(length=306)

default_root = "your working directory"
dataset = os.path.join(default_root, 'data/seq.txt')
labels  = os.path.join(default_root, 'data/exp.txt')
save_path = os.path.join(default_root, 'checkpoints/')
model.train(dataset=dataset,labels=labels,savepath=save_path)


# Predict
model_path = os.path.join(default_root, "checkpoints/GRUClassifier/checkpoint.pth")
data_path =  os.path.join(default_root, "data/example.txt")
model.predict(model_path=model_path, data_path=data_path)

# Predict input
res = model.predict_input(model_path=model_path, inputs=data_path)
print(res)

Citations

[1] Gupta A, Zou J. Feedback GAN for DNA optimizes protein functions[J]. Nature Machine Intelligence, 2019, 1(2): 105-111.
[2] Li, Liu, and Zhang. “An Improved Approach for Text Sentiment Classification Based on a Deep Neural Network via a Sentiment Attention Mechanism”. In: Future Internet 11 (Apr. 2019), p. 96. doi: 10.3390/fi11040096.
⚠️ **GitHub.com Fallback** ⚠️