tf.nn.compute_accidental_hits
Stay organized with collections
Save and categorize content based on your preferences.
Compute the position ids in sampled_candidates
matching true_classes
.
tf.nn.compute_accidental_hits(
true_classes, sampled_candidates, num_true, seed=None, name=None
)
In Candidate Sampling, this operation facilitates virtually removing
sampled classes which happen to match target classes. This is done
in Sampled Softmax and Sampled Logistic.
See our Candidate Sampling Algorithms
Reference.
We presuppose that the sampled_candidates
are unique.
We call it an 'accidental hit' when one of the target classes
matches one of the sampled classes. This operation reports
accidental hits as triples (index, id, weight)
, where index
represents the row number in true_classes
, id
represents the
position in sampled_candidates
, and weight is -FLOAT_MAX
.
The result of this op should be passed through a sparse_to_dense
operation, then added to the logits of the sampled classes. This
removes the contradictory effect of accidentally sampling the true
target classes as noise classes for the same example.
Args |
true_classes
|
A Tensor of type int64 and shape [batch_size,
num_true] . The target classes.
|
sampled_candidates
|
A tensor of type int64 and shape [num_sampled] .
The sampled_candidates output of CandidateSampler.
|
num_true
|
An int . The number of target classes per training example.
|
seed
|
An int . An operation-specific seed. Default is 0.
|
name
|
A name for the operation (optional).
|
Returns |
indices
|
A Tensor of type int32 and shape [num_accidental_hits] .
Values indicate rows in true_classes .
|
ids
|
A Tensor of type int64 and shape [num_accidental_hits] .
Values indicate positions in sampled_candidates .
|
weights
|
A Tensor of type float and shape [num_accidental_hits] .
Each value is -FLOAT_MAX .
|
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-10-06 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[],[],null,["# tf.nn.compute_accidental_hits\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/candidate_sampling_ops.py#L466-L513) |\n\nCompute the position ids in `sampled_candidates` matching `true_classes`.\n\n#### View aliases\n\n\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.compute_accidental_hits`](https://www.tensorflow.org/api_docs/python/tf/nn/compute_accidental_hits)\n\n\u003cbr /\u003e\n\n tf.nn.compute_accidental_hits(\n true_classes, sampled_candidates, num_true, seed=None, name=None\n )\n\nIn Candidate Sampling, this operation facilitates virtually removing\nsampled classes which happen to match target classes. This is done\nin Sampled Softmax and Sampled Logistic.\n\nSee our [Candidate Sampling Algorithms\nReference](http://www.tensorflow.org/extras/candidate_sampling.pdf).\n\nWe presuppose that the `sampled_candidates` are unique.\n\nWe call it an 'accidental hit' when one of the target classes\nmatches one of the sampled classes. This operation reports\naccidental hits as triples `(index, id, weight)`, where `index`\nrepresents the row number in `true_classes`, `id` represents the\nposition in `sampled_candidates`, and weight is `-FLOAT_MAX`.\n\nThe result of this op should be passed through a `sparse_to_dense`\noperation, then added to the logits of the sampled classes. This\nremoves the contradictory effect of accidentally sampling the true\ntarget classes as noise classes for the same example.\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| `sampled_candidates` | A tensor of type `int64` and shape `[num_sampled]`. The sampled_candidates output of CandidateSampler. |\n| `num_true` | An `int`. The number of target classes per training example. |\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| `indices` | A `Tensor` of type `int32` and shape `[num_accidental_hits]`. Values indicate rows in `true_classes`. |\n| `ids` | A `Tensor` of type `int64` and shape `[num_accidental_hits]`. Values indicate positions in `sampled_candidates`. |\n| `weights` | A `Tensor` of type `float` and shape `[num_accidental_hits]`. Each value is `-FLOAT_MAX`. |\n\n\u003cbr /\u003e"]]