# tff.simulation.datasets.shakespeare.load_data

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Loads the federated Shakespeare dataset.

    tff.simulation.datasets.shakespeare.load_data(
        cache_dir: Optional[str] = None
    ) -> tuple[client_data.ClientData, client_data.ClientData]

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Federated Learning for Text Generation](https://www.tensorflow.org/federated/tutorials/federated_learning_for_text_generation) - [Private Heavy Hitters](https://www.tensorflow.org/federated/tutorials/private_heavy_hitters) |

Downloads and caches the dataset locally. If previously downloaded, tries to
load the dataset from cache.

This dataset is derived from the Leaf repository
(<https://github.com/TalwalkarLab/leaf>) pre-processing on the works of
Shakespeare, which is published in "LEAF: A Benchmark for Federated Settings"
<https://arxiv.org/abs/1812.01097>

The data set consists of 715 users (characters of Shakespeare plays), where
each
example corresponds to a contiguous set of lines spoken by the character in a
given play.

#### Data set sizes:

- train: 16,068 examples
- test: 2,356 examples

Rather than holding out specific users, each user's examples are split across
*train* and *test* so that all users have at least one example in *train* and
one example in *test*. Characters that had less than 2 examples are excluded
from the data set.

The `tf.data.Datasets` returned by
[`tff.simulation.datasets.ClientData.create_tf_dataset_for_client`](https://www.tensorflow.org/federated/api_docs/python/tff/simulation/datasets/ClientData#create_tf_dataset_for_client) will yield
`collections.OrderedDict` objects at each iteration, with the following keys
and values:

- `'snippets'`: a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with `dtype=tf.string`, the snippet of contiguous text.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `cache_dir` | (Optional) directory to cache the downloaded file. If `None`, caches in Keras' default cache directory. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Tuple of (train, test) where the tuple elements are [`tff.simulation.datasets.ClientData`](https://www.tensorflow.org/federated/api_docs/python/tff/simulation/datasets/ClientData) objects. ||

<br />