Preprint
Short Note

This version is not peer-reviewed.

Biotorch: A Unified PyTorch Automl Library for Biological Sequences, Networks and Graphs

Submitted:

19 October 2026

Posted:

20 October 2026

You are already at the latest version

Abstract
Modernized deep learning includes sequence models, graph neural networks and domain specific analysis. We present biotorch, a PyTorch-based Python package that handles biological sequences (DNA, RNA, protein), biological networks (protein–protein interaction, gene regulatory, metabolic and other typed, weighted or directed networks) and graphs (protein structures, molecules, de Bruijn graphs) under one interface. Each and every model exposes batch method, which allows the users to automate classification, regression, per-residue labelling, masked language modelling, node classification, link prediction, graph classification and sequence-network fusion. The package include synthetic benchmarks. biotorch is written in Python (≥3.9) and distributed as an installable package. Source code, documentation and tests: https://github.com/sablokg/biotorch. License: MIT. The package was developed and tested with Python 3.12 and PyTorch 2.14 on CPU.
Keywords: 
;  ;  ;  

1. Introduction

Machine learning on biological data entails working on different sequences and networks in biology (Tarca et al. 2017). High througput modelling involves modelling sequence embeddings with one hot encoded counterparts using convolutional, recurrent and attention architectures (Chen et al., 2019; Devlin et al., 2019). On the similar note, modelling interaction and regulatory networks involves graph neural networks (GNNs) such as GCN, GraphSAGE, GAT, GIN and relational GCN (Kipf and Welling, 2017; Hamilton et al., 2017; Veličković et al., 2018; Xu et al., 2019; Schlichtkrull et al., 2018) or with walk-based embeddings (Grover and Leskovec, 2016). General graph libraries such as PyTorch Geometric (Fey and Lenssen, 2019) and the Deep Graph Library (Wang et al., 2019) offer broad GNN coverage but no biological sequence handling. Selene (Chen et al., 2019) and the Kipoi model repository (Avsec et al., 2019) concentrate on sequence-based genomics models. TorchDrug (Zhu et al., 2022) targets drug discovery, and Biopython (Cock et al., 2009) provides parsing and sequence utilities rather than model training. To address this gap, biotorch provides (i) biological data structures that convert directly to tensors, (ii) pure-PyTorch implementations of the common sequence encoders and GNN layers, and (iii) a task-agnostic training engine with an automated hyperparameter search.

2. Implementation

2.1. Sequences

Biotorch provides implementation for the sequences for DNA, RNA and protein, which forms the building blocks of the biological sequences with reserve padding, unknown, class, end and masking tokens. Several in built functions are included such as reverse complement (with IUPAC ambiguity codes), transcription, translation with the standard codon table, GC content, k-mer counting and one-hot encoding. FASTA, FASTQ and CSV/TSV files (optionally gzip-compressed) for sequence and biological networks. It also supports multiclass, multilabel and regression tasks, and unlabelled data for masked language modeling. Transform encoders are a critical part of the sequence modeling and developing genome scale language models (Jiang et al. 2024). biotorch provides dilated residual 1-D CNN, a pre-norm Transformer with sinusoidal positions, and bidirectional GRU or LSTM networks.

2.2. Networks and Graphs and Task Model

To store nodes, optional edge weights, relation types and node types, for directed or undirected networks, it has a BioNetwork module, which reads edge lists, removes self-loops and duplicate edges, and provides degree, adjacency, neighbourhood queries, k-hop expansion, connected components, induced subgraphs and vectorised random walks. Graphs are represented as tensors and are batched them as disjoint unions using BioGraph and GraphBatch. Biotorch provides support for all the constructor build residue graphs from C-alpha coordinates (k-nearest-neighbour edges with radial-basis distance and sequence-separation features), kmer de Bruijn graphs, and, also molecular graphs using RdKit. Message passing is implemented with index-add and scatter-reduce primitives. GCN, GraphSAGE, GAT (with optional edge features), GIN (with edge features) and relational GCN layers are combined in a configurable residual encoder with optional node-type embeddings and mean, max, sum or mean–max pooling. BioModel is the central layer that provides the connection to all SeqModel(sequence level and per residue prediction), SeqMLM (masked language modelling with 80/10/10 corruption), GraphModel (graph based prediction), NodeModel(node classification or regression), LinkModel (graph based link prediction with dot-product, DistMult or MLP decoders), Node2Vec (skip gram embeddings from random walks) and SeqGraphNodeModel(propagates the embeddings over the network by generating the sequence for every node).

2.4. Automated Training and Search

A auto trainer Trainer provides mixed precision on CUDA devices, gradient accumulation and clipping, parameter groups that exclude biases and normalisation weights from weight decay, linear warm-up followed by cosine, linear or plateau schedules, early stopping on any logged metric, best and last checkpoints, resumption, and task-appropriate metrics computed without external dependencies (accuracy, macro-F1, AUROC, average precision, MSE, MAE, R², Pearson and Spearman correlation, perplexity). The experimental loop has been implemented using the auto_fit, which performs a stratified train/test/validation split with augmentation and writes the JSON report for the best configuration. For graph based node classification and link prediction, node_split_loaders and link_split_loaders supply masked full graph loaders, resampling of the link-prediction training and edge based message passing.

3. Results and Discussion

