File size: 6,132 Bytes
bf928ee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | ---
frameworks:
- TensorFlow
language:
- en
license: mit
tags:
- OneScience
- bioscience
- nanobody
- antigen
- BiLSTM
- attention
- DCU
tasks:
- binary-classification
datasets:
- SAbDab-nano
---
<p align="center">
<strong>
<span style="font-size: 30px;">NABP-LSTM-Att</span>
</strong>
</p>
# Model Introduction
NABP-LSTM-Att is a binary classification model that predicts whether a nanobody binds to an antigen using sequence information only.
The model separately encodes the nanobody CDR and antigen sequences, extracts interaction features through one-dimensional convolution, bidirectional LSTM, and a soft attention mechanism, and finally outputs a binding probability between 0 and 1.
Paper: [NABP-LSTM-Att: Nanobody–Antigen binding prediction using bidirectional LSTM and soft attention mechanism](https://doi.org/10.1016/j.compbiolchem.2025.108490)
# Model Description
The default model uses the following inputs and architecture:
- The nanobody CDR is represented using 3-mers with an input length of 24;
- The antigen is represented using 1-mers with an input length of 2371;
- CDR sequence embeddings are added to CDR positional/index embeddings before being passed through a convolutional layer;
- The antigen sequence is processed through an independent embedding layer and convolutional layer;
- The two feature streams are concatenated and aggregated using a BiLSTM and soft attention layer;
- A Sigmoid output layer produces a single binding probability;
- Binary cross-entropy is used as the training objective.
# Use Cases
| Use Case | Description |
| :---: | :--- |
| Nanobody–antigen binding prediction | Predict the probability of binding from CDR and antigen sequence features. |
| Official test-set evaluation | Evaluate the official pretrained model using AUROC and AUPR. |
| Model retraining | Train the model from randomly initialized weights using the precomputed training and validation datasets. |
| DCU compatibility validation | Validate inference, backward propagation, parameter updates, and device placement on DCU. |
# Usage
## 1. OneCode
You can use the OneCode online environment for an intelligent one-click AI4S programming experience:
[Try OneCode for AI4S Programming](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)
## 2. Manual Installation
**Hardware Requirements**
- Running in the OneScience Hygon DCU environment is recommended;
- The current adaptation has been validated on BW DCU;
- Both inference and training support single-device execution.
### Download the Model Package
Install the Hugging Face command-line tool and download the model repository:
```bash
python -m pip install -U huggingface_hub
hf download OneScience-Group/NABP-LSTM-Att --local-dir ./NABP-LSTM-Att
cd NABP-LSTM-Att
```
### Install the OneScience Base Environment
```bash
conda create -n onescience311 python=3.11 -y
conda activate onescience311
python -m pip install "onescience[bio-dcu]" \
-i http://mirrors.onescience.ai:3141/pypi/simple/ \
--trusted-host mirrors.onescience.ai
```
### Version Compatibility
This project requires an upgraded DTK and TensorFlow environment.
Load DTK and install the additional dependencies:
```bash
module load compiler/dtk/26.04
python -m pip install --upgrade --no-deps -r requirements.txt
```
### Weights and Data Preparation
The Hugging Face model package already contains the precomputed features, k-mer vocabularies, and official pretrained weights required for inference and training.
No additional dataset download is required for the default workflow.
The default assets are:
```text
conf/data/features/cdr_kmer3_ag_kmer1/
weight/cdr_kmer3_ag_kmer1/Model99.h5
```
### Quick Inference
**Purpose:** Evaluate the complete official test set using the pretrained weights. The script reports AUROC, AUPR, runtime, and throughput, and can optionally save the prediction results.
```bash
python scripts/evaluate_test_set.py \
--batch-size 64 \
--output output/test_predictions.npz
```
### Full-Dataset Training
**Purpose:** Train the model from randomly initialized weights using the complete training dataset and evaluate it on the validation set.
By default, training runs for 100 epochs.
Checkpoints are written to:
```text
output/checkpoints/
```
The official pretrained weights are not overwritten.
Run:
```bash
python scripts/train.py
```
To validate the complete training pipeline with only one epoch, run:
```bash
python scripts/train_one_epoch.py \
--batch-size 64 \
--output-dir output/one_epoch_run1
```
### Minimal Compatibility Validation
Use the following commands to perform lightweight inference and training validation:
```bash
python scripts/verify_minimal_inference.py --samples 8
python scripts/verify_minimal_training.py \
--batch-size 8 \
--steps 3
```
### Custom Data
Custom sequences must first be converted into CDR and antigen feature objects that are compatible with the pickle format used by the official dataset.
Scripts for data acquisition, dataset splitting, k-mer TSV generation, and feature encoding are provided in:
```text
scripts/
```
When rebuilding the dataset from the original SAbDab-nano data, additional external tools such as CD-HIT and Clustal Omega are also required.
# OneScience Official Resources
| Platform | OneScience Main Repository | Skills Repository |
| --- | --- | --- |
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
# Citation and License
- Ahmed, F. S., Aly, S., El-Tabakh, M. A. M., & Liu, X. (2025). [NABP-LSTM-Att: Nanobody–Antigen binding prediction using bidirectional LSTM and soft attention mechanism](https://doi.org/10.1016/j.compbiolchem.2025.108490). *Computational Biology and Chemistry*, **118**, 108490.
- Original project: https://github.com/FMoonlightS/NABP-LSTM-Att
- This project is distributed under the MIT License.
- Model assets, datasets, and external tools remain subject to their respective original licenses and terms of use. |