PoreCodec-RSQ742C36A

PoreCodec-RSQ742C36A is a lightweight neural codec for nanopore electrical signals. It converts continuous ionic current measurements into discrete token sequences while preserving the original temporal resolution of the signal. The model combines a fully convolutional dilated encoder with a production-oriented Residual Finite Scalar Quantization (Residual FSQ) module to generate hierarchical discrete representations suitable for downstream foundation models.
Unlike conventional neural codecs that compress the temporal dimension, PoreCodec maintains a one-to-one correspondence between signal samples and latent tokens. Each input sample produces one discrete token, enabling accurate temporal alignment for biological sequence modeling, retrieval, and representation learning.
Instead of learned vector codebooks, the codec employs deterministic finite scalar quantization with exhaustive codebooks stored directly inside the model checkpoint, providing stable optimization, deterministic encoding, and constant-time decoding.
Highlights
- One token generated for every input signal sample
- Full-resolution temporal representation
- Five-layer dilated convolutional encoder and decoder
- Residual Finite Scalar Quantization (Residual FSQ)
- Exhaustive codebooks stored inside safetensors
- Constant-time O(1) decoding lookup
- Hierarchical discrete token generation
- HuggingFace AutoModel compatible
- End-to-end signal reconstruction
- Foundation-model ready discrete representation
Architecture
Raw Nanopore Signal
│
▼
Dilated CNN Encoder
│
▼
512-D Latent Features
│
▼
Linear Projection
│
▼
Residual Finite Scalar Quantization
│
├──────────────► Hierarchical Token IDs
│
▼
Quantized Latent Features
│
▼
Linear Projection
│
▼
Dilated CNN Decoder
│
▼
Reconstructed Signal
The model consists of three major components.
Dilated CNN Encoder
The encoder extracts local electrical signal patterns using a five-layer one-dimensional dilated convolutional network.
Unlike conventional neural codecs, the encoder does not perform temporal downsampling. Progressive dilation enlarges the receptive field while preserving the original sequence length, allowing every input signal sample to correspond to one latent representation.
| Property | Value |
|---|---|
| Input Channels | 1 |
| Output Channels | 512 |
| Downsampling Factor | ×1 |
| Receptive Field | 37 Samples |
| Architecture | Five-layer Dilated CNN |
Residual Finite Scalar Quantization
The latent representation is discretized using a production-oriented Residual Finite Scalar Quantization (Residual FSQ) module.
Instead of learning vector embeddings as in conventional VQ-VAE methods, PoreCodec performs deterministic scalar quantization over a finite Cartesian lattice.
Each residual stage progressively quantizes the remaining reconstruction error, producing increasingly accurate hierarchical representations.
Compared with learned vector quantizers, Residual FSQ provides:
- Deterministic encoding
- Stable optimization
- No codebook collapse
- No dead entries
- Constant-time decoding
- Exact lookup reconstruction
All exhaustive codebooks are precomputed and stored directly inside the model checkpoint.
Quantization Configuration
| Parameter | Value |
|---|---|
| Levels | 7 7 7 7 |
| Codebook Size | 2401 |
| Residual Quantizers | 2 |
| Quantization Type | Residual FSQ |
Hierarchical Tokens
Each latent position produces hierarchical residual quantization indices.
Latent Vector
↓
Residual Quantizer 1
↓
Residual Quantizer 2
↓
Residual Indices
↓
Unified Token ID
Supported hierarchy levels:
| layer | Description |
|---|---|
| 1 | First residual quantizer |
| 2 | First two residual quantizers |
| 0 | All available quantizers |
Since the encoder preserves the original temporal resolution, the number of generated tokens is identical to the number of input signal samples.
Signal Preprocessing
The accompanying FeatureExtractor automatically preprocesses raw nanopore electrical signals before inference.
Pipeline:
- Physical boundary correction
- Spike removal
- Median-MAD normalization
- Optional median filtering
- Smooth nonlinear clipping
Supported preprocessing strategies:
apple (default)
- Error repair
- Spike removal
- Median-MAD normalization
- Median filtering
- Smooth clipping
mongo
- Error repair
- Spike removal
- Median-MAD normalization
- Smooth clipping
Quick Start
import numpy as np
from transformers import AutoFeatureExtractor, AutoModel
model_name = "ShuaiAnwo/pore-codec-rsq742c36a-512"
feature_extractor = AutoFeatureExtractor.from_pretrained(
model_name,
trust_remote_code=True,
)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
)
model.eval()
raw_signal = np.random.normal(
loc=70,
scale=8,
size=1855,
).astype(np.float32)
signal = feature_extractor(
raw_signal,
return_tensors="pt",
)["signal"]
token_ids = model.encode_signal(
signal,
layer=2,
)
reconstructed = model.decode_token(
token_ids,
layer=2,
)
print(signal.shape)
print(token_ids.shape)
print(reconstructed.shape)
Expected output
torch.Size([1, 1, 1855])
torch.Size([1, 1855])
torch.Size([1, 1, 1855])
API Reference
encode_signal
Convert a normalized nanopore signal into unified discrete token IDs.
token_ids = model.encode_signal(
signal,
layer=2,
)
Returns
[B, N]
decode_token
Reconstruct normalized nanopore signals directly from unified token IDs.
signal = model.decode_token(
token_ids,
layer=2,
)
tokenize_indices
Convert hierarchical residual quantization indices into unified token IDs.
token_ids = model.tokenize_indices(
level_indices,
layer=2,
)
decode_indices
Reconstruct signals directly from hierarchical residual indices.
signal = model.decode_indices(
level_indices,
layer=2,
)
forward
Perform complete end-to-end encoding and decoding.
reconstruction, level_indices = model(signal)
Returns:
- Reconstructed signal
- Hierarchical residual indices
Temporal Alignment
Unlike conventional neural codecs that reduce temporal resolution, PoreCodec preserves the original signal length throughout the encoding pipeline.
For an input signal of length N, the model produces exactly N discrete tokens.
This one-to-one temporal correspondence simplifies downstream integration with biological foundation models, retrieval systems, sequence alignment algorithms, and multimodal learning pipelines.
Validation
The released checkpoint has been validated using the provided evaluation pipeline.
| Validation Item | Status |
|---|---|
| AutoConfig Loading | ✅ |
| AutoFeatureExtractor Loading | ✅ |
| AutoModel Loading | ✅ |
| End-to-End Encoding | ✅ |
| End-to-End Decoding | ✅ |
| Token Length = Signal Length | ✅ |
| Reconstruction Length = Signal Length | ✅ |
| Multi-layer Decoding | ✅ |
Model Configuration
| Parameter | Value |
|---|---|
| CNN Architecture | Five-layer Dilated CNN |
| CNN Output Dimension | 512 |
| Downsampling Factor | ×1 |
| Receptive Field | 37 |
| FSQ Levels | 7 7 7 7 |
| Residual Quantizers | 2 |
| Codebook Size | 2401 |
| Data Type | float32 |
Applications
PoreCodec is suitable for:
- Nanopore signal tokenization
- Biological signal representation learning
- Neural signal compression
- Nanopore foundation models
- Token-based biological language modeling
- Retrieval and indexing of nanopore reads
- Generative modeling over nanopore electrical signals
- Signal-to-token interfaces for multimodal biological AI
Advantages over Conventional VQ
| PoreCodec Residual FSQ | Conventional VQ |
|---|---|
| Deterministic encoding | Learned codebooks |
| No codebook collapse | Codebook collapse possible |
| No dead entries | Dead vectors possible |
| Stable optimization | Sensitive optimization |
| O(1) decoding lookup | Embedding search |
| Exhaustive finite lattice | Learned embeddings |
| Sample-level temporal alignment | Often temporally compressed |
Limitations
This model is designed for preprocessed nanopore electrical current signals using the accompanying FeatureExtractor.
The model produces discrete signal representations and signal reconstructions. It is not intended to perform direct DNA basecalling or nucleotide sequence prediction.
Citation
If you use PoreCodec in your research, please cite:
@misc{jiao2026porecodec,
title={PoreCodec: Residual Finite Scalar Quantization for Full-Resolution Nanopore Signal Tokenization},
author={Shuai Jiao},
year={2026}
}
License
This model is released under the Apache-2.0 License.