Decoder only Transformer : Building a GPT-2 model prototype to make it understand Natural Language…

· Source: NLP on Medium · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering, Data Science & Analytics · Depth: Intermediate, medium

Summary

A prototype GPT-2 model, configured as a decoder-only Transformer, was developed and trained on a dataset of seven classic fiction novels from Project Gutenberg, including "Pride and Prejudice" and "Moby Dick." The training data was concatenated into a single file, separated by `<|endoftext|>` tokens. The model utilizes a 768-dimension token embedding vector, 12 attention heads, and 12 transformer blocks, with a vocabulary size of 50257 tokens. Training involved two configurations: one from scratch with random initial weights and another using pre-trained GPT-2 weights. The pre-trained initialization achieved a significantly lower validation loss of 3.99 (perplexity of 54) compared to the scratch-trained model's 5.12 (perplexity of 167), indicating better performance. Inference examples demonstrate the model's text generation capabilities using parameters like temperature and Top-K sampling.

Key takeaway

For AI Scientists and Machine Learning Engineers building custom language models, leveraging pre-trained weights for initialization significantly enhances model performance, as demonstrated by the perplexity reduction from 167 to 54. When curating training data, consider concatenating diverse texts with explicit separators like `<|endoftext|>` to maintain context boundaries. Experiment with inference parameters like temperature and Top-K sampling to control the creativity and determinism of generated text.

Key insights

Training a GPT-2 prototype on classic novels demonstrates decoder-only Transformer architecture and performance benefits of pre-trained weights.

Principles

Method

A GPT-2 prototype was built using a decoder-only Transformer architecture, trained on concatenated fiction novels, and evaluated with both random and pre-trained weight initialization using AdamW and CosineAnnealingLR.

In practice

Topics

Best for: AI Scientist, Machine Learning Engineer, AI Student

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by NLP on Medium.