kur*_*eta 23 python machine-learning neural-network tensorflow
我试图在Tensorflow中定义我自己的RNNCell(回声状态网络),根据下面的定义.
x(t + 1)= tanh(Win*u(t)+ W*x(t)+ Wfb*y(t))
y(t)= Wout*z(t)
z(t)= [x(t),u(t)]
x是状态,u是输入,y是输出.Win,W和Wfb不可训练.所有权重都是随机初始化的,但W的修改如下:"将W的元素的某个百分比设置为0,将W的比例设置为保持其光谱半径低于1.0
我有这个代码来生成方程式.
x = tf.Variable(tf.reshape(tf.zeros([N]), [-1, N]), trainable=False, name="state_vector")
W = tf.Variable(tf.random_normal([N, N], 0.0, 0.05), trainable=False)
# TODO: setup W according to the ESN paper
W_x = tf.matmul(x, W)
u = tf.placeholder("float", [None, K], name="input_vector")
W_in = tf.Variable(tf.random_normal([K, N], 0.0, 0.05), trainable=False)
W_in_u = tf.matmul(u, W_in)
z = tf.concat(1, [x, u])
W_out = tf.Variable(tf.random_normal([K + N, L], 0.0, 0.05))
y = tf.matmul(z, W_out)
W_fb = tf.Variable(tf.random_normal([L, N], 0.0, 0.05), trainable=False)
W_fb_y = tf.matmul(y, W_fb)
x_next = tf.tanh(W_in_u + W_x + W_fb_y)
y_ = tf.placeholder("float", [None, L], name="train_output")
Run Code Online (Sandbox Code Playgroud)
我的问题是双重的.首先,我不知道如何将其作为RNNCell的超类来实现.其次我不知道如何根据上述规范生成W张量.
任何这些问题的任何帮助非常感谢.也许我可以找到一种方法来准备W,但我肯定不明白如何将我自己的RNN实现为RNNCell的超类.
小智 11
快速总结一下:
查看下面的TensorFlow源代码,python/ops/rnn_cell.py
看看如何子类化 RNNCell.它通常是这样的:
class MyRNNCell(RNNCell):
def __init__(...):
@property
def output_size(self):
...
@property
def state_size(self):
...
def __call__(self, input_, state, name=None):
... your per-step iteration here ...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2677 次 |
最近记录: |