Overview
Introduction
Strict n-grams miss word associations that are separated by an intervening word or two, which is exactly the gap that k-skip-n-grams were designed to capture in NLP research.
It runs entirely client-side, so nothing you paste is ever uploaded to a server.
What Is Text Skip-gram Generator?
A k-skip-n-gram generator that lists every word sequence of length N where up to K words may be skipped between the chosen words, preserving their original order, one skip-gram per line.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How Text Skip-gram Generator Works
The input is split into words, and for every starting word, the tool considers a window of the next N+K words and enumerates every way to choose N of them (starting with that anchor word) while keeping their relative order.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Text Skip-gram Generator
Use it to build training data for a skip-gram-based model like word2vec, or to capture word associations that a strict n-gram would miss due to an intervening word.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside Text N-gram Generator and String Bigram Generator.
Features
Advantages
- Captures word associations that span a small gap, unlike strict contiguous n-grams.
- Each combination is generated exactly once, anchored to its first word, avoiding duplicate output.
- Anchors every combination to its first word, so the same pairing is never emitted twice from two different starting positions.
Limitations
- Requires at least N words of input.
- The output size grows quickly with both N and K, since more combinations become valid.
Examples
Best Practices & Notes
Best Practices
- Start with a small K (1 or 2) since larger values quickly produce a much longer list of combinations.
- Check the output size before raising K, since the number of combinations grows sharply with each additional skip allowed.
- Strip stopwords first when the goal is capturing meaningful associations, because common words otherwise dominate the resulting pairs.
Developer Notes
The generator recursively extends a `chosen` index array within a window bounded by `Math.min(words.length - 1, anchor + n + k - 1)`, always starting the recursion from the `anchor` index so each combination is produced exactly once, during the iteration where `anchor` equals its first word's index, matching the standard k-skip-n-gram definition (e.g. Guthrie et al.).
Text Skip-gram Generator Use Cases
- Building training data for a skip-gram-based word embedding model
- Capturing word associations that span a small intervening gap
- Comparing skip-gram overlap between two texts for looser similarity scoring
Common Mistakes
- Setting K too high on a long text, producing an overwhelming number of combinations.
- Expecting K=0 to behave differently from a plain n-gram; it's mathematically identical.
Tips
- Compare the K=0 output to the Text N-gram Generator's output for the same N to see the baseline before adding skips.
- Setting K to 0 reduces the output to ordinary contiguous n-grams, which makes it easy to see exactly what the skips are adding.