We bench-marked the available modules on synthetic tasks with known planted signals, using a single CPU and one random seed per task (Table 1). Sequence tasks used random sequences with planted motifs (binary presence, three classes, motif copy number, and per-residue motif position). Graph classification distinguished density-matched random graphs with and without a planted 5-clique. Node classification, link prediction and sequence–network fusion used stochastic block model networks, which demonstrates the sequence utilities and the graph based modeling of the package.
In comparison tests, Node2Vec embeddings gave a higher mean cosine similarity within planted communities (0.588) than between them (0.468), and masked language model training completed on short DNA sequences. Additional 11 tests were performed covering sequence utilities, FASTA checks including batching and token-label alignment, network queries and negative sampling correction, all graph neural networks. Biological research requires the tailoring of the biological resources for biological machine learning (Magnano et al. 2022, Ghosh et al. 2025). PyTorch offers a lot of feasibility and computational capacity for the biological machine learning. However, the training of the convolution network and graph based modeling requires a lot of boiler plate code writing and hence makes PyTorch a high level learning for the developers for the biological machine learning. biotorch exposes all the layers natively and thus minimizes such boilerplate reduction.

Funding

GS received no funding for this study. GS conceived the software, coded biotorch and wrote the paper.

Conflicts of Interest

GS declares no conflict of interest.

References

  1. Avsec, Ž.; et al. The Kipoi repository accelerates community exchange and reuse of predictive models for genomics. Nat. Biotechnol. 2019, 37, 592–594. [Google Scholar] [CrossRef] [PubMed]
  2. Chen, K.M.; et al. A deep learning framework for sequence-based genomics models using Selene. Nat. Methods 2019, 16, 315–318. [Google Scholar] [PubMed]
  3. Cock, P.J.A.; et al. Biopython: freely available Python tools for computational molecular biology and bioinformatics. Bioinformatics 2009, 25, 1422–1423. [Google Scholar] [CrossRef] [PubMed]
  4. Devlin, J.; et al. BERT: pre-training of deep bidirectional transformers for language understanding. Proc. NAACL-HLT. 2019. [Google Scholar] [CrossRef]
  5. Fey, M.; Lenssen, J.E. Fast graph representation learning with PyTorch Geometric. ICLR Workshop on Representation Learning on Graphs and Manifolds; 2019. [Google Scholar]
  6. Grover, A.; Leskovec, J. node2vec: scalable feature learning for networks. Proc. KDD 2016, 855–864. [Google Scholar]
  7. Hamilton, W.L.; et al. Inductive representation learning on large graphs. Adv. Neural Inf. Process. Syst. 2017, 30. [Google Scholar]
  8. Kipf, T.N.; Welling, M. Semi-supervised classification with graph convolutional networks. Proc. ICLR. 2017. [Google Scholar] [CrossRef]
  9. Paszke, A.; et al. PyTorch: an imperative style, high-performance deep learning library. Adv. Neural Inf. Process. Syst. 2019, 32. [Google Scholar]
  10. Schlichtkrull, M.; et al. Modeling relational data with graph convolutional networks. Proc. ESWC 2018, 593–607. [Google Scholar] [CrossRef]
  11. Veličković, P.; et al. Graph attention networks. Proc. ICLR. 2018. [Google Scholar] [CrossRef]
  12. Wang, M.; et al. Deep Graph Library: a graph-centric, highly-performant package for graph neural networks. 2019. [Google Scholar] [CrossRef]
  13. Xu, K.; et al. How powerful are graph neural networks? Proc. ICLR. 2019. [Google Scholar] [CrossRef]
  14. Zhu, Z.; et al. TorchDrug: a powerful and flexible machine learning platform for drug discovery. 2022. [Google Scholar] [CrossRef]
  15. Tarca, A. L.; Carey, V. J.; Chen, X.-W.; Romero, R.; Drăghici, S. Machine learning and its applications to biology. PLoS Comput. Biol. 2007, 3, e116. [Google Scholar] [CrossRef] [PubMed]
  16. Magnano, CS; Mu, F; Russ, RS; Cvetkovic, M; Treu, D; Gitter, A. An approachable, flexible and practical machine learning workshop for biologists. Bioinformatics 2022, 38 (Suppl 1), i10–i18. [Google Scholar] [CrossRef] [PubMed]
  17. Jiang, J; Ke, L; Chen, L; Dou, B; Zhu, Y; Liu, J; Zhang, B; Zhou, T; Wei, GW. Transformer technology in molecular science. Wiley Interdiscip Rev Comput Mol Sci 2024, 14(4), e1725. [Google Scholar] [CrossRef] [PubMed]
  18. Ghosh, N; Santoni, D; Saha, I; Felici, G. A review on the applications of Transformer-based language models for nucleotide sequence analysis. Comput Struct Biotechnol J 2025, 27, 1244–1254. [Google Scholar] [CrossRef] [PubMed]
Table 1. Held-out test performance on synthetic tasks (single run, one seed, CPU).
Table 1. Held-out test performance on synthetic tasks (single run, one seed, CPU).
Task Model Metric Result
Motif presence (binary) CNN Accuracy 0.967
Motif class (3 classes) CNN Accuracy 0.967
Motif copy number (regression) CNN R² 0.716
Motif position (per residue) CNN Accuracy 0.997
Planted clique (graph classification) GIN Accuracy 0.958
Community (node classification) GCN Accuracy 1.000
Held-out edges (link prediction) GraphSAGE + MLP AUROC 0.761
Community from node sequence + network CNN + GraphSAGE Accuracy 0.958
Motif presence with auto_fit (3 trials) CNN or GRU Accuracy / AUROC 0.975 / 0.997
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.