agentleFS
orange4664orange4664/research-skills/code-writer/SKILL.md

code-writer

Skill41 starsChanged 8 months agoMITView on GitHub

Generate implementation code scaffolding from paper descriptions when no source code exists.

  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. SalehB1/shunt-anywhere★ 4same name
    2. melonkernel/shuntkit★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 11 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When a paper has no source code, this skill generates a complete project scaffolding with model, training, data loading, and evaluation …

    line 9
  2. Very specific:

    After paper-parser has extracted the paper content but paper-finder found no code

    line 14
  3. Distinctive:

    When reproducing a paper from scratch

    line 15
  4. Distinctive:

    Read the paper's experiment section for dataset details

    line 109
  5. Distinctive:

    Check normalization: [0,1] or [-1,1]?

    line 112
  6. Very specific:

    Use formula2code for any mathematical operations:

    line 126
  7. Distinctive:

    Check parameter count against paper (if reported)

    line 134
  8. Very specific:

    Use formula2code to convert the paper's loss equation

    line 137
  9. Distinctive:

    If it's a standard loss (CE, MSE, etc.), use PyTorch built-in

    line 138
  10. Distinctive:

    Add learning rate scheduler (check paper for warmup/cosine)

    line 143
  11. Distinctive:

    Add gradient clipping (if mentioned)

    line 144
  12. Distinctive:

    When stuck, the agent should fetch these URLs for guidance:

    line 211
  13. Distinctive:

    When modifying Jinja2 templates:

    line 226
  14. Distinctive:

    When implementing data loading:

    line 233

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code-Writer Skill

Purpose

When a paper has no source code, this skill generates a complete project scaffolding with model, training, data loading, and evaluation code — ready to fill in and run.

When to Use

  • Paper has no associated GitHub repository
  • User says "implement this paper" or "write code for this model"
  • After paper-parser has extracted the paper content but paper-finder found no code
  • When reproducing a paper from scratch

Prerequisites

  • Paper content (from paper-parser JSON/MD, or user description)
  • formula2code skill (for converting paper equations to code)
  • code-analyzer skill (for analyzing reference implementations)
  • paper-finder skill (for searching reference code)

Architecture

Paper Content (JSON/MD/description)
    │
    ▼
Phase 0: Reference Code Discovery ← KEY INNOVATION
    │  "Papers don't exist in a vacuum — find code for what they build on"
    │  → paper-finder: search for base methods' implementations
    │  → code-analyzer: analyze found repos for reusable components
    ▼
Phase 1: Paper Info Extraction
    │  → extractors/paper_info.py: title, abstract, sections
    │  → extractors/architecture.py: model components, layer types
    │  → extractors/equations.py: LaTeX formulas
    │  → extractors/experiment.py: hyperparameters, datasets, metrics
    ▼
Phase 2: Code Generation (with reference code guidance)
    │  → generate.py: fill templates with extracted info
    │  → formula2code: convert equations to loss/model code
    ▼
Phase 3: Output
    project/
    ├── configs/default.yaml        # Hyperparameters from paper
    ├── src/
    │   ├── model.py                # Architecture skeleton with TODOs
    │   ├── train.py                # Training loop (standard PyTorch)
    │   ├── data.py                 # Data loading skeleton
    │   └── evaluate.py             # (generated when metrics detected)
    ├── references/
    │   └── search_plan.md          # What code to search for
    ├── implementation_checklist.md  # Step-by-step guide
    ├── requirements.txt
    └── README.md

Usage

Quick Start

# From paper-parser JSON
python code-writer/generate.py --paper workspace/<paper>/paper_content.json -o workspace/<paper>/implementation/

# From markdown
python code-writer/generate.py --markdown workspace/<paper>/paper.md -o workspace/<paper>/implementation/

# From text description
python code-writer/generate.py --describe "A transformer-based model for image classification with self-attention" -o project/

Agent Workflow — How to Implement a Paper from Scratch

This is the most important section. Follow this methodology step by step.

Step 0: Reference Code Discovery (BEFORE writing any code)

The paper you're implementing is NOT invented from nothing. It builds on existing methods. Find their code first.

  1. Read the paper (from paper-parser output) and identify:
    • What base methods/architectures it uses (e.g., "extends ResNet", "uses Transformer encoder")
    • Which cited papers are most important (usually the "baseline" they compare against)
  2. Run generate.py to get the scaffold AND the references/search_plan.md
  3. Execute the search plan using paper-finder:
    paper-finder: search "ResNet PyTorch implementation" on GitHub
    paper-finder: search base paper on Papers With Code
  4. Clone & analyze the most relevant reference repo:
    git clone <reference_repo> workspace/<paper>/references/<name>
    code-analyzer: analyze workspace/<paper>/references/<name>
  5. Study the reference code — pay attention to:
    • How they implement the specific layers you need
    • Their training loop structure
    • Data preprocessing pipeline
    • Loss function implementation

