阅读(2513) (6)

TensorFlow函数:tf.nn.compute_accidental_hits

2018-12-04 11:17:32 更新

tf.nn.compute_accidental_hits函数

tf.nn.compute_accidental_hits(
    true_classes,
    sampled_candidates,
    num_true,
    seed=None,
    name=None
)

定义在:tensorflow/python/ops/candidate_sampling_ops.py.

请参阅指南:神经网络>候选抽样

计算与true_classes匹配的sampled_candidate中的位置id.

在Candidate Sampling中,此操作实际上有助于删除恰好与目标类匹配的抽样类.这在Sampled Softmax和Sampled Logistic中完成.

我们预先假定sampled_candidates是独一无二的.

当其中一个目标类与其中一个抽样类匹配时,我们将其称为“意外命中”.此操作将意外命中报告为三元组(index, id, weight),其中index表示true_classes中的行号,id表示sampled_candidates中的位置,权重为-FLOAT_MAX.

此op的结果应该通过一个sparse_to_dense操作来传递,然后添加到抽样类的logits中.这消除了意外采样真实目标类作为同一示例的噪声类的矛盾效果.

参数:

  • true_classes:一个Tensor,器类型为int64,并且形状为[batch_size, num_true];是目标类.
  • sampled_candidates:一个Tensor,类型为int64,并且形状为[num_sampled];CandidateSampler的sampled_candidates输出.
  • num_true:int,每个训练示例的目标类数.
  • seed:int,特定于操作的seed;默认值为0.
  • name:操作的名称(可选).

返回:

  • indices:一个Tensor,其类型为int32,并且形状为[num_accidental_hits];值表示true_classes中的行.
  • ids:一个Tensor,类型为int64,并且形状为[num_accidental_hits];值表示sampled_candidates中的位置.
  • weights:一个Tensor,其类型为float,并且形状为[num_accidental_hits];每个值都是-FLOAT_MAX.