CoolFace
Modelpublic

ShuaiAnwo/pore-codec-rsq542c12m-340

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
0likes15downloads
Model Card

license: apache-2.0 library_name: transformers tags:

  • —genomics
  • —nanopore
  • —signal-processing
  • —fsq
  • —vector-quantization
  • —nanopore-codec ---

PoreCodec-RSQ5x4x2-605261

PoreCodec is a high-performance, standardized neural tokenization ecosystem designed for raw nanopore electrical signals (squiggles).

pore-codec-rsq5x4x4-2605 represents the first-generation release featuring a Residual Finite Scalar Quantization (RSQ) architecture. It compresses high-frequency continuous electrical squiggles into discrete token IDs, acting as a critical bridge between raw genomic signals and generative language models (e.g., downstream Genomic Foundation Models or PoreGPT).

Model Architecture

The architecture consists of three interconnected blocks engineered for high-throughput genomic data:

  1. 1.Backbone (PoreCNNModel): A 1D Convolutional Neural Network optimized with standard receptive-field scaling. The encoder yields a downsampling factor (stride) of 4, compressing the raw signal length while capturing transient current alterations.
  2. 2.Quantizer (PoreResidualFSQ): A multi-codebook system deploying Finite Scalar Quantization (FSQ) with a straight-through estimator (STE).
  3. 3.Level Configuration: [5, 5, 5, 5] per quantizer layer ($5^4 = 625$ codebook size per layer).
  4. 4.Residual Depth: 2 layers of residual quantizers (x2), allowing coarse-to-fine signal discretization.
  5. 5.Outer Projection Layers: Fully tied linear projections (project_in and project_out) handling the dimensionality mapping seamlessly, keeping weight states native to safetensors.

Installation

Ensure you have transformers, torch, and einops installed in your environment:

bash
pip install torch transformers einops numpy


## Quick Start

Since this model is natively integrated with the Hugging Face `transformers` API via dynamic auto-class registration, you can initialize and load it directly with `trust_remote_code=True`.

### 1. Signal Tokenization (Encoding)

Convert continuous raw nanopore electrical currents into discrete token sequences:

import torch from transformers import AutoModel

1. Load Model with Auto-Class API

modelid = "ShuaiAnwo/pore-codec-rsq5x4x4-2605" model = AutoModel.frompretrained(modelid, trustremote_code=True) model.eval()

2. Prepare mock signal input [Batch, Channels (1), Signal_Length]

Imagine a raw squiggle vector padded/normalized

mockrawsignal = torch.randn(2, 1, 12000)

3. Tokenize signals down to discrete codebook IDs

Set layer=0 to collapse all residual quantizers, or select a specific depth

with torch.nograd(): tokenids = model.encodesignal(mockraw_signal, layer=0)

print("Encoded Token Shape:", tokenids.shape) # Expected: [2, 3000] (due to stride=4) print("Sample Tokens:", tokenids[0, :10])



### 2. Signal Reconstruction (Decoding)

Reconstruct the estimated continuous signal curve back from the discrete token IDs:

Reconstruct raw squiggles directly from tokens

with torch.nograd(): reconstructedsignal = model.decodetoken(tokenids, layer=0)

print("Reconstructed Signal Shape:", reconstructed_signal.shape) # Expected: [2, 1, 12000]


## Technical Specifications

| Parameter | Value | Description |
| :--- | :--- | :--- |
| **Stride / Downsample** | 4 | Downsampling factor of the CNN backbone |
| **FSQ Levels** | `5 5 5 5` | Codebook structure per residual layer |
| **Single Codebook Size** | 625 | Number of discrete items ($5^4$) per layer |
| **Num Quantizers** | 2 | Number of cascading residual quantization steps |
| **Effective Vocabulary** | $625^4$ | Theoretical total combination space |