Carbon VEPor (Carbon powered Variant Effect Prediction (VEP) Engine)
Carbon powered Variant Effect Prediction (VEP) Engine
By utilizing an autonomous ML-Intern agent with NVIDIA's Nemotron-3-Nano-4B to build our script foundation and pairing it with MiniCPM-V-4.6 and Carbon-3B in a multi-stage production pipeline, we built an end-to-end machine learning system that transitions from raw sequence tokens to a production-ready classification head.
Link to space: https://huggingface.co/spaces/build-small-hackathon/carbon-vepor
The technical heavy lifting of setting up our data engineering pipelines was handled by an autonomous data-sourcing agent session (ML-Intern). Given a description of our task parameters, the agent operated within an isolated workspace sandbox to read the raw data and output our underlying script infrastructure:
+-------------------------------------------------------------------------+
| ML-INTERN AGENT WORKSPACE |
| |
| 1. Parses User Description |
| 2. Streams & Inspects Hugging Face Dataset (viveksil/clinvar-cls) |
| 3. Resolves Schema Anomalies & Data Splits |
| |
| โ โ |
| โผ (Code Generation) โผ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ |
| โ extract.py โ โ train.py โ |
| โ โ โ โ |
| โ - Carbon GGUF Logit Ingestionโ โ - PyTorch 3-Layer โ |
| โ - LLR Feature Array Creation โ โ MLP Framework โ |
| โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ |
+-------------------------------------------------------------------------+
viveksil/clinvar-cls genomic variant dataset directly from the Hugging Face Hub.extract.py (to handle sequence extraction and token math) and train.py (to setup and optimize the PyTorch classification head).The feature file written by the ML-Intern (extract.py) isolates a metric called the Log-Likelihood Ratio (LLR) using a local Carbon-3B model via native llama_cpp bindings. The LLR measures the specific statistical disruption caused by a nucleotide substitution variant.
To extract token-level log-probabilities from the model, genomic sequences are wrapped in <dna>...</dna> sequence boundaries. This enforces that Carbon's 6-mer tokenizer matches its pre-training tokenization offsets. For a single nucleotide variation fixed at base-index , the exact mutation coordinate is mapped to its relative token index via a shifting window calculation:
Base Sequence Index:
[0] ... [500] [501] [502] ...
โโโฌโโโโ โ
+5 Bases โ (Target Mutation Site)
โ โผ
โโโโโโโผโโโโโโโโโโโโโโโ
โ (501 + 5) // 6 = 84โ โโโบ Maps directly to Token Index: [84]
โโโโโโโโโโโโโโโโโโโโโโ
Running a forward pass with the model parameters configured to track all sequence probabilities (logits_all=True) exposes the raw output logit matrices.
The LLR represents the difference between the likelihood of seeing the alternate mutation under the mutated context versus the reference nucleotide under the wild-type context:
LLR_score with an engineered binary flag indicating whether the mutation falls in a functional protein-coding region (coding_flag). The resulting 2D matrix is saved to disk as a serialized PyTorch tensor (data/extracted_llr.pt).The model code written by the ML-Intern (train.py) sets up a downstream Classifier Head neural network to map the engineered LLR features directly to diagnostic labels.
Input Vector: [ LLR_score , coding_flag ] (Shape: 1x2)
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Linear Layer (2โ32) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ReLU โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Dropout (0.2) โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Linear Layer (32โ16) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ReLU โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Linear Layer (16โ1) โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
Raw Logit
The architecture consists of a compact 3-layer Multi-Layer Perceptron (MLP) optimized for binary classification:
[LLR_score, coding_flag]).Linear(2 โ 32) projection, a ReLU activation function, and a Dropout(p=0.2) layer to penalize co-adaptation of features. This is followed by a secondary Linear(32 โ 16) projection and another ReLU layer.Linear(16 โ 1) mapping layer yields a raw, unscaled pathogenicity logit.The training script loads the data engineered by the ML-Intern, enforces a reproducible $80/20$ train/validation split, and optimizes parameters across multiple epochs using the AdamW optimizer ,
The model tracks validation loss and ROC-AUC scores to evaluate performance. To preserve mathematical precision during backpropagation, a BCEWithLogitsLoss function is appliedโkeeping the sigmoid function out of the training loop graph and utilizing it strictly during the inference runtime.
The runtime production environment is tied together by a central coordinator (orchestrator.py). This script does not handle data building or training; instead, it coordinates our active model endpoints to execute live, multi-stage pipeline inference on incoming patient reports.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ User Uploads Clinical PDF Report โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STAGE 1: Document Parsing & Extraction โ
โ Model: MiniCPM-V (Vision) | Port: 8081 โ
โ โ
โ Input : Raw PDF Document Visual Stream โ
โ Action: Visual table parsing & structural pattern matching โ
โ Output: Structured JSON Data โ
โ { โ
โ "wild_type_sequence": "ATCG...", โ
โ "mutated_sequence": "ATGG...", โ
โ "is_coding": true โ
โ } โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STAGE 2: Genomic Language Scoring โ
โ Model: Carbon-3B (LLM via llama.cpp GGUF) | Port: 8082 โ
โ โ
โ Input : Sequences + Alignment Target (Token Index: 84) โ
โ Action: Extracts raw log-probabilities from token-level logits โ
โ Math : LLR = log_p(alt | mutated) - log_p(ref | wild-type) โ
โ Output: Compressed Feature Vector -> [ LLR_score , coding_flag ] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STAGE 3: Bare-Metal Classification Boundary โ
โ Engine: NumPy Head (carbon_backend.py) | Pure CPU Math โ
โ โ
โ Input : [ LLR_score , coding_flag ] โ
โ Action: Runs multi-layer perceptron forward pass using raw weight โ
โ tensors (W1, W2, W3) and biases loaded from PyTorch checkpoint.โ
โ Math : Sub-millisecond matrix dot products + explicit Sigmoid โ
โ Output: Pathogenicity Probability Score (Continuous scalar in [0, 1]) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STAGE 4: Clinical Report Synthesis โ
โ Model: MiniCPM-V (Text-Gen) | Port: 8081 โ
โ โ
โ Input : Extracted Variant Data + Pathogenicity Probability Score โ
โ Action: Autoregressive prompt engineering pass โ
โ Output: Finished Corporate Markdown Diagnostic Report โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Polished Clinical Report Rendered on UI Dashboard โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
wild_type_sequence, mutated_sequence) alongside the is_coding parameter.llama.cpp HTTP endpoints. The model isolates target token index and computes the mathematical LLR score.carbon_backend.py).During initialization, the production engine loads the raw weight tensors and bias vectors ) directly from the serialized checkpoint file (classifier_head.pt). The forward pass is then executed entirely through pure NumPy matrix dot-products and manual element-wise mathematical functions:
By shifting live production inference from heavy deep learning computation graphs to explicit CPU math operations, the final classification step runs faster, providing an instant binary probability mapping inside the dashboard.
Carbon powered Variant Effect Prediction (VEP) Engine
More from this author