<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/text/blob/v2.21.1/tensorflow_text/python/ops/whitespace_tokenizer.py#L44-L158) |

Tokenizes a tensor of UTF-8 strings on whitespaces.

Inherits From: [`TokenizerWithOffsets`](https://www.tensorflow.org/text/api_docs/python/text/TokenizerWithOffsets), [`Tokenizer`](https://www.tensorflow.org/text/api_docs/python/text/Tokenizer), [`SplitterWithOffsets`](https://www.tensorflow.org/text/api_docs/python/text/SplitterWithOffsets), [`Splitter`](https://www.tensorflow.org/text/api_docs/python/text/Splitter)

    text.WhitespaceTokenizer()

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Tokenizing with TF Text](https://www.tensorflow.org/text/guide/tokenizers) - [Converting TensorFlow Text operators to TensorFlow Lite](https://www.tensorflow.org/text/guide/text_tf_lite) | - [Private Heavy Hitters](https://www.tensorflow.org/federated/tutorials/private_heavy_hitters) |

## Methods

### `split`

[View source](https://github.com/tensorflow/text/blob/v2.21.1/tensorflow_text/python/ops/tokenization.py#L74-L76)

    split(
        input
    )

Alias for [`Tokenizer.tokenize`](https://www.tensorflow.org/text/api_docs/python/text/Tokenizer#tokenize).

### `split_with_offsets`

[View source](https://github.com/tensorflow/text/blob/v2.21.1/tensorflow_text/python/ops/tokenization.py#L152-L154)

    split_with_offsets(
        input
    )

Alias for [`TokenizerWithOffsets.tokenize_with_offsets`](https://www.tensorflow.org/text/api_docs/python/text/TokenizerWithOffsets#tokenize_with_offsets).

### `tokenize`

[View source](https://github.com/tensorflow/text/blob/v2.21.1/tensorflow_text/python/ops/whitespace_tokenizer.py#L55-L75)

    tokenize(
        input
    )

Tokenizes a tensor of UTF-8 strings on whitespaces.

The strings are split on ICU defined whitespace characters. These
whitespace characters are dropped.

#### Example:

    WhitespaceTokenizer().tokenize("small medium large")
    <tf.Tensor: shape=(3,), dtype=string, numpy=array([b'small', b'medium',
    b'large'], dtype=object)>

<br />

<br />

<br />

| Args ||
|---|---|
| `input` | A `RaggedTensor` or `Tensor` of UTF-8 strings with any shape. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `RaggedTensor` of tokenized text. The returned shape is the shape of the input tensor with an added ragged dimension for tokens of each string. ||

<br />

### `tokenize_with_offsets`

[View source](https://github.com/tensorflow/text/blob/v2.21.1/tensorflow_text/python/ops/whitespace_tokenizer.py#L77-L134)

    tokenize_with_offsets(
        input
    )

Tokenizes a tensor of UTF-8 strings on whitespaces.

The strings are split on ICU defined whitespace characters. These
whitespace characters are dropped.

#### Example:

    splitter = WhitespaceTokenizer()
    pieces, starts, ends = splitter.tokenize_with_offsets("a bb ccc")
    print(pieces.numpy(), starts.numpy(), ends.numpy())
    [b'a' b'bb' b'ccc'] [0 2 5] [1 4 8]

<br />

<br />

<br />

| Args ||
|---|---|
| `input` | A `RaggedTensor`or `Tensor` of UTF-8 strings with any shape. |

<br />

<br />

<br />

| Returns ||
|---|---|
| A tuple `(tokens, start_offsets, end_offsets)` where: <br /> - `tokens`: A `RaggedTensor` of tokenized text. - `start_offsets`: A `RaggedTensor` of the tokens' starting byte offset. - `end_offsets`: A `RaggedTensor` of the tokens' ending byte offset. ||

<br />