DEV Community

George Panos
George Panos

Posted on

From Paper to Working Repo: Replicating an AI/ML Research Article Step‑by‑Step

If you want to move from “I read a lot of papers” to “I can build on top of them,” replicating a research article is one of the highest‑leverage skills you can develop. In this post, I’ll walk through a complete, practical workflow for turning a paper into a clean, reproducible repository—code, configs, tests, and all—plus how to turn that work into a strong dev.to article and portfolio piece.

Why replicate papers?
Replication is not just about matching numbers. It’s about building a mental model of how research becomes code.

You get:
Deeper understanding of architectures, losses, and training tricks that often stay hidden in dense notation.
Critical thinking about what’s essential vs. what’s just “paper polish.”

A reusable codebase you can extend, combine, or benchmark against your own ideas.
Strong portfolio content: a well‑documented “paper → repo” is far more compelling than yet another MNIST tutorial.
In short: if you can reliably go from paper to working repo, you’ve unlocked a permanent advantage as an AI/ML engineer or researcher.

Step 0 — Choose the right paper
Not all papers are equally beginner‑friendly to replicate.

A good “first replication” usually has:
A clear problem statement and well‑defined metrics (e.g., top‑1 accuracy, F1, BLEU).
Publicly available data or data you can reasonably obtain and preprocess.

An official implementation or at least one independent re‑implementation on GitHub / Papers with Code.
Manageable compute needs for your hardware (or a way to scale down without breaking the core idea).
If you’re new to this, consider:
Classic or widely cited methods in your area (e.g., a foundational transformer variant, a standard diffusion model, or a well‑known GNN).

Papers with:
Clear architecture diagrams
Explicit training details (optimizer, learning rate schedule, batch size, etc.)
Supplementary material or an appendix with extra hyperparameters
Avoid, at least initially:
Papers that rely on massive, proprietary datasets.
Methods that need huge clusters or specialized hardware unless you have access.
Articles with very vague descriptions and no code or community implementations.

Step 1 — Read the paper like an engineer

You’re not reading for a literature review; you’re reading to extract an implementation spec.
A practical reading order
Abstract + Conclusion
What is the main claim?
What gap does this method fill?
What are the reported limitations?
Data section
What are the inputs and outputs?
How is the data preprocessed?
How are train/val/test splits defined?
Are there any risks of data leakage or subtle preprocessing tricks?
Experiments / Results
Which baselines are used?
What metrics are reported?
Which tables/figures represent the “core result” you want to match?

Model architecture & training
Extract concrete details:

Layer types and ordering
Hidden dimensions, number of layers, attention heads, etc.
Activation functions, normalization type and placement
Loss function(s)
Optimizer, learning rate, schedule, weight decay, gradient clipping
Batch size, number of steps/epochs, warm‑up, etc.
Appendix / Supplementary material
This is often where the real implementation lives:
Extra hyperparameters
Architecture details omitted from the main text
Ablation studies that hint at what’s actually important
While reading: create a “living spec”
Use a doc (Notion, Obsidian, or a paper_notes.md in your repo) with three sections:
Spec
Equations rewritten in your own notation if needed
Tensor shapes at key points
Exact hyperparameters and training settings
Questions
Anything unclear or seemingly missing
Contradictions between sections
Context map
How this method compares to prior work
What it improves, and at what cost (compute, data, complexity)
This doc becomes the backbone of both your implementation and your eventual dev.to post.

Step 2 — Set up the repo before writing model code

Treat the repo as a research artifact, not a scratch directory. Future you—and your readers—will thank you.

Suggested structure
paper-replica/
├─ configs/
│ ├─ paper_default.yaml
│ └─ ablation_x.yaml
├─ data/
│ ├─ download.sh
│ └─ preprocess.py
├─ src/
│ ├─ models/
│ │ ├─ paper_model.py
│ │ └─ baselines.py
│ ├─ training.py
│ ├─ eval.py
│ └─ utils.py
├─ scripts/
│ ├─ train.sh
│ └─ eval.sh
├─ tests/
│ ├─ test_shapes.py
│ └─ test_repro.py
├─ results/
│ ├─ metrics/
│ │ ├─ paper_default_run1.json
│ │ └─ paper_default_run2.json
│ └─ figures/
│ ├─ learning_curve.png
│ └─ some_ablation.png
├─ README.md
├─ requirements.txt # or pyproject.toml
└─ paper_notes.md
Key ideas:
Configs separate from code
Every experiment should be reproducible by a single config file and a command.
Scripts encode exact commands
train.sh and eval.sh capture the precise CLI calls you used.
Tests from day one
Even simple shape checks will save you hours later.
Initialize version control early:
git init
git add .
git commit -m "Initial structure + paper notes"