Step 1: Data Pipeline (FIRST!)

Why first? Because wrong data = nothing else matters.
  1. Read the paper's experiment section for dataset details
  2. Implement src/data.py with actual data loading
  3. Verify: print(next(iter(loader))) should match expected shapes
  4. Check normalization: [0,1] or [-1,1]? ImageNet stats?

Step 2: Model Components (Bottom-Up)

Why bottom-up? Build small, test small, then compose.
  1. Implement each component as a separate nn.Module
  2. For each component:
    # Test with dummy tensor
    block = MyBlock()
    x = torch.randn(2, 64, 32, 32)  # (batch, channels, h, w)
    print(block(x).shape)  # Should match expected output
  3. Use formula2code for any mathematical operations:
    python formula2code/convert.py "<latex from paper>" --to pytorch -v

Step 3: Assemble Model

  1. Connect components in the main model class
  2. Verify: model(dummy_input).shape should match paper's output description
  3. Check parameter count against paper (if reported)

Step 4: Loss Function

  1. Use formula2code to convert the paper's loss equation
  2. If it's a standard loss (CE, MSE, etc.), use PyTorch built-in
  3. Verify: loss should be a scalar

Step 5: Training Loop

  1. The scaffold already generates a working loop — customize it:
    • Add learning rate scheduler (check paper for warmup/cosine)
    • Add gradient clipping (if mentioned)
    • Add evaluation loop
  2. Critical test: Overfit on 5 samples
    # If loss doesn't approach ~0, you have a bug
    python src/train.py --epochs 1000 --batch-size 5

Step 6: Evaluate & Compare

  1. Implement evaluation metrics from the paper
  2. Compare against paper's reported results (Table 1)

Common Pitfalls & Debugging Guide

ProblemSymptomFix
Wrong normalizationTraining doesn't convergeCheck if paper uses [0,1] or [-1,1]
Missing weight initPoor performanceCheck paper appendix for init method
Wrong norm layerNaN lossesBatchNorm vs LayerNorm matters!
No LR scheduleCan't match paper resultsAdd warmup + cosine decay
Wrong loss functionLoss doesn't decreaseVerify with formula2code
Dimension mismatchRuntime crashTest each component with dummy tensors

Dependencies

pip install -r code-writer/requirements.txt
# Requires: jinja2, pyyaml

Examples

See code-writer/examples/ for runnable demos:

ExampleWhat it Shows
01_generate_from_description.pyFull project generation from paper-like data
02_extractors_demo.pyEach extractor running independently

Quick Example: Architecture Detection

from extractors.architecture import extract_architecture

sections = [{'title': 'Method', 'content': 'We use a U-Net with self-attention...'}]
arch = extract_architecture(sections)
# → {'components': ['attention', 'unet'], 'architecture_type': 'attention'}

Quick Example: Hyperparameter Extraction

from extractors.experiment import extract_experiment

sections = [{'title': 'Experiments', 'content': 'Adam optimizer lr 1e-4, batch 64, 200 epochs on CIFAR-10'}]
exp = extract_experiment(sections)
# → {'hyperparameters': {'learning_rate': '1e-4', 'batch_size': '64', ...}, 'datasets': ['CIFAR-10']}

Quick Example: Reference Code Discovery

from extractors.reference_finder import find_reference_code

paper_info = {'title': 'My DDPM Paper', 'abstract': 'diffusion model using U-Net...', ...}
refs = find_reference_code(paper_info)
# → {'base_methods': ['U-Net', 'DDPM'], 'search_queries': [...], 'strategy': '...'}

📚 Reference URLs (for agent self-help)

When stuck, the agent should fetch these URLs for guidance:

TopicURL
Jinja2 template syntaxhttps://jinja.palletsprojects.com/en/3.1.x/templates/
PyYAML documentationhttps://pyyaml.org/wiki/PyYAMLDocumentation
PyTorch model best practiceshttps://pytorch.org/tutorials/beginner/introyt/modelsyt_tutorial.html
PyTorch training loophttps://pytorch.org/tutorials/beginner/introyt/trainingyt.html
PyTorch data loadinghttps://pytorch.org/tutorials/beginner/basics/data_tutorial.html
Papers With Code methodshttps://paperswithcode.com/methods
torchvision datasetshttps://pytorch.org/vision/stable/datasets.html
Hugging Face datasetshttps://huggingface.co/docs/datasets/
Common training recipeshttps://github.com/pytorch/examples

Template Customization Help

When modifying Jinja2 templates:

# Fetch Jinja2 template syntax docs:
fetch_url("https://jinja.palletsprojects.com/en/3.1.x/templates/")

Dataset Implementation Help

When implementing data loading:

# Fetch PyTorch data loading tutorial:
fetch_url("https://pytorch.org/tutorials/beginner/basics/data_tutorial.html")

# Fetch torchvision available datasets:
fetch_url("https://pytorch.org/vision/stable/datasets.html")

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.