Skip to content

Implement character-level GPT model from scratch#1

Draft
myz21 with Copilot wants to merge 3 commits into
mainfrom
copilot/build-character-level-gpt-model
Draft

Implement character-level GPT model from scratch#1
myz21 with Copilot wants to merge 3 commits into
mainfrom
copilot/build-character-level-gpt-model

Conversation

Copilot AI commented Feb 8, 2026

Copy link
Copy Markdown

Full PyTorch implementation of a character-level GPT transformer for text generation.

Architecture

  • model.py: Transformer components

    • Multi-head self-attention with causal masking
    • Residual blocks with LayerNorm
    • Position + token embeddings
    • Temperature and top-k sampling for generation
  • train.py: Training infrastructure

    • Character tokenizer (vocab built from input text)
    • AdamW optimizer with train/val split
    • Batch generation with configurable context window
  • example.py: Usage demonstrations

Usage

from train import train, generate_text

model, tokenizer = train(
    text,
    n_embd=384,
    num_heads=6,
    num_layers=6,
    block_size=256,
    max_iters=5000
)

generated = generate_text(
    model, tokenizer,
    prompt="Once upon",
    max_new_tokens=500,
    temperature=0.8,
    top_k=10
)

Configuration

Default hyperparameters suitable for ~10K character texts. Scale n_embd, num_layers, and block_size for larger datasets.

Original prompt

A character-level GPT model built from scratch.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Feb 8, 2026
Copilot AI and others added 2 commits February 8, 2026 13:23
Co-authored-by: myz21 <155391307+myz21@users.noreply.github.com>
Co-authored-by: myz21 <155391307+myz21@users.noreply.github.com>
Copilot AI changed the title [WIP] Add character-level GPT model implementation Implement character-level GPT model from scratch Feb 8, 2026
Copilot AI requested a review from myz21 February 8, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants