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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 下面是完整 `README.md` Markdown 源码格式,可以直接复制保存为 `README.md` 上传 HuggingFace。
2
+
3
+ ```markdown
4
+ ---
5
+ language:
6
+ - en
7
+
8
+ tags:
9
+ - nanopore
10
+ - dna
11
+ - sequencing
12
+ - genomics
13
+ - bioinformatics
14
+ - foundation-model
15
+ - transformer
16
+ - bert
17
+ - masked-language-modeling
18
+ - signal-processing
19
+ - vector-quantization
20
+ - vq-tokenizer
21
+
22
+ pipeline_tag: feature-extraction
23
+
24
+ library_name: transformers
25
+
26
+ base_model:
27
+ - none
28
+
29
+ datasets:
30
+ - ShuaiAnwo/PoreDNA_S1_HG002_MOD_250F701901011_A50
31
+
32
+ new_version:
33
+ - v526
34
+
35
+ metrics:
36
+ - loss
37
+
38
+ license:
39
+ - openrail
40
+ ---
41
+
42
+ # PoreBERT-DNA-VQI-256-526
43
+
44
+ A compact BERT-style foundation model for nanopore DNA sequencing signal representation learning.
45
+
46
+ PoreBERT-DNA-VQI-256-526 learns contextual representations from discretized nanopore electrical signal tokens generated by a Vector Quantization (VQ) tokenizer.
47
+
48
+ The model is pretrained with a Masked Language Modeling (MLM) objective on large-scale nanopore DNA sequencing token sequences.
49
+
50
+ The model is designed for downstream nanopore sequencing applications including:
51
+
52
+ - Basecalling
53
+ - Modified base detection
54
+ - Signal representation learning
55
+ - Read-level embedding
56
+
57
+
58
+ ---
59
+
60
+ # Model Summary
61
+
62
+ | Property | Description |
63
+ |---|---|
64
+ | Model Type | BERT Encoder |
65
+ | Domain | Nanopore DNA sequencing |
66
+ | Architecture | Transformer Encoder |
67
+ | Parameters | ~8M |
68
+ | Training Objective | Masked Language Modeling (MLM) |
69
+ | Input | Discrete nanopore signal tokens |
70
+ | Tokenizer | VQ-based neural codec |
71
+ | Vocabulary Size | 2560 |
72
+ | Release Version | 526 |
73
+
74
+
75
+ ---
76
+
77
+ # Model Name Explanation
78
+
79
+ ```
80
+
81
+ PoreBERT-DNA-VQI-256-526
82
+
83
+ ```
84
+
85
+ ## PoreBERT
86
+
87
+ Nanopore sequencing foundation model based on the BERT encoder architecture.
88
+
89
+
90
+ ## DNA
91
+
92
+ The model is trained on nanopore DNA sequencing electrical signal representations.
93
+
94
+
95
+ ## VQI
96
+
97
+ Vector Quantization based minimal vocabulary tokenizer.
98
+
99
+ The raw nanopore electrical signal is converted into discrete token IDs using a neural codec based on vector quantization.
100
+
101
+
102
+ ## 256
103
+
104
+ The hidden representation dimension of the Transformer encoder.
105
+
106
+ ```
107
+
108
+ hidden_size = 256
109
+
110
+ ```
111
+
112
+
113
+ ## 526
114
+
115
+ Internal development release identifier.
116
+
117
+
118
+ ---
119
+
120
+ # Architecture Overview
121
+
122
+ The complete representation pipeline:
123
+
124
+ ```
125
+
126
+ Nanopore Electrical Signal
127
+
128
+ ```
129
+ |
130
+ v
131
+ ```
132
+
133
+ PoreCodec
134
+ (CNN Encoder + Vector Quantization)
135
+
136
+ ```
137
+ |
138
+ v
139
+ ```
140
+
141
+ Discrete Signal Tokens
142
+
143
+ ```
144
+ |
145
+ v
146
+ ```
147
+
148
+ PoreBERT-DNA-VQI-256-526
149
+
150
+ ```
151
+ |
152
+ v
153
+ ```
154
+
155
+ Contextual Token Embeddings
156
+
157
+ ```
158
+ |
159
+ v
160
+ ```
161
+
162
+ Downstream Applications
163
+
164
+ ```
165
+
166
+
167
+ The PoreBERT model itself does not directly process raw electrical signals.
168
+
169
+ The input of PoreBERT is the discrete token sequence generated by the PoreCodec tokenizer.
170
+
171
+
172
+ ---
173
+
174
+ # Tokenizer
175
+
176
+ This model uses the following tokenizer:
177
+
178
+ ```
179
+
180
+ ShuaiAnwo/pore-codec-rsq742c12a-511
181
+
182
+ ```
183
+
184
+
185
+ The tokenizer converts nanopore electrical signals into discrete token IDs through a VQ-based neural codec.
186
+
187
+
188
+ Workflow:
189
+
190
+ ```
191
+
192
+ Raw signal
193
+
194
+ ```
195
+ |
196
+ v
197
+ ```
198
+
199
+ PoreCodec VQ tokenizer
200
+
201
+ ```
202
+ |
203
+ v
204
+ ```
205
+
206
+ Discrete Token IDs
207
+
208
+ ```
209
+ |
210
+ v
211
+ ```
212
+
213
+ PoreBERT Encoder
214
+
215
+ ```
216
+ |
217
+ v
218
+ ```
219
+
220
+ Contextual Embeddings
221
+
222
+ ```
223
+
224
+
225
+ ---
226
+
227
+ # Model Architecture Details
228
+
229
+ Configuration:
230
+
231
+ | Parameter | Value |
232
+ |---|---:|
233
+ | Architecture | Transformer Encoder |
234
+ | Hidden Size | 256 |
235
+ | Transformer Layers | 8 |
236
+ | Attention Heads | 8 |
237
+ | Attention Head Dimension | 32 |
238
+ | Intermediate Size | 1024 |
239
+ | Maximum Sequence Length | 1536 |
240
+ | Vocabulary Size | 2560 |
241
+ | Parameters | ~8M |
242
+
243
+
244
+ Architecture:
245
+
246
+ ```
247
+
248
+ Token Embedding
249
+ |
250
+ Position Embedding
251
+ |
252
+ LayerNorm + Dropout
253
+ |
254
+ 8 Transformer Encoder Layers
255
+ |
256
+ LayerNorm
257
+ |
258
+ Contextual Token Representation
259
+
260
+ ```
261
+
262
+
263
+ ---
264
+
265
+ # Pretraining Objective
266
+
267
+ The model is pretrained using Masked Language Modeling (MLM).
268
+
269
+
270
+ During training:
271
+
272
+ 1. Nanopore electrical signals are converted into discrete tokens.
273
+ 2. Random tokens are masked.
274
+ 3. The Transformer predicts the original tokens using bidirectional context.
275
+
276
+
277
+ Example:
278
+
279
+ ```
280
+
281
+ Input:
282
+
283
+ A B [MASK] D E
284
+
285
+ Prediction:
286
+
287
+ C
288
+
289
+ ```
290
+
291
+
292
+ Training configuration:
293
+
294
+ | Parameter | Value |
295
+ |---|---:|
296
+ | MLM Probability | 0.15 |
297
+ | Optimizer | AdamW |
298
+ | Learning Rate | 8e-4 |
299
+ | Weight Decay | 0.01 |
300
+ | Adam beta1 | 0.9 |
301
+ | Adam beta2 | 0.98 |
302
+ | Precision | BF16 |
303
+ | Sequence Length | 1536 |
304
+
305
+
306
+ ---
307
+
308
+ # Learning Rate Schedule
309
+
310
+ The model uses:
311
+
312
+ ```
313
+
314
+ cosine_with_restarts
315
+
316
+ ```
317
+
318
+
319
+ Configuration:
320
+
321
+ | Parameter | Value |
322
+ |---|---:|
323
+ | Scheduler | cosine_with_restarts |
324
+ | Number of Cycles | 2 |
325
+ | Warmup Steps | 2000 |
326
+
327
+
328
+ The learning rate schedule consists of a warmup phase followed by cosine decay with restart cycles.
329
+
330
+
331
+ ---
332
+
333
+ # Usage
334
+
335
+ PoreBERT-DNA-VQI-256-526 operates on discrete signal tokens generated by the corresponding PoreCodec VQ tokenizer.
336
+
337
+
338
+ Pipeline:
339
+
340
+ ```
341
+
342
+ Nanopore Raw Signal
343
+
344
+ ```
345
+ |
346
+ v
347
+ ```
348
+
349
+ PoreCodec VQ Tokenizer
350
+
351
+ ```
352
+ |
353
+ v
354
+ ```
355
+
356
+ Discrete Token IDs
357
+
358
+ ```
359
+ |
360
+ v
361
+ ```
362
+
363
+ PoreBERT Encoder
364
+
365
+ ```
366
+ |
367
+ v
368
+ ```
369
+
370
+ Contextual Signal Embeddings
371
+
372
+ ````
373
+
374
+
375
+ ## Quick Start
376
+
377
+ ```python
378
+ import numpy as np
379
+ import torch
380
+
381
+ from transformers import AutoFeatureExtractor, AutoModel
382
+
383
+
384
+ codec_name = "ShuaiAnwo/pore-codec-rsq742c12a-511"
385
+ bert_name = "ShuaiAnwo/PoreBERT-DNA-VQI-256-526"
386
+
387
+
388
+ codec = AutoModel.from_pretrained(
389
+ codec_name,
390
+ trust_remote_code=True,
391
+ ).eval()
392
+
393
+
394
+ feature_extractor = AutoFeatureExtractor.from_pretrained(
395
+ codec_name,
396
+ trust_remote_code=True,
397
+ )
398
+
399
+
400
+ bert = AutoModel.from_pretrained(
401
+ bert_name,
402
+ ).eval()
403
+
404
+
405
+
406
+ raw_signal = np.random.normal(
407
+ 70,
408
+ 8,
409
+ 1855,
410
+ ).astype(np.float32)
411
+
412
+
413
+
414
+ with torch.no_grad():
415
+
416
+ # Raw signal -> VQ token IDs
417
+
418
+ signal = feature_extractor(
419
+ raw_signal,
420
+ return_tensors="pt",
421
+ )["signal"]
422
+
423
+
424
+ token_ids = codec.encode_signal(
425
+ signal,
426
+ layer=2,
427
+ )
428
+
429
+
430
+ # Token IDs -> contextual embeddings
431
+
432
+ outputs = bert(
433
+ input_ids=token_ids,
434
+ )
435
+
436
+
437
+ embeddings = outputs.last_hidden_state
438
+
439
+
440
+
441
+ print(
442
+ "Embedding shape:",
443
+ embeddings.shape
444
+ )
445
+ ````
446
+
447
+ Output:
448
+
449
+ ```
450
+ Embedding shape:
451
+
452
+ (batch_size, sequence_length, 256)
453
+ ```
454
+
455
+ The generated embeddings can be used for downstream nanopore sequencing tasks:
456
+
457
+ * Basecalling
458
+ * Modified base detection
459
+ * Signal representation learning
460
+ * Read-level embedding
461
+ * Sequence classification
462
+
463
+ ---
464
+
465
+ # Training Data
466
+
467
+ The model was pretrained on nanopore DNA sequencing token sequences.
468
+
469
+ Dataset:
470
+
471
+ ```
472
+ ShuaiAnwo/PoreDNA_S1_HG002_MOD_250F701901011_A50
473
+ ```
474
+
475
+ Training pipeline:
476
+
477
+ ```
478
+ Nanopore Electrical Signal
479
+
480
+ |
481
+ v
482
+
483
+ PoreCodec VQ Tokenizer
484
+
485
+ |
486
+ v
487
+
488
+ Discrete Token Sequence
489
+
490
+ |
491
+ v
492
+
493
+ Masked Language Modeling
494
+
495
+ |
496
+ v
497
+
498
+ PoreBERT Encoder
499
+ ```
500
+
501
+ ---
502
+
503
+ # Training Configuration
504
+
505
+ Training configuration from the original experiment:
506
+
507
+ ```yaml
508
+ model:
509
+ bert_model_type: electra
510
+ vocab_size: 2560
511
+ hidden_size: 256
512
+ num_hidden_layers: 8
513
+ num_attention_heads: 8
514
+ intermediate_size: 1024
515
+ max_position_embeddings: 1536
516
+
517
+
518
+ mlm_config:
519
+ mlm_probability: 0.15
520
+
521
+
522
+ optimizer:
523
+ name: adamw
524
+ learning_rate: 8.0e-4
525
+ weight_decay: 0.01
526
+ beta1: 0.9
527
+ beta2: 0.98
528
+
529
+
530
+ scheduler:
531
+ name: cosine_with_restarts
532
+ num_cycles: 2
533
+ t_warmup: 2000
534
+
535
+
536
+ precision:
537
+ amp_bf16
538
+ ```
539
+
540
+ ---
541
+
542
+ # Gradient Checkpointing
543
+
544
+ The training framework supports gradient checkpointing.
545
+
546
+ Gradient checkpointing reduces GPU memory usage by recomputing intermediate activations during backward propagation.
547
+
548
+ Benefits:
549
+
550
+ * Lower GPU memory consumption
551
+ * Longer sequence training
552
+ * Larger models on limited hardware
553
+
554
+ Trade-off:
555
+
556
+ * Increased training computation time
557
+
558
+ ---
559
+
560
+ # Limitations
561
+
562
+ * The model does not directly accept raw nanopore electrical signals.
563
+ * Raw signals must first be converted into VQ token IDs.
564
+ * Performance depends on tokenizer quality and training data distribution.
565
+ * The model is optimized for nanopore DNA sequencing representation learning.
566
+
567
+ ---
568
+
569
+ # Citation
570
+
571
+ Coming soon.
572
+
573
+ ---
574
+
575
+ # License
576
+
577
+ Please refer to the LICENSE file for usage conditions.
578
+
579
+ ```
580
+ ```