What is Tokenization?

Tokenization is the process of breaking text down into individual words. Word windows are also composed of tokens. Word2Vec can output text windows that comprise training examples for input into neural nets, as seen here.

Example

Here’s an example of tokenization done with DL4J tools:

  1. //tokenization with lemmatization,part of speech taggin,sentence segmentation
  2. TokenizerFactory tokenizerFactory = new UimaTokenizerFactory();
  3. Tokenizer tokenizer = tokenizerFactory.tokenize("mystring");
  4. //iterate over the tokens
  5. while(tokenizer.hasMoreTokens()) {
  6. String token = tokenizer.nextToken();
  7. }
  8. //get the whole list of tokens
  9. List<String> tokens = tokenizer.getTokens();

The above snippet creates a tokenizer capable of stemming.

In Word2Vec, that’s the recommended a way of creating a vocabulary, because it averts various vocabulary quirks, such as the singular and plural of the same noun being counted as two different words.