liveBook · Manning

Split

As explained in Deep Learning with R, Third Edition

Splitting is the segmentation of text into a sequence of individual tokens.

Splitting breaks text into small, individual units called tokens. It is a standard step in text preprocessing, alongside standardization and indexing, and prepares written language for conversion into numeric data. section 14.2 section 14.6

Split a sentence into words

Using stringr, define a function that detects word boundaries, preserves punctuation, removes whitespace, and returns tokens such as "The", "quick", "brown", and ".". The resulting tokens can then be matched against a vocabulary to obtain integer IDs. section 14.2

Choose the splitting unit according to the representation the model needs:

  • Character splitting returns each character, including spaces, as a separate token. section 14.2
  • Word splitting separates text at word boundaries; preserving punctuation requires retaining nonword elements and filtering out whitespace. section 14.2
  • Subword splitting is another major tokenization type and is usually the most effective when models have sufficient data and capacity. section 14.6
  • Regular expressions provide flexible character-pattern matching for more specialized splitting rules. section 14.2
library(stringr)
library(glue)
library(dplyr)
library(keras3)split_chars <- function(text) {
  unlist(str_split(text, boundary("character")))
}

Runnable R code defines character splitting with stringr and prepares the packages used by the text-preprocessing example. section 14.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains character and word splitting with runnable R functions, punctuation handling, regex context, and vocabulary indexing, but defers regex instruction.
Examples
Uses the sentence "The quick brown fox jumped over the lazy dog." to demonstrate character tokens, word tokens, punctuation, and vocabulary IDs.
What it assumes
Assumes basic text handling and introduces the need to turn written language into tokens and then integer data.
What you can do after
Apply splitting via stringr boundary functions to produce character or word tokens for later vocabulary indexing.
How it connects
Connects splitting to standardization, indexing, tokenization, regular expressions, character tokens, word tokens, subword tokens, and sequence order.

Also explained in

Compare how 11 books explain split →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.