TL;DR
Standard word vector models give each word its own vector, so a rare word seen only a few times gets a poor vector and a word never seen gets none. This paper changes the skip-gram model (Skip-Gram Model) so that a word's vector is the sum of vectors for its character n-grams, short letter sequences of length 3 to 6. The authors report that training is about 1.5 times slower than the baseline, that the model gives vectors to unseen words, and that it beats the baselines on most word similarity datasets in nine languages and on syntactic analogy tests in four.
Builds on: Skip-Gram Model, Negative Sampling, Stochastic Gradient Descent, Word Embedding · Leads to: Subword Tokenization, word vector methods for morphologically rich languages
Why it mattered
Word vectors became a standard input for language systems, and this paper showed a cheap way to fix their biggest gap, rare words. The method is simple enough to train on a laptop-scale corpus, and the authors released a C++ implementation publicly, as the paper states, which made it easy for others to compare against. The idea that a word can be built from its pieces also fits the subword units that later language models use. The paper's related-work section already cites machine translation work on subword units.
The problem
A word vector model learns one vector per vocabulary word. The paper's introduction names the weakness: most methods "ignore the internal structure of words", which is a serious limitation for "morphologically rich languages, such as Turkish or Finnish". The paper gives a concrete picture: in French or Spanish most verbs have more than forty inflected forms, and Finnish has fifteen cases for nouns. Many of these forms are rare or absent from a training corpus, so each gets too little data to learn a good vector. Yet the forms share pieces, such as a verb stem and an ending, and the pieces follow rules.
The goal is therefore to share statistical strength across words through their shared pieces, and to give a vector to any word, including one never seen in training.
How it works
The paper keeps the skip-gram training procedure and changes one thing: how a word's vector is computed. Here is one word traced from start to finish.
- Start with a word. Take the word where and use character n-grams of length 3. (The paper uses all lengths from 3 to 6; length 3 keeps this example short.)
- Add boundary markers. Pad the word with a start marker and an end marker, written as the angle bracket characters, so the padded form is the word with a bracket in front and a bracket after. The markers tell a prefix apart from a letter sequence in the middle of a word.
- List the n-grams. Slide a window of length 3 across the padded word. You get the pieces that start with the start marker, the pieces in the middle, and the piece that ends with the end marker. The paper's example writes the five pieces as
<wh, whe, her, ere, re>. - Add the whole word. The paper also keeps the word itself as a special piece, so each word has its own vector too. This is one extra item on top of the five n-grams.
- Look up one vector per piece. Each n-gram
ghas a vectorz_g. The word's representation is the sum of its pieces' vectors. Suppose the first piece has vector (1, 0), the second has (0, 1), and the other pieces are zero for this check. The sum is (1, 1). - Score a context word. Skip-gram asks whether a context word
ctends to appear near the word. The score is the dot product of the summed word vector with the context vectorv_c. Withv_c= (2, 3), the score from the two pieces above is 1×2 + 1×3 = 5. - Train as usual. The score feeds the same logistic loss and negative sampling that skip-gram uses. The gradient flows into each n-gram vector, so a piece shared by many words gets many updates.
Two things follow from step 5. First, the piece for the short word her and the piece her inside where are different, because the boundary markers differ. Second, a word that never appeared in training still has pieces, and those pieces were learned from other words. So its vector is the sum of familiar pieces.
flowchart LR
W["word: where"] --> B["add boundary markers"]
B --> N["character n-grams 3 to 6, plus the whole word"]
N --> S["sum the n-gram vectors"]
S --> D["dot product with context vector"]
D --> L["logistic loss with negative samples"]
L --> U["update every n-gram vector"]
Worked examples
Take the word where with n-gram lengths 3 to 6.
- Write the padded word, which has 7 characters once the two markers are added.
- Length 3: start positions 0 to 4 give five pieces:
<wh,whe,her,ereandre>. - Length 4: start positions 0 to 3 give four pieces:
<whe,wher,hereandere>. - Length 5: start positions 0 to 2 give three pieces:
<wher,whereandhere>. - Length 6: start positions 0 and 1 give two pieces:
<whereandwhere>. - Add the whole word as its own piece. Total: 5 + 4 + 3 + 2 + 1 = 15 pieces.
Interpretation: a short word yields many overlapping pieces, and each piece is a shared unit that other words can also use.
Let the dimension be 2. Suppose a word has two n-grams, with vectors (1, 0) and (0, 1), and the context vector is (2, 3).
- Sum the n-gram vectors: (1, 0) + (0, 1) = (1, 1). This is the word's vector.
- Take the dot product with the context vector: (1, 1) · (2, 3) = 1 × 2 + 1 × 3 = 5.
- The score is 5. The logistic loss for a true pair is log(1 + e^(−5)), which is about 0.007, so this pair is already well predicted.
- Change the context vector to (−1, 0). The score becomes 1 × (−1) + 1 × 0 = −1. The loss for a true pair rises to log(1 + e) ≈ 1.31, so training would push the vectors apart.
Interpretation: the score is a sum over pieces, so a change to one piece changes every word that contains it.
The paper uses Czech and Russian as its morphologically rich examples. Table 5 gives test perplexity (lower is better) for a language model that starts from pre-trained vectors. For Czech, the skip-gram vectors give 339 and the subword vectors give 312. For Russian, skip-gram gives 237 and subword gives 206.
- Czech reduction: 339 − 312 = 27.
- Relative Czech reduction: 27 / 339 ≈ 0.080, which is about 8%. The paper reports 8%.
- Russian reduction: 237 − 206 = 31.
- Relative Russian reduction: 31 / 237 ≈ 0.131, which is about 13%. The paper reports 13%.
- The paper says the gain is smaller for Spanish (3%) and French (2%), which fits its claim that the gain is largest for rich morphology.
Try it: for Spanish, skip-gram gives 150 and subword gives 145. What is the relative reduction, and does it match the paper's 3%? Answer: 5 / 150 ≈ 0.033, which is about 3%, so it matches.
The math
The paper first states the baseline skip-gram objective, then changes only the scoring function.
Step 1 in symbols: the skip-gram objective
Given a corpus of words , skip-gram maximises the log-likelihood . Here is the set of positions near position , and is the word at a context position .
A full softmax over the vocabulary of size would normalise over every word. The paper instead treats each context word as an independent yes-or-no question. For a context word it uses the logistic loss on the score of the true pair, and the same loss on the negative sampled words with flipped sign:
Here is a set of negative samples drawn at random from the dictionary.
Step 5 in symbols: the subword score
The new scoring function is
where is the set of n-grams of word (including the whole word), is the vector of n-gram , and is the output vector of the context word. The scalar is the dot product. The sum over is step 5 of the walkthrough, and the dot product is step 6.
The paper hashes n-grams into a fixed number of buckets, , to bound memory. Several n-grams can then share a bucket, which is a trade-off the paper accepts for a fixed memory size.
Step 7 in symbols: the step size
The paper uses plain stochastic gradient descent (Stochastic Gradient Descent) with a step size that falls linearly over training. With words per pass, passes and a starting step , the step at time is
so the step is at the start and falls to zero at the end. The paper sets for the skip-gram baseline and for its model and the CBOW baseline.
Results
Table 1 reports the correlation between model similarity scores and human judgements, using Spearman's coefficient as the paper does. On German Gur350 the skip-gram baseline gets 61 and the subword model gets 70. On Russian HJ the scores are 59 and 66. Table 2 reports analogy accuracy: on Czech syntactic analogies the skip-gram baseline gets 52.8 and the subword model gets 77.8. The gains are not uniform. On German semantic analogies the subword model is lower, 62.3 against 66.5 for skip-gram. The paper ties this to the n-gram length it chose, and Table 4 shows that the best range depends on the task.
With little data the model still holds up. Trained on 5% of Wikipedia, the subword model reaches 66 on German Gur350, above the CBOW baseline trained on the full corpus, which gets 62. On English RW, 1% of the corpus gives 45 against 43 for CBOW on the full corpus. The paper calls this a practical advantage for small or specialised datasets.
The limits matter as much as the wins. It is tempting to think that the subword model replaces the whole word with its pieces. In fact the paper keeps the whole word as one extra piece, so that each word still has a representation of its own in addition to its n-grams. The pieces are added to the word, not used instead of it.
It is also tempting to think that more n-grams always help. The paper's experiment on n-gram length (Table 4) shows that the best range depends on language and task. The authors chose 3 to 6 arbitrarily, and they say a proper validation procedure was not used because test data was scarce. Longer n-grams help German compounds, while very short ones (length 2) are not informative for analogy tasks.
The model also does not help everywhere. On the English WS353 similarity set, the paper's model does not beat the baseline, because those words are common enough that good vectors come without subwords. The gain is largest for rare words and for languages with many forms.
Reading guide
The paper is short, so read it with its prerequisites at hand.
- Section 1 and 2 (Introduction, Related work): the problem of one vector per word, and the earlier morphology methods. Needs Word Embedding and N-gram Language Model.
- Section 3 (Model): the skip-gram objective and the subword score. Needs Skip-Gram Model, Negative Sampling, Softmax (the rejected alternative in 3.1) and Logistic Regression (the binary loss). Section 3.2 also uses Hash Function for the bucket scheme.
- Section 4 (Experimental setup): training details. Needs Stochastic Gradient Descent for the step size.
- Section 5 (Results): similarity uses Cosine Similarity between vectors. The language model experiment in 5.6 uses Recurrent Neural Network and Perplexity.
- Section 6 (Qualitative analysis): the n-gram importance test in 6.2 and the nearest-neighbour tables. No new lesson needed.
- Section 7 (Conclusion): the summary. Read it last.
Check yourself
QuestionHow many character n-grams of length 3 does the word where have under the paper's rule, once boundary markers are added, and what are they?Show answer
Five: the padded word has 7 characters, so a window of length 3 has 7 − 3 + 1 = 5 start positions. The pieces are the start-marked piece, three middle pieces, and the end-marked piece.
QuestionA word has n-gram vectors (2, 0), (0, 2) and (1, 1). The context vector is (1, 4). What is the score under the paper's model?Show answer
The summed word vector is (2 + 0 + 1, 0 + 2 + 1) = (3, 3). The dot product with (1, 4) is 3 × 1 + 3 × 4 = 15.
QuestionWhy can the subword model give a vector to a word that never appeared in training?Show answer
The word is built from its n-grams, and those n-grams were learned from other words. The new word's vector is the sum of familiar pieces, so it is not empty.
QuestionTable 5 gives Czech perplexity of 339 for skip-gram and 312 for subword vectors. What is the relative reduction, to the nearest whole percent?Show answer
The reduction is 27. Then 27 / 339 ≈ 0.0796, which rounds to 8%.
QuestionScenario: a team builds word vectors for a small corpus of product reviews in English, where most words are common. Would the subword model be the best choice, and why?Show answer
Probably not as the main gain. The paper shows that on common English words the subword model does not beat the baseline, because good vectors come without subwords. The subword model helps most for rare words and rich morphology, so the team would see little benefit on common English vocabulary.
Sources
- Bojanowski, P., Grave, E., Joulin, A., and Mikolov, T. Enriching Word Vectors with Subword Information. arXiv:1607.04606. https://arxiv.org/abs/1607.04606
- Bojanowski, P., Grave, E., Joulin, A., and Mikolov, T. Enriching Word Vectors with Subword Information. Transactions of the Association for Computational Linguistics, doi:10.1162/tacl_a_00051. https://doi.org/10.1162/tacl_a_00051