<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/transform/blob/v1.21.0/tensorflow_transform/mappers.py#L1786-L1836) |

Find the token count of each document/row.

    tft.word_count(
        tokens: Union[tf.SparseTensor, tf.RaggedTensor], name: Optional[str] = None
    ) -> tf.Tensor

`tokens` is either a `RaggedTensor` or `SparseTensor`, representing tokenized
strings. This function simply returns size of each row, so the dtype is not
constrained to string.

#### Example:

*** ** * ** ***

    >>> sparse = tf.SparseTensor(indices=[[0, 0], [0, 1], [2, 2]],
    ...                          values=['a', 'b', 'c'], dense_shape=(4, 4))
    >>> tft.word_count(sparse)
    <tf.Tensor: shape=(4,), dtype=int64, numpy=array([2, 0, 1, 0])>

<br />

<br />

<br />

| ## Args ||
|---|---|

<br />

*** ** * ** ***

tokens: either
(1) a `SparseTensor`, or
(2) a `RaggedTensor` with ragged rank of 1, non-ragged rank of 1
of dtype [`tf.string`](https://www.tensorflow.org/api_docs/python/tf#string) containing tokens to be counted
name: (Optional) A name for this operation.

<br />

<br />

<br />

| ## Returns ||
|---|---|

<br />

*** ** * ** ***

A one-dimensional `Tensor` the token counts of each row.

<br />

<br />

<br />

| ## Raises ||
|---|---|

<br />

*** ** * ** ***

ValueError: if tokens is neither sparse nor ragged