|  View source on GitHub | 
Gets top unique elements from the input dataset.
tff.analytics.data_processing.get_top_elements(
    dataset: tf.data.Dataset,
    max_user_contribution: int,
    string_max_bytes: Optional[int] = None
)
This method returns the set of max_user_contribution elements that appear
most frequently in the dataset. Each word will only appear at most once in the
output.
This differs from get_top_multi_elements in that it returns a set rather
than a multiset.
The input dataset must yield batched rank-1 tensors. This function reads
each coordinate of the tensor as an individual element and caps the total
number of elements to return. Note that the returned set of top elements will
not necessarily be sorted.
| Args | |
|---|---|
| dataset | A tf.data.Datasetto extract top elements from. Element type must
betf.string. | 
| max_user_contribution | The maximum number of elements to keep. | 
| string_max_bytes | The maximum length (in bytes) of strings in the dataset.
Strings longer than string_max_byteswill be truncated. Defaults toNone, which means there is no limit of the string length. | 
| Returns | |
|---|---|
| A rank-1 Tensor containing the top max_user_contributionunique elements
of the inputdataset. If the total number of unique elements is less than
or equal tomax_user_contribution, returns the list of all unique
elements. | 
| Raises | |
|---|---|
| ValueError | -- If the shape of elements in datasetis not rank 1.
-- Ifmax_user_contributionis less than 1.
-- Ifstring_max_bytesis notNoneand is less than 1. | 
| TypeError | If dataset.element_spec.dtypemust betf.stringis nottf.string. |