Step 3 — Reproduce the data pipeline first

Most failed replications die in data, not models. Get the data pipeline right before you touch the architecture.
Checklist
Download script
Write download.sh (or equivalent) that:
Fetches the dataset from the official source
Verifies checksums if provided
Documents the dataset version and date
Preprocessing
Implement exactly what the paper describes:
Tokenization rules, vocabularies, special tokens
Image resizing, cropping, normalization, augmentations
Any filtering, cleaning, or sampling strategies
Logging dataset stats
Print and save:
Number of samples
Class distribution (for classification)
Sequence length distributions (for text)
Image size distributions (for vision)
Freeze the data version
In your README and paper_notes.md, note:
Dataset name and version
When you downloaded it
Any custom filtering or modifications
Add a small inspection script to visualize a few samples and confirm they match the paper’s description (input shapes, label format, etc.).

Step 4 — Implement the model architecture from the spec

Now translate your “model spec” into code. The goal is clarity first, optimization later.
Process
Start minimal
Implement the core architecture without:
Fancy logging
Mixed precision
Distributed training
Get a single forward pass working on dummy data.
Match shapes exactly
Use assertions in your forward() method:
assert x.shape == (B, C, H, W), f"Expected (B, C, H, W), got {x.shape}"
This catches shape mismatches early instead of silently producing wrong results.
Use tiny dummy inputs
Run with very small batches and sequence lengths to:
Verify shapes through every layer
Check that residuals and connections are wired correctly
Compare to references
If there’s an official repo or a “Papers with Code” implementation:
Compare layer ordering
Check normalization placement (pre‑norm vs post‑norm)
Confirm activation functions and residual connections
Common pitfalls
Off‑by‑one errors in layer counts or hidden dimensions.
Different default initialization than the paper assumes.
Subtle differences in attention masking, padding, or positional encodings.
Misinterpreting a diagram (e.g., thinking a block is repeated N times when it’s N−1).
Keep updating paper_notes.md with:
What you implemented
Any deviations from your initial spec
New questions that arise

Step 5 — Implement training and evaluation loops
Separate concerns cleanly:
training.py: dataset loading, optimizer, scheduler, loss, training loop
eval.py: metric computation, inference, and result logging
Training loop essentials
Seed everything
Set seeds for:
Python’s random
NumPy
Your ML framework (e.g., PyTorch, JAX, TensorFlow)
If relevant, GPU‑level seeds
Use the exact training settings from the paper
Optimizer type and hyperparameters
Learning rate and schedule (including warm‑up, cooldown, etc.)
Weight decay, gradient clipping, label smoothing, EMA, etc.
Log meaningful metrics
At least:
Training loss
Validation metric(s) reported in the paper
Optionally:
Learning rate over time
Gradient norms
Throughput (samples/sec)
Store logs in a structured way (JSON, CSV, or a lightweight experiment tracker).
Evaluation
Reproduce the paper’s evaluation protocol:
Same splits (train/val/test)
Same metric definitions and implementations
Same post‑processing (e.g., thresholding, NMS, beam search settings)
If the paper reports results over multiple runs or seeds, plan to run at least 2–3 seeds to estimate variance.
Organize results like this:
results/
├─ metrics/
│ ├─ paper_default_run1.json
│ ├─ paper_default_run2.json
│ └─ ablation_x_run1.json
└─ figures/
├─ learning_curve.png
└─ confusion_matrix.png

Step 6 — Try to match the reported numbers

