tf.random.learned_unigram_candidate_sampler
Stay organized with collections
Save and categorize content based on your preferences.
Samples a set of classes from a distribution learned during training.
tf.random.learned_unigram_candidate_sampler(
true_classes,
num_true,
num_sampled,
unique,
range_max,
seed=None,
name=None
)
This operation randomly samples a tensor of sampled classes
(sampled_candidates
) from the range of integers [0, range_max)
.
The elements of sampled_candidates
are drawn without replacement
(if unique=True
) or with replacement (if unique=False
) from
the base distribution.
The base distribution for this operation is constructed on the fly
during training. It is a unigram distribution over the target
classes seen so far during training. Every integer in [0, range_max)
begins with a weight of 1, and is incremented by 1 each time it is
seen as a target class. The base distribution is not saved to checkpoints,
so it is reset when the model is reloaded.
In addition, this operation returns tensors true_expected_count
and sampled_expected_count
representing the number of times each
of the target classes (true_classes
) and the sampled
classes (sampled_candidates
) is expected to occur in an average
tensor of sampled classes. These values correspond to Q(y|x)
defined in this
document.
If unique=True
, then these are post-rejection probabilities and we
compute them approximately.
Args |
true_classes
|
A Tensor of type int64 and shape [batch_size,
num_true] . The target classes.
|
num_true
|
An int . The number of target classes per training example.
|
num_sampled
|
An int . The number of classes to randomly sample.
|
unique
|
A bool . Determines whether all sampled classes in a batch are
unique.
|
range_max
|
An int . The number of possible classes.
|
seed
|
An int . An operation-specific seed. Default is 0.
|
name
|
A name for the operation (optional).
|
Returns |
sampled_candidates
|
A tensor of type int64 and shape [num_sampled] .
The sampled classes.
|
true_expected_count
|
A tensor of type float . Same shape as
true_classes . The expected counts under the sampling distribution
of each of true_classes .
|
sampled_expected_count
|
A tensor of type float . Same shape as
sampled_candidates . The expected counts under the sampling distribution
of each of sampled_candidates .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-03-17 UTC.
[null,null,["Last updated 2023-03-17 UTC."],[],[],null,["# tf.random.learned_unigram_candidate_sampler\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.9.3/tensorflow/python/ops/candidate_sampling_ops.py#L153-L211) |\n\nSamples a set of classes from a distribution learned during training.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.nn.learned_unigram_candidate_sampler`](https://www.tensorflow.org/api_docs/python/tf/random/learned_unigram_candidate_sampler)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.nn.learned_unigram_candidate_sampler`](https://www.tensorflow.org/api_docs/python/tf/random/learned_unigram_candidate_sampler), [`tf.compat.v1.random.learned_unigram_candidate_sampler`](https://www.tensorflow.org/api_docs/python/tf/random/learned_unigram_candidate_sampler)\n\n\u003cbr /\u003e\n\n tf.random.learned_unigram_candidate_sampler(\n true_classes,\n num_true,\n num_sampled,\n unique,\n range_max,\n seed=None,\n name=None\n )\n\nThis operation randomly samples a tensor of sampled classes\n(`sampled_candidates`) from the range of integers `[0, range_max)`.\n\nThe elements of `sampled_candidates` are drawn without replacement\n(if `unique=True`) or with replacement (if `unique=False`) from\nthe base distribution.\n\nThe base distribution for this operation is constructed on the fly\nduring training. It is a unigram distribution over the target\nclasses seen so far during training. Every integer in `[0, range_max)`\nbegins with a weight of 1, and is incremented by 1 each time it is\nseen as a target class. The base distribution is not saved to checkpoints,\nso it is reset when the model is reloaded.\n\nIn addition, this operation returns tensors `true_expected_count`\nand `sampled_expected_count` representing the number of times each\nof the target classes (`true_classes`) and the sampled\nclasses (`sampled_candidates`) is expected to occur in an average\ntensor of sampled classes. These values correspond to `Q(y|x)`\ndefined in [this\ndocument](http://www.tensorflow.org/extras/candidate_sampling.pdf).\nIf `unique=True`, then these are post-rejection probabilities and we\ncompute them approximately.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|------------------------------------------------------------------------------------|\n| `true_classes` | A `Tensor` of type `int64` and shape `[batch_size, num_true]`. The target classes. |\n| `num_true` | An `int`. The number of target classes per training example. |\n| `num_sampled` | An `int`. The number of classes to randomly sample. |\n| `unique` | A `bool`. Determines whether all sampled classes in a batch are unique. |\n| `range_max` | An `int`. The number of possible classes. |\n| `seed` | An `int`. An operation-specific seed. Default is 0. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `sampled_candidates` | A tensor of type `int64` and shape `[num_sampled]`. The sampled classes. |\n| `true_expected_count` | A tensor of type `float`. Same shape as `true_classes`. The expected counts under the sampling distribution of each of `true_classes`. |\n| `sampled_expected_count` | A tensor of type `float`. Same shape as `sampled_candidates`. The expected counts under the sampling distribution of each of `sampled_candidates`. |\n\n\u003cbr /\u003e"]]