【问题标题】:How to use event-by-event weights in Tensorflow?如何在 Tensorflow 中使用逐个事件的权重?
【发布时间】:2016-02-22 11:40:13
【问题描述】:

在我的数据集中,每个条目(事件)都有一个权重。这个权重由几个量组成,但基本上代表了这个事件对数据的重要性,必须加以考虑。

在 Tensorflow 中训练时如何使用此权重?我不想简单地将其用作另一个功能。

谢谢

【问题讨论】:

  • 这个其实很具体,给出一个问题,我想了解如何使用有问题的库。

标签: python machine-learning neural-network tensorflow deep-learning


【解决方案1】:

一个简单的解决方案是在计算小批量的总成本之前,将每个示例的计算成本乘以其权重。

假设您有以下内容:

# Vector of features per example.
x = tf.placeholder(tf.float32, shape=[batch_size, num_features])

# Scalar weight per example.
x_weights = tf.placeholder(tf.float32, shape=[batch_size])

# Vector of outputs per example.
y = tf.placeholder(tf.float32, shape=[batch_size, num_outputs])

# ...
logits = ...

# Insert appropriate cost function here.
cost = tf.nn.softmax_cross_entropy_with_logits(logits, y)

计算出的cost张量是一个长度为batch_size的向量。您可以简单地使用 x_weights 执行逐元素乘法以获得加权成本。

overall_cost = tf.mul(cost, x_weights) / batch_size

最后,您可以使用overall_cost 作为在您的optimizer 中最小化的值。

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    相关资源
    最近更新 更多