This is where reality hits. You will almost never match the paper exactly on the first try.
If you’re close but not exact
Double‑check:
Random seeds and number of steps/epochs
Data preprocessing details (resize, crop, tokenization, normalization)
“Hidden” tricks in the appendix:
Gradient clipping values
Label smoothing
Exponential moving averages (EMA)
Special initialization schemes
Run small ablations:
Remove one new technique at a time to see its impact
Compare your baseline (without the paper’s key idea) to a known baseline
Document everything in paper_notes.md:
Your best metric vs. the paper’s
Hypotheses for remaining gaps
What you tried and what changed
If you’re far off
Re‑read the methods and appendix with your “questions” list in hand.

Search for:
Independent re‑implementations (blog posts, repos, videos)
Issues or discussions in the official repo
Consider reaching out:
Open a concise, polite issue on the official repo summarizing:
Your setup
Your results
Specific points of confusion
Or send a short email to the authors with the same info
Researchers often appreciate serious replication attempts and may share useful details that aren’t in the paper.

Step 7 — Add tests that encode your understanding

Tests turn your intuition into guarantees and make future extensions safer.
Useful test types
Shape tests
For each module, verify that given an input of shape X, the output has the expected shape Y.
Forward‑pass smoke tests
Tiny dataset, few steps: ensure the full training pipeline runs end‑to‑end without errors.
Metric sanity checks
On a synthetic dataset where you know the ground truth, ensure:
Accuracy behaves as expected
Loss decreases when the model is allowed to overfit a tiny set
Reproduction tests
For your best run, store:
Config
Seed
Expected metric range
Then assert that a small test run lands in that range.
These tests are invaluable when you:
Refactor code
Add new features
Try variations or ablations
Step 8 — Write a README that tells the story
Your README should let someone else reproduce your best run in minutes and understand what you did.

Include:
One‑sentence summary
Example:
“A minimal re‑implementation of [Paper Title], focusing on clarity and reproducibility.”
Key results
Your best metric vs. the paper’s reported metric
Any notable differences you observed
How to run

Example:
git clone
cd paper-replica
pip install -r requirements.txt
bash scripts/download_data.sh
bash scripts/train.sh
bash scripts/eval.sh
Config map
Which config file corresponds to which experiment (e.g., “paper_default.yaml” = main result, “ablation_no_xyz.yaml” = ablation without component XYZ).
Known differences from the paper
Where your results differ
Your hypotheses why (data, compute, missing details, etc.)
Links
Paper (arXiv/venue)
Official repo (if any)
“Papers with Code” page
This README becomes both documentation and a showcase for potential collaborators or employers.

Step 9 — Turn it into a dev.to post (and portfolio piece)

Once the repo is solid, write a post around it. This is where you convert hard‑won experience into visible expertise.

Possible angles
“From Paper to Working Repo: How I Replicated [Paper Name]”
Walk through the steps above with your concrete choices, pain points, and results.
“What Broke When I Tried to Reproduce [Method]”
Focus on mismatches, debugging stories, and lessons learned. Readers love honest “here’s where it went wrong” posts.
“A Minimal, Clean Re‑implementation of [Method]”
Emphasize:
Clear architecture
Tests
How the repo is organized for extensions and ablations
What to include in the post
A diagram of the architecture (even a simple one you draw yourself).
A table of your results vs. the paper’s.
A few code snippets:
The core layer or block
The training loop skeleton
An interesting utility function (e.g., a custom loss or metric)
Structure the article like a story:
Why you chose this paper
What you expected vs. what you found
Key challenges and how you solved them
Final results and open questions
Link to the repo and invitation for feedback or collaboration
A minimal template you can copy
You can start your next replication with this skeleton (adapt to your stack and language):

paper-replica/
├─ configs/
│ └─ default.yaml
├─ data/
│ ├─ download.sh
│ └─ preprocess.py
├─ src/
│ ├─ models/
│ │ └─ paper_model.py
│ ├─ training.py
│ └─ eval.py
├─ scripts/
│ ├─ train.sh
│ └─ eval.sh
├─ tests/
│ └─ test_shapes.py
├─ results/
├─ README.md
├─ requirements.txt
└─ paper_notes.md
From there, the workflow is:
Pick a paper
Write the spec
Build the data pipeline
Implement the model
Train and evaluate
Iterate to match numbers (or understand why you can’t)
Document everything
Share the repo and write a dev.to post

Top comments (0)