Bachelor’s Thesis · Build Log

From a Blank Repo to a Working Predictor

How the MIC prediction model was built, tested, and improved — every dataset, feature set, and experiment that got us from a first physicochemical baseline to the model running behind this site.

9 tracked model variants 114,881 activity records Frozen ESM2 protein LM
01 · Foundation

The data everything is built on

Every model in this project is trained on antimicrobial peptide activity measurements pulled from DBAASP, the Database of Antimicrobial Activity and Structure of Peptides.

114,881 Raw MIC activity records
103,613 Records with resolved Gram stain
75,224 Training rows
13,479 Held-out test rows

Sequences are matched to their target organism’s taxonomy (Phylum → Class → Order → Family → Genus) and Gram status, then de-duplicated by taking the median log-MIC per sequence–target pair. The regression target is log10(MIC), so a validation MAE of 0.39 corresponds to an average error of about 10^0.39 ≈ 2.4× in raw MIC — the scale used throughout this page.

02 · Feature Engineering

How the feature space grew

Each stage of the project added a new family of features on top of the last, rather than replacing it. The final production model combines all of them into a single 5,502-dimensional input vector.

1

Physicochemical descriptors

28 → 492 features

Started as 28 global descriptors from Biopython (amino-acid composition, molecular weight, pI, aromaticity, GRAVY, secondary-structure fractions). Later expanded via modlAMP and custom code to 492 columns: amino-acid fractions, terminal and windowed composition, hydrophobic-moment descriptors, and reduced-alphabet 2–3-mer motif counts (pos / neg / hyd / aro / pol / gly / pro).

2

Taxonomy & Gram context

344+ one-hot columns

One-hot encoded organism context — Phylum, Class, Order, Family, Genus, and Gram status — resolved from NCBI taxonomy lookups against each experiment’s target species. Unknown taxonomy gets its own explicit category rather than being dropped.

3

Engineered ratio features

9 features

Hand-designed ratios such as charge-per-length, hydrophobic-to-charge balance, Boman index per length, and moment balance — compact signals that helped the smaller baseline models before a protein language model was in the picture.

4

Frozen ESM2 embeddings

480-dim (or PCA-compressed)

Sequences are passed once through facebook/esm2_t12_35M_UR50D, a pretrained protein language model, with no fine-tuning. Per-residue outputs are mean-pooled into a single 480-dim vector and cached to disk so the transformer never has to run twice on the same sequence. A PCA-compressed variant reduces this block further for a cheaper, near-equivalent alternative.

03 · Timeline

How the model evolved, step by step

Ten tracked stages, from an empty repository to the model currently deployed on this site. Metrics are validation-split MAE and R² on log10(MIC), single-seed unless noted.

  1. Mar 2026 Stage 1 · Scaffolding

    Project structure & feature interfaces

    Data loaders, a sequence cleaner, and the first encoder interfaces (physicochemical, one-hot, Word2Vec, PLM placeholder) behind a shared BaseModel contract. No trained model yet — this stage built the scaffolding every later experiment reused.

  2. May 2026 Stage 2 · First baseline

    Physicochemical-only MIC baseline

    The first working regressor: 28 physicochemical descriptors, no organism context at all.

    Val MAE 0.504 Val R² 0.327
  3. May 2026 Stage 3 · Biological context

    + Taxonomy & Gram status

    Adding organism taxonomy and Gram status was the single biggest free win in the whole project — a large jump in validation R² before touching the model architecture at all.

    Val MAE 0.473 Val R² 0.390 −6% MAE · +19% R² vs. Stage 2
  4. Jun 3, 2026 Stage 4 · Infrastructure

    Shared experiment runner & model registry

    Refactored training and evaluation into one shared MIC runner plus a named model registry. Unglamorous, but this is what made the next dozen experiments cheap to run instead of copy-pasted scripts.

  5. Jun 18, 2026 Stage 5 · Gradient boosting

    XGBoost + richer sequence descriptors

    Expanded the descriptor set to 492 features (motif k-mers, windowed composition, autocorrelation) and trained XGBoost on top. It did not beat the much simpler Stage 3 baseline — an early lesson that more features and a stronger model aren’t automatically better on a noisy MIC target.

    Val MAE 0.502 Val R² 0.367
  6. Jun 20, 2026 Stage 6 · Protein language model

    Frozen ESM2 embeddings enter the picture

    Introduced facebook/esm2_t12_35M_UR50D as a frozen encoder and ran five parallel experiments to see how it behaved alone, regularized, and across model families.

    XGBoost + ESM2 + context MAE 0.490 · R² 0.387
    XGBoost + ESM2, feature-selected MAE 0.499 · R² 0.375
    XGBoost + ESM2, heavily regularized MAE 0.532 · R² 0.310 — underfit
    MLP + ESM2 + context MAE 0.465 · R² 0.419
    MLP, physicochemical only MAE 0.403 · R² 0.524

    Two findings survived this stage: an MLP squeezes more out of dense ESM2 embeddings than a tree model does, and frozen ESM2 alone still doesn’t beat hand-crafted physicochemical descriptors.

  7. Jun 20, 2026 Stage 7 · Best result Best validation score

    Physicochemical + ESM2 + taxonomy, combined

    Feeding physicochemical descriptors, frozen ESM2 embeddings, and taxonomy/Gram context into one regularized MLP produced the best validation result of the entire project — the PLM adds information on top of hand-crafted features, not instead of them.

    Val MAE 0.387 Val R² 0.552 ≈ 2.44× average MIC error
  8. Jul 15, 2026 Stage 8 · Deployed Running on this site

    PCA-compressed ESM2 variant

    Compressed the ESM2 block with PCA to cut dimensionality while keeping validation performance almost unchanged — a near-tie with Stage 7 at a fraction of the embedding size. This is the model this website calls to serve predictions.

    Val MAE 0.391 Val R² 0.541
  9. Jul 17, 2026 Stage 9 · In progress

    Huber-loss XGBoost + ESM2

    The most recent addition to the model registry: an XGBoost variant trained with a pseudo-Huber loss, aimed at making the tree-based branch more robust to MIC outliers. Results aren’t finalized yet.

  10. Jul 19, 2026 Stage 10 · Two-tower + uncertainty

    Two-tower deep model with calibrated confidence intervals

    A new architecture rather than a bigger MLP: a peptide tower (frozen esm2_t33_650M_UR50D, 14× larger than the ESM2 model used earlier, followed by a learnable Transformer encoder and attention pooling) combined with an organism tower (an FT-Transformer over species identity and numeric organism features). Trained on ~106k aggregated pairs, split by k-mer Jaccard clustering to keep near-duplicate sequences out of the test set. For the first time, the model outputs a calibrated 90% confidence interval alongside each point prediction, via one of two interchangeable heads.

    Gaussian head (NLL loss) MAE 0.576 · Spearman 0.449 · PICP 82.8%
    Quantile head (pinball loss) MAE 0.555 · Spearman 0.478 · PICP 75.9%

    Evaluated on a stricter, leakage-safe split than the random validation split used by earlier stages, so these numbers aren’t directly comparable to the MAE/R² chart below — see the dedicated section further down the page for the full breakdown.

