【发布时间】:2020-07-06 22:41:11
【问题描述】:
第一次发帖,所以请对我放轻松 :) 请发布任何关于我的提问和论坛技巧的 cmets,我们将不胜感激!
我试图了解构成 RNN 的矩阵大小和操作。我将介绍我已经了解的内容,因此希望我们都在同一页面上。 (或者你可以 TL;DR 到底部的问题)
X_Sets 是一个二维数组,它有一些正弦波值,Y_sets 是一个一维数组,它保存每个记录序列中的下一个正弦波值。这里的目标是准确预测正弦波的下一个值。
初始值:
learning_rate = 0.0001
nepoch = 25
T = 50 # sequence length
hidden_dim = 100
output_dim = 1
U = np.random.uniform(0, 1, (hidden_dim, T))
W = np.random.uniform(0, 1, (hidden_dim, hidden_dim))
V = np.random.uniform(0, 1, (output_dim, hidden_dim))
这是我目前正在使用的代码的 sn-p,它是前向传播函数的一部分。 cmets中的解释。
for i in range(Y_Sets.shape[0]):
#select the first record from both data sets and print out the sizes for all to see
x, y = X_Sets[i], Y_Sets[i]
print(Y_Sets.shape) #(100, 1)
print(X_Sets.shape) #(100, 50, 1)
print(x.shape) #(50, 1)
print(y.shape) #(1,)
#clear the prev_s values as the computed hidden values will be different for each record.
prev_s = np.zeros((hidden_dim, 1))
#loop for one record.
for t in range(T):
#new input array is 0'd every loop
new_input = np.zeros(x.shape)
#we only fill the array in the t'th position, everything else is 0
new_input[t] = x[t]
#See Question
mulu = np.dot(U, new_input)
#Same issue here
mulw = np.dot(W, prev_s) #why is W a 2D matrix?
add = mulw + mulu
s = sigmoid(add)
mulv = np.dot(V, s)
prev_s = s
问题:
我知道有 100 个隐藏层,每个隐藏层都有自己的 U,因此将每个单独的 x[t] 乘以一列 U 是有意义的。但是 - 在下一轮循环中,t 将是2,x[2] 将在第二列中,这将是由不同的 100 Us 组成的点积(ed)。
现在 - 我被引导相信 RNN 的全部意义在于它们是高效的,因为 U、V 和 W 在整个序列中是恒定的,而在这里我们可以看到它们在序列中是不同的。 为什么?
编辑:这是我正在关注的指南:https://www.analyticsvidhya.com/blog/2019/01/fundamentals-deep-learning-recurrent-neural-networks-scratch-python/
【问题讨论】:
标签: python machine-learning recurrent-neural-network