Op@Operator(group="random") public final class UniformCandidateSampler extends PrimitiveOp
See explanations of candidate sampling and the data formats at go/candidate-sampling.
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.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
UniformCandidateSampler.Options |
Optional attributes for
UniformCandidateSampler |
operation| Modifier and Type | Method | Description |
|---|---|---|
static UniformCandidateSampler |
create(Scope scope,
Operand<java.lang.Long> trueClasses,
java.lang.Long numTrue,
java.lang.Long numSampled,
java.lang.Boolean unique,
java.lang.Long rangeMax,
UniformCandidateSampler.Options... options) |
Factory method to create a class to wrap a new UniformCandidateSampler operation to the graph.
|
Output<java.lang.Long> |
sampledCandidates() |
A vector of length num_sampled, in which each element is
the ID of a sampled candidate.
|
Output<java.lang.Float> |
sampledExpectedCount() |
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.
|
static UniformCandidateSampler.Options |
seed(java.lang.Long seed) |
|
static UniformCandidateSampler.Options |
seed2(java.lang.Long seed2) |
|
Output<java.lang.Float> |
trueExpectedCount() |
A batch_size * num_true matrix, representing
the number of times each candidate is expected to occur in a batch
of sampled candidates.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitequals, hashCode, toStringpublic static UniformCandidateSampler create(Scope scope, Operand<java.lang.Long> trueClasses, java.lang.Long numTrue, java.lang.Long numSampled, java.lang.Boolean unique, java.lang.Long rangeMax, UniformCandidateSampler.Options... options)
scope - current graph scopetrueClasses - A batch_size * num_true matrix, in which each row contains the
IDs of the num_true target_classes in the corresponding original label.numTrue - Number of true labels per context.numSampled - Number of candidates to randomly sample.unique - If unique is true, we sample with rejection, so that all sampled
candidates in a batch are unique. This requires some approximation to
estimate the post-rejection sampling probabilities.rangeMax - The sampler will sample integers from the interval [0, range_max).options - carries optional attributes valuespublic static UniformCandidateSampler.Options seed(java.lang.Long seed)
seed - If either seed or seed2 are set to be non-zero, the random number
generator is seeded by the given seed. Otherwise, it is seeded by a
random seed.public static UniformCandidateSampler.Options seed2(java.lang.Long seed2)
seed2 - An second seed to avoid seed collision.public Output<java.lang.Long> sampledCandidates()
public Output<java.lang.Float> trueExpectedCount()
public Output<java.lang.Float> sampledExpectedCount()