根据论文中的说明对编码器-解码器进行建模
Modeling Encoder-Decoder according to instructions from a paper
我是这个领域的新手,我正在阅读一篇论文“基于深度神经网络学习技术预测引用计数”。如果有人想重现结果,作者会在那里描述他们实施的代码。我尝试这样做,但不确定是否成功。
这是他们的描述:
-RNN module - SimpleRNN
-Output dimension of the encoder - 512
-The output layer - Dense layer
-Activation function - ReLU
-Overfitting prevention technique - Dropout with 0.2 rate
-Epochs - 100
Optimization algorithm - RMSProp
Learning rate - 10^{-5}
Batch size - 256
这是我的实现。我不确定我创建的模型是否是sequence to sequence。
epocsh = 100
batch_size = 256
optimizer = keras.optimizers.RMSprop(lr=0.00001)
model = keras.models.Sequential([
keras.layers.SimpleRNN(512, input_shape=[X_train.shape[0], X_train.shape[1]],
activation='relu', return_sequences=True, dropout=0.2),
keras.layers.Dense(9)
])
model.compile(loss='mse', optimizer=optimizer, metrics=[keras.metrics.RootMeanSquaredError()])
这个模型的总结是:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
simple_rnn (SimpleRNN) (None, 154521, 512) 266240
_________________________________________________________________
dense (Dense) (None, 154521, 9) 4617
=================================================================
Total params: 270,857
Trainable params: 270,857
Non-trainable params: 0
_________________________________________________________________
更新:这可能是正确的表达方式吗?
encoder = keras.layers.SimpleRNN(512,
input_shape=[X_train.shape[0], X_train.shape[1]],
activation='relu',
return_sequences=False,
dropout=0.2)
decoder = keras.layers.SimpleRNN(512,
input_shape=[X_train.shape[0], X_train.shape[1]],
activation='relu',
return_sequences=True,
dropout=0.2)
output = keras.layers.Dense(9)(decoder)
这是我正在使用的数据集。
year venue c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14
1989 234 0 1 2 3 4 5 5 5 5 8 8 10 11 12
1989 251 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1990 346 0 0 0 0 0 0 0 0 0 0 0 0 0 0
我需要将所有列作为输入,直到 c5,并尝试预测其他 c(这是未来几年的引用计数)。这是前进的正确方式吗?
您的模型是标记分类模型,而不是序列到序列。
Seq-2-seq 模型由编码器和解码器组成(在您的例子中两者都是 RNN)。它不能用 Sequential API 创建,因为编码器和解码器有单独的输入。
应使用参数 return_sequences=False
创建编码器。
密集层应该跟随解码器。
应该是这样的:
encoder_input = Input(shape=(None, 512))
decoder_input = Input(shape=(None, 512))
encoder_output = keras.layers.SimpleRNN(512,
activation='relu',
return_sequences=False,
dropout=0.2)(encoder_input)
encoder_output = encoder_output[:, tf.newaxis, ...]
decoder_inputs = tf.concat([encoder_output, decoder_input], 1)
decoder_output = keras.layers.SimpleRNN(512,
activation='relu',
return_sequences=True,
dropout=0.2)(decoder_inputs)
output = keras.layers.Dense(9)(decoder_output)
model_att = tf.keras.models.Model([encoder_input, decoder_input], output )
model_att.compile(optimizer=ADAM, loss='sparse_categorical_crossentropy')
model_att.summary()
我是这个领域的新手,我正在阅读一篇论文“基于深度神经网络学习技术预测引用计数”。如果有人想重现结果,作者会在那里描述他们实施的代码。我尝试这样做,但不确定是否成功。
这是他们的描述:
-RNN module - SimpleRNN
-Output dimension of the encoder - 512
-The output layer - Dense layer
-Activation function - ReLU
-Overfitting prevention technique - Dropout with 0.2 rate
-Epochs - 100
Optimization algorithm - RMSProp
Learning rate - 10^{-5}
Batch size - 256
这是我的实现。我不确定我创建的模型是否是sequence to sequence。
epocsh = 100
batch_size = 256
optimizer = keras.optimizers.RMSprop(lr=0.00001)
model = keras.models.Sequential([
keras.layers.SimpleRNN(512, input_shape=[X_train.shape[0], X_train.shape[1]],
activation='relu', return_sequences=True, dropout=0.2),
keras.layers.Dense(9)
])
model.compile(loss='mse', optimizer=optimizer, metrics=[keras.metrics.RootMeanSquaredError()])
这个模型的总结是:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
simple_rnn (SimpleRNN) (None, 154521, 512) 266240
_________________________________________________________________
dense (Dense) (None, 154521, 9) 4617
=================================================================
Total params: 270,857
Trainable params: 270,857
Non-trainable params: 0
_________________________________________________________________
更新:这可能是正确的表达方式吗?
encoder = keras.layers.SimpleRNN(512,
input_shape=[X_train.shape[0], X_train.shape[1]],
activation='relu',
return_sequences=False,
dropout=0.2)
decoder = keras.layers.SimpleRNN(512,
input_shape=[X_train.shape[0], X_train.shape[1]],
activation='relu',
return_sequences=True,
dropout=0.2)
output = keras.layers.Dense(9)(decoder)
这是我正在使用的数据集。
year venue c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14
1989 234 0 1 2 3 4 5 5 5 5 8 8 10 11 12
1989 251 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1990 346 0 0 0 0 0 0 0 0 0 0 0 0 0 0
我需要将所有列作为输入,直到 c5,并尝试预测其他 c(这是未来几年的引用计数)。这是前进的正确方式吗?
您的模型是标记分类模型,而不是序列到序列。
Seq-2-seq 模型由编码器和解码器组成(在您的例子中两者都是 RNN)。它不能用 Sequential API 创建,因为编码器和解码器有单独的输入。
应使用参数 return_sequences=False
创建编码器。
密集层应该跟随解码器。
应该是这样的:
encoder_input = Input(shape=(None, 512))
decoder_input = Input(shape=(None, 512))
encoder_output = keras.layers.SimpleRNN(512,
activation='relu',
return_sequences=False,
dropout=0.2)(encoder_input)
encoder_output = encoder_output[:, tf.newaxis, ...]
decoder_inputs = tf.concat([encoder_output, decoder_input], 1)
decoder_output = keras.layers.SimpleRNN(512,
activation='relu',
return_sequences=True,
dropout=0.2)(decoder_inputs)
output = keras.layers.Dense(9)(decoder_output)
model_att = tf.keras.models.Model([encoder_input, decoder_input], output )
model_att.compile(optimizer=ADAM, loss='sparse_categorical_crossentropy')
model_att.summary()