liveBook · Manning

Skip-gram

As explained in Natural Language Processing in Action, Second Edition

Skip-gram is a word-embedding training approach that predicts surrounding or skipped words from a context word.

Skip-gram trains word embeddings by using a context word to predict words nearby or skipped within the same sentence. It reverses the prediction direction of continuous bag of words (CBOW): CBOW predicts a target from context, while skip-gram predicts context from a target. Both create many small training examples from sliding windows. section 6.3.2

A practical skip-gram pipeline proceeds as follows:

  • Collect domain text, such as medical journals, Wikipedia, or online news, because the corpus determines which word relationships the embeddings can learn. section 6.3.2
  • Tokenize and normalize the text; a space-delimited corpus can use lowercasing and split-based tokenization. section 6.3.3
  • Build a vocabulary and map each token to an integer so pairs can be encoded for the neural network. section 6.3.3

WikiText2 and a 10-token window

A runnable experiment loads 10,000 WikiText2 text rows, lowercases and splits each row, constructs a vocabulary, and generates pairs with WINDOW_WIDTH = 10. A Word2Vec model then maps vocabulary IDs into 100-dimensional vectors; the resulting dataset can be batched with DataLoader and trained on a CPU or available GPU.

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains prediction direction, window construction, vocabulary encoding, model layers, batching, and device selection, but does not detail optimization theory.
Examples
Uses WikiText2, lowercased token sequences, a ten-token window, vocabulary IDs, and 100-dimensional Word2Vec vectors.
What it assumes
Assumes basic neural-network and tensor familiarity while teaching corpus preparation, vocabulary construction, pair generation, and one-hot encoding.
What you can do after
Builds skip-gram embeddings from scratch with Python and PyTorch using tokenization, windowing, batching, and a Word2Vec model.
How it connects
Connects skip-gram with CBOW, Word2Vec, word embeddings, sliding windows, one-hot encoding, neural networks, and DataLoader.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.