BPfold¶
Pre-trained model for RNA secondary structure prediction using base pair motif energy.
Disclaimer¶
This is an UNOFFICIAL implementation of Deep generalizable prediction of RNA secondary structure via base pair motif energy by Heqin Zhu, Fenghe Tang, Quan Quan, Ke Chen, Peng Xiong, and S. Kevin Zhou.
The OFFICIAL repository of BPfold is at heqin-zhu/BPfold.
Tip
The MultiMolecule implementation preserves the released BPfold architecture, base-pair motif energy feature construction, and canonical/non-canonical post-processing semantics.
The team releasing BPfold did not write this model card for this model so this model card has been written by the MultiMolecule team.
Model Details¶
BPfold predicts RNA base-pair contact maps from a single RNA sequence. It augments a transformer encoder with two L x L base-pair motif energy maps computed from three-neighbor base-pair motifs. MultiMolecule exposes BPfold as a single checkpoint and stores the motif-energy lookup tables inside it.
The model uses:
- token order: follows the MultiMolecule tokenizer.
- unknown bases: tokenized as
Nand treated asUduring BPfold feature construction, matching the upstream fallback; padding followsattention_mask. - self-attention: dynamic position bias with adjacency bias from motif-energy maps.
- pairwise convolutions: three residual 2D convolution layers over the adjacency maps before the transformer blocks.
- post-processing: constrained refinement for canonical pairs, plus the optional BPfold non-canonical pass and mixed canonical/non-canonical outputs.
Model Specification¶
| Num Layers | Hidden Size | Num Heads | Max Num Tokens | Num Parameters (M) | FLOPs (G) | MACs (G) |
|---|---|---|---|---|---|---|
| 12 | 256 | 8 | 600 | 47.77 | 87.78 | 42.74 |
FLOPs and MACs are computed with multimolecule.utils for one 600 nt sequence.
Links¶
- Code: multimolecule.bpfold
- Paper: Deep generalizable prediction of RNA secondary structure via base pair motif energy
- Developed by: Heqin Zhu, Fenghe Tang, Quan Quan, Ke Chen, Peng Xiong, S. Kevin Zhou
- Original Repository: heqin-zhu/BPfold
Usage¶
The model file depends on the multimolecule library. You can install it using pip:
| Bash | |
|---|---|
RNA Secondary Structure Pipeline¶
| Python | |
|---|---|
PyTorch Inference¶
Training Details¶
BPfold was trained for RNA secondary structure prediction with base-pair motif energy priors.
Training Data¶
- RNAStrAlign: 37,149 RNAs from eight RNA families were filtered to remove redundant sequences and invalid secondary structures, yielding 29,647 unique RNAs. Sequences longer than 600 nt were removed for training, leaving 19,313 training RNAs.
- bpRNA-1m: 102,318 RNAs from 2,588 families were deduplicated with CD-HIT at 80% sequence identity and split into TR0/TS0 with 12,114/1,305 RNAs.
- evaluation data: ArchiveII contains 3,966 RNAs; Rfam12.3-14.10 contains 10,791 RNAs from 1,992 families; bpRNA-new contains 5,401 RNAs; PDB contains 116 high-resolution RNAs split into TS1/TS2/TS3.
Training Procedure¶
- objective: binary cross entropy over base-pair contact maps.
- optimizer: Adam.
- learning rate: 5e-4.
- training epochs: 150.
- batch size: 48.
- positive-class weight: 300.
- batching: length-matching mini-batches to reduce padding.
- sequence features: token embeddings converted to the MultiMolecule tokenizer order.
- structural priors: two
L x Lenergy maps from three-neighbor base-pair motifs. - post-processing: constrained refinement for canonical pairs, minimum loop length, non-overlapping pairs, and isolated-pair removal.
Citation¶
Note
The artifacts distributed in this repository are part of the MultiMolecule project. If you use MultiMolecule in your research, you must cite the MultiMolecule project as follows:
| BibTeX | |
|---|---|
Contact¶
Please use GitHub issues of MultiMolecule for any questions or comments on the model card.
Please contact the authors of the BPfold paper for questions or comments on the paper/model.
License¶
This model implementation is licensed under the GNU Affero General Public License.
For additional terms and clarifications, please refer to our License FAQ.
| Text Only | |
|---|---|
multimolecule.models.bpfold
¶
RnaTokenizer
¶
Bases: Tokenizer
Tokenizer for RNA sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Alphabet | str | List[str] | None
|
alphabet to use for tokenization.
|
None
|
|
int
|
Size of kmer to tokenize. |
1
|
|
bool
|
Whether to tokenize into codons. |
False
|
|
bool
|
Whether to replace T with U. |
True
|
|
bool
|
Whether to convert input to uppercase. |
True
|
Examples:
Source code in multimolecule/tokenisers/rna/tokenization_rna.py
BpfoldConfig
¶
Bases: PreTrainedConfig
This is the configuration class to store the configuration of a
BpfoldModel. It is used to instantiate a BPfold model according to the
specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a
similar configuration to that of the BPfold heqin-zhu/BPfold architecture.
Configuration objects inherit from PreTrainedConfig and can be used to
control the model outputs. Read the documentation from PreTrainedConfig
for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Token vocabulary size of the BPfold model. |
11
|
|
int
|
Dimensionality of nucleotide token embeddings and transformer hidden states. |
256
|
|
int
|
Number of base-pair attention transformer blocks. |
12
|
|
int
|
Hidden size per attention head. |
32
|
|
int
|
Dimensionality of the feed-forward layer inside each transformer block. |
768
|
|
float
|
Dropout probability in transformer blocks. |
0.1
|
|
str
|
Positional bias type used by self-attention. The original checkpoint uses |
'dyn'
|
|
int
|
Number of convolutional layers applied to the pairwise energy map. |
3
|
|
int
|
Kernel size for pairwise energy convolutions. |
3
|
|
bool
|
Whether to use squeeze-and-excitation blocks in pairwise convolutions. |
True
|
|
bool
|
Whether to use base-pair motif energy maps. |
True
|
|
bool
|
Whether to use an externally provided base-pair probability map. |
False
|
|
bool
|
Whether motif energy is represented as separate outer and inner energy maps. |
True
|
|
int
|
Number of neighboring bases in base-pair motifs. The published BPfold model uses three. |
3
|
|
int
|
Training-time maximum sequence length used by the original checkpoints. |
600
|
|
float
|
Probability threshold for predicting base pairs during post-processing. |
0.5
|
|
bool
|
Whether to run the constrained BPfold post-processing loop in |
False
|
|
int
|
Number of constrained post-processing iterations. |
100
|
|
float
|
Learning rate for the minimization step in post-processing. |
0.01
|
|
float
|
Learning rate for the Lagrangian multiplier maximization step in post-processing. |
0.1
|
|
float
|
L1 sparsity coefficient used by canonical post-processing. |
1.6
|
|
float
|
L1 sparsity coefficient used by non-canonical post-processing. |
0.5
|
|
bool
|
Whether to apply L1 shrinkage in post-processing. |
True
|
|
float
|
Logit cutoff used by canonical post-processing. |
1.5
|
|
float
|
Logit cutoff used by non-canonical post-processing. |
0.5
|
|
float
|
Positive-class weight used by the original weighted binary cross-entropy training loss. |
300.0
|
|
int
|
Number of internal checkpoint members in the released BPfold predictor. |
6
|
Examples:
| Python Console Session | |
|---|---|
Source code in multimolecule/models/bpfold/configuration_bpfold.py
| Python | |
|---|---|
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 | |
BpfoldModel
¶
Bases: BpfoldPreTrainedModel
Source code in multimolecule/models/bpfold/modeling_bpfold.py
| Python | |
|---|---|
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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |