How to Build a Tokenizer, Generative Python Transformer p.4

15.9K views
May 15, 2021
by
sentdex
YouTube video player
How to Build a Tokenizer, Generative Python Transformer p.4

TL;DR

Build a GPT-2 tokenizer by importing ByteLevelBPETokenizer, supplying one large text file or a list of files, and training a base tokenizer before loading it into the model-specific Hugging Face tokenizer. Byte-level BPE offers a relatively small vocabulary with complete text coverage, avoiding unknown tokens; the example uses a 52k vocabulary and discusses GPT-2’s 1024-token context. Read on for the workflow, configuration choices, and key tradeoffs.

Transcript

what is going on everybody and welcome to i think part four of the generative python transformers videos uh in this video what we're gonna be doing is building a tokenizer and so if you're a little unfamiliar with tokenizers we use them with natural language processing to convert strings of text because this is kind of unacceptable the machine does... Read More

Key Insights

  • 🎰 Tokenizers are used in natural language processing to convert text into machine-understandable representations.
  • 🛩️ Byte-level Byte-Pair Encoding (BPE) is a popular tokenization technique that offers a small vocabulary size and complete coverage.
  • 🚂 Training a tokenizer involves providing text data to create a vocabulary and encoding scheme.
  • 😷 The GPT-2 tokenizer handles special tokens like padding, unknown tokens, and masking to support various NLP tasks.
  • 🎚️ Different models, such as GPT-2 and BERT, can benefit from tokenization techniques like Byte-level BPE.
  • 🍵 Managing unknown tokens and handling large vocabulary sizes are common challenges in tokenization.
  • 👻 Tokenization allows for efficient processing and analysis of text data in machine learning models.

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do you build a tokenizer for a Generative Python Transformer?

Import ByteLevelBPETokenizer from the tokenizers package, create a list of paths to the training text, and initialize the byte-level BPE tokenizer. Train this base tokenizer first, then load it into the model-specific tokenizer intended for use through Hugging Face.

Q: Why is tokenization needed in natural language processing?

Machines do not directly understand strings of text in the form provided by people. Tokenization converts those strings into vectors of values that a model can accept as input.

Q: What is byte-level Byte-Pair Encoding?

Byte-level Byte-Pair Encoding represents text using smaller pieces rather than assigning every complete word its own arbitrary ID. The approach is used here because it can provide complete text coverage with a relatively small vocabulary and without unknown tokens.

Q: How does byte-level BPE differ from a bag-of-words tokenizer?

In a classic bag-of-words model, each word receives a unique arbitrary ID. Byte-level BPE instead works with smaller pieces that can be combined, reducing the need to place every possible string in the vocabulary.

Q: Why are unknown tokens a problem?

An unknown, or UNK, token is produced when text is not contained in the tokenizer’s vocabulary. The presenter says this makes learning difficult because the model will never really learn what a generic unknown token represents.

Q: Why not use a vocabulary of about 1 million entries?

A vocabulary of roughly 1 million avoids some coverage problems, but it creates a very large vector. The presenter explains that such a large representation is also difficult for the model to learn.

Q: What training data format does the tokenizer accept?

The tokenizer can train from one large file or from a list containing a cluster of files. According to the presenter, splitting the data into many smaller files does not appear to solve the memory problems encountered later.

Q: What GPT-2 tokenizer settings are discussed in the example?

The copied training configuration uses a vocabulary size of 52k and includes a minimum-frequency setting that the presenter guesses requires an item to occur twice. It also defines beginning-of-sentence and padding tokens; padding is needed because a neural network cannot take variable-length input, and GPT-2’s context length is described as 1024.

Summary & Key Takeaways

  • Tokenizers are used in natural language processing to convert strings of text into machine-understandable vectors of values.

  • Byte-level Byte-Pair Encoding (BPE) is a popular technique for tokenization, allowing for a smaller vocabulary size and complete coverage without unknown tokens.

  • The tutorial refers to the Hello World example from Hugging Face and explores the use of GPT-2 and BERT models.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from sentdex 📚