【问题标题】:What is this line of Theano doing?Theano 的这一行在做什么?
【发布时间】:2016-12-01 21:39:42
【问题描述】:

我不明白我们是否正在迭代 y,因为看起来对 y 中的值做了什么?它们是 T.log 的一部分吗?它们是否以某种方式与 p_y_given_x 相结合?

result = -T.mean(T.log(p_y_given_x)[T.arange(y1.shape[0]), y1])
print ("result1", result.eval())


print("_________________________")
print("y ", y2)
print("y.shape[0] ", y2.shape[0])

temp =  (y2.shape[0], y2)
print("y.shape[0], y", temp)

temp2 = [T.arange(2), y2]
print("T.arange(y rows)", T.arange(2).eval())
print("[t.arange(2), y]    [[0, 1], [1, 2]]")
print("T.log(p_y_given_x) ", (T.log(p_y_given_x)).eval())
print(-T.mean(T.log(p_y_given_x)).eval())
print("#########################")


result1 1.022485096286888
_________________________
y  <TensorType(int64, matrix)>
y.shape[0]  Subtensor{int64}.0
y.shape[0], y (Subtensor{int64}.0, <TensorType(int64, matrix)>)
T.arange(y rows) [0 1]
[t.arange(2), y]    [[0, 1], [1, 2]]
T.log(p_y_given_x)  [[-1.11190143 -0.91190143 -1.31190143]
 [-1.13306876 -1.03306876 -1.13306876]]
1.10581842962
#########################

【问题讨论】:

    标签: python neural-network theano


    【解决方案1】:

    我没有足够的声誉来发表评论,所以我会发布这个作为答案。

    逐字引用here

    y.shape[0] is (symbolically) the number of rows in y, i.e.,
    number of examples (call it n) in the minibatch
    T.arange(y.shape[0]) is a symbolic vector which will contain
    [0,1,2,... n-1] T.log(self.p_y_given_x) is a matrix of
    Log-Probabilities (call it LP) with one row per example and
    one column per class LP[T.arange(y.shape[0]),y] is a vector
    v containing [LP[0,y[0]], LP[1,y[1]], LP[2,y[2]], ...,
    LP[n-1,y[n-1]]] and T.mean(LP[T.arange(y.shape[0]),y]) is
    the mean (across minibatch examples) of the elements in v,
    i.e., the mean log-likelihood across the minibatch.
    

    y 中的值是小批量中示例的标签。例如,让一个包含三个示例的小批量具有y(label) 向量为[0,6,9](考虑手写数字示例)。 所以,[LP[0,y[0]], LP[1,y[1]], LP[2,y[2]], ...,LP[n-1,y[n-1]]] 将是 LP[1,0], L[2,6], LP[3,9] 现在,我们为什么对这些数字感兴趣? 那是因为您需要这些数字来计算似然性,它被定义为小批量中示例的对数概率的平均值。例如LP[1,0] 包含第一个示例属于类 0 的对数概率。您希望这个数字尽可能高,因为这是事实。然后取平均值以找到这些数字的平均值。负号是因为损失的可能性为负。这有帮助吗?

    【讨论】:

    • 发布为代码块,因为 o/w 我遇到了错误。
    • 谢谢,我确实读过,这就是原行的来源。我仍然不明白 y 和 p_y_given_x 之间的相互作用我们是否正在记录所有人的日志,找到两个向量中数字的平均值?一个是在 1 和 0 之间缩放的答案的概率,(p_y_given_x)另一个是实际正确答案。取缩放向量和未缩放向量的平均值如何相互关联?
    • 感谢您提供的附加信息,所有这些信息也都位于代码行的同一页面上。我已经阅读了该页面,并且代码可以正常工作。我正在更改代码以尝试不同的问题。
    • 1.该日志仅用于p_y_given_x 2。仅在T.log(p_y_given_x) 中找到数字的平均值
    • 3. y 仅用于索引我们想要取平均值的T.log(p_y_given_x) 的值。 y 中的值不取平均值。 y 中的值只是用作一种花哨的索引机制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    相关资源
    最近更新 更多