04 · Results

Every model, side by side

Validation-split metrics for all nine tracked variants, in the order they were built. Shorter MAE bars and longer R² bars are better.

Validation MAE (log10 MIC · lower is better)

Validation R² (higher is better)

Model variant Best validation score Deployed on this site Underfit / regressed
05 · Interpretation

What the experiments actually showed

01

Hand-crafted descriptors are still strong

Physicochemical descriptors outperformed frozen ESM2 embeddings whenever each feature family was tested alone. Pretrained protein language models did not make domain expertise obsolete on this dataset.

02

ESM2 adds signal on top, not instead

Combining frozen ESM2 embeddings with physicochemical descriptors and taxonomy context beat either feature family alone — the best model in the project is the combined one, not the purely neural one.

03

A smaller train/val gap isn’t automatically better

Every time regularization was pushed harder to shrink the train–validation gap, validation error got worse, not better — a repeated underfitting trap rather than successful generalization.

06 · In production

The model answering predictions on this site

mlp_mic_physchem_esm2_pca_context_regularized Regularized MLP · physicochemical + PCA-compressed ESM2 + taxonomy/Gram context
Try the live predictor →
Hidden layers 192 → 96 → 48
Dropout 0.35
Weight decay 7×10−4
Best epoch 80 of 450 max, patience 30
Val MAE 0.391
Val R² 0.541

The non-PCA sibling (mlp_mic_physchem_esm2_context_regularized) scored marginally better on validation (MAE 0.387 vs. 0.391), but the PCA-compressed embedding keeps the served feature vector smaller for a near-identical result — the tradeoff chosen for this live demo.

07 · Latest experiment

Two-tower model with calibrated confidence intervals

The newest addition to the registry swaps the single MLP for a two-tower deep learning architecture and, for the first time, reports a calibrated 90% confidence interval alongside every point prediction — not just a single MIC estimate.

P

Peptide tower

Frozen ESM2-650M + Transformer

Uppercased sequences pass through a frozen esm2_t33_650M_UR50D protein language model (14× larger than the 35M-parameter model used earlier in the project) to get per-residue embeddings, then through a learnable Transformer encoder with attention pooling.

O

Organism tower

FT-Transformer

A Feature Tokenizer + Transformer jointly encodes species identity and numeric organism-level features, replacing the earlier one-hot taxonomy block with a learned representation.

Trained on ~106k aggregated (peptide, organism) pairs across 15 named species plus an “other” category, with replicate measurements combined by geometric mean in log-space. The train/test split uses k-mer Jaccard similarity clustering to keep near-duplicate sequences out of the test set — a stricter, leakage-safe split than the random validation split used earlier in the project, so its numbers aren’t directly comparable to the MAE/R² chart above.

Metric (held-out test) Gaussian head Quantile head
RMSE (log₁₀ MIC)0.7530.744
MAE0.5760.555
Pearson r0.4550.493
Spearman ρ0.4490.478
Within 2-fold34.3%37.8%
Within 4-fold61.8%65.1%
PICP (nominal 90%)82.8%75.9%
MPIW (interval width)1.9231.564
A

Quantile head wins on accuracy

The quantile head beats the Gaussian head on every point-prediction metric and produces narrower 90% intervals (1.56 vs. 1.92 log₁₀ units), at the cost of under-covering the nominal 90% target (75.9% vs. 82.8%). Both heads support post-hoc split-conformal calibration to correct this gap without retraining.

B

Organism biology still drives error

Gram-negative species (P. aeruginosa, A. baumannii, K. pneumoniae) get the best Spearman correlation (0.47–0.54), while the fungal C. albicans is the weakest (0.24–0.28) — the same pattern seen throughout the project.

C

D-peptides are the easiest group

D-amino acid peptides are predicted better than standard L-peptides (Spearman 0.55–0.57 vs. 0.46–0.49), likely because they cluster in a distinct MIC range; modified/X peptides remain the hardest group (Spearman 0.31–0.38).