#include <candidate_sampling_ops.h>
Generates labels for candidate sampling with a learned unigram distribution.
A unigram sampler could use a fixed unigram distribution read from a file or passed in as an in-memory array instead of building up the distribution from data on the fly. There is also an option to skew the distribution by applying a distortion power to the weights.
The vocabulary file should be in CSV-like format, with the last field being the weight associated with the word.
For each batch, this op picks a single set of sampled candidate labels.
The advantages of sampling candidates per-batch are simplicity and the possibility of efficient dense matrix multiplication. The disadvantage is that the sampled candidates must be chosen independently of the context and of the true labels.
Arguments:
Optional attributes (see Attrs
):
Returns:
Output
sampled_candidates: A vector of length num_sampled, in which each element is the ID of a sampled candidate.Output
true_expected_count: A batch_size * num_true matrix, representing the number of times each candidate is expected to occur in a batch of sampled candidates. If unique=true, then this is a probability.Output
sampled_expected_count: A vector of length num_sampled, for each sampled candidate representing the number of times the candidate is expected to occur in a batch of sampled candidates. If unique=true, then this is a probability. Constructors and Destructors | |
---|---|
FixedUnigramCandidateSampler(const ::tensorflow::Scope & scope, ::tensorflow::Input true_classes, int64 num_true, int64 num_sampled, bool unique, int64 range_max) | |
FixedUnigramCandidateSampler(const ::tensorflow::Scope & scope, ::tensorflow::Input true_classes, int64 num_true, int64 num_sampled, bool unique, int64 range_max, const FixedUnigramCandidateSampler::Attrs & attrs) |
Public attributes | |
---|---|
operation | |
sampled_candidates | |
sampled_expected_count | |
true_expected_count |
Public static functions | |
---|---|
Distortion(float x) | |
NumReservedIds(int64 x) | |
NumShards(int64 x) | |
Seed(int64 x) | |
Seed2(int64 x) | |
Shard(int64 x) | |
Unigrams(const gtl::ArraySlice< float > & x) | |
VocabFile(StringPiece x) |
Structs | |
---|---|
tensorflow::ops::FixedUnigramCandidateSampler::Attrs | Optional attribute setters for FixedUnigramCandidateSampler. |
Operation operation
::tensorflow::Output sampled_candidates
::tensorflow::Output sampled_expected_count
::tensorflow::Output true_expected_count
FixedUnigramCandidateSampler( const ::tensorflow::Scope & scope, ::tensorflow::Input true_classes, int64 num_true, int64 num_sampled, bool unique, int64 range_max )
FixedUnigramCandidateSampler( const ::tensorflow::Scope & scope, ::tensorflow::Input true_classes, int64 num_true, int64 num_sampled, bool unique, int64 range_max, const FixedUnigramCandidateSampler::Attrs & attrs )
Attrs Distortion( float x )
Attrs NumReservedIds( int64 x )
Attrs NumShards( int64 x )
Attrs Seed( int64 x )
Attrs Seed2( int64 x )
Attrs Shard( int64 x )
Attrs Unigrams( const gtl::ArraySlice< float > & x )
Attrs VocabFile( StringPiece x )
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/cc/class/tensorflow/ops/fixed-unigram-candidate-sampler