Skip to content

Four text-gen mini-demos: (1) a PyTorch char-level RNN built from scratch, (2) a toy GAN over characters, (3) GPT-2 sampling, and (4) T5-small translation — plus quick BLEU/ROUGE scoring with torchmetrics. Compact, educational, and easy to run.

Notifications You must be signed in to change notification settings

Joe-Naz01/pytorch_text_gem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Text Generation Demos (PyTorch + HF Transformers)

This notebook bundles four focused text-generation experiments:

  1. Char-RNN from scratch (PyTorch)

    • Custom RNNmodel using nn.RNNnn.Linear
    • Trains on a short text snippet (e.g., Alice-like sample)
    • Next-character prediction with cross-entropy
  2. Toy Character GAN

    • Generator and Discriminator are small nn.Sequential MLPs
    • Operate on the character vocabulary vector
    • Prints a few generated characters (illustrative, not SOTA)
  3. GPT-2 Free-form Sampling

    • GPT2Tokenizer, GPT2LMHeadModel
    • Generate with controls like temperature, top_k, top_p, no_repeat_ngram_size, max_length
  4. T5-Small Translation

    • T5Tokenizer, T5ForConditionalGeneration
    • Example prompt: translate English to French: 'Hello, ...'
  5. BLEU & ROUGE with torchmetrics

    • Quick, reference vs generated comparison to sanity-check outputs

Quickstart

# 1) Create & activate a virtual environment
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate

# 2) Install deps
pip install -r requirements.txt

# 3) Launch
jupyter lab  # or: jupyter notebook

4) Git clone
git clone https://github.com/Joe-Naz01/pytorch_text_gem.git
cd pytorch_text_gem

About

Four text-gen mini-demos: (1) a PyTorch char-level RNN built from scratch, (2) a toy GAN over characters, (3) GPT-2 sampling, and (4) T5-small translation — plus quick BLEU/ROUGE scoring with torchmetrics. Compact, educational, and easy to run.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published