CNN + RNN 可能。为了理解让我尝试发布评论代码。句子字符的 CNN 运行和与词嵌入合并的 CNN 输出被馈送到 LSTM
N -批次数
M -示例数
L -句子长度
W -任何单词中的最大字符长度
coz - cnn char 输出大小
考虑x = [N, M, L]- 单词级别
考虑cnnx = [N, M, L, W]- 字符级别
目的是在 LSTM 中使用字符和词嵌入
CNNx = tf.nn.embedding_lookup(emb_mat, cnnx) [N, M, L, W, dc]
filter_sizes = [100]
heights = [5]
outs = []
for filter_size, height in zip(filter_sizes, heights):
num_channels = 3
filter_ = [1, height, num_channels, filter_size]
strides = [1, 1, 1, 1]
xxc = tf.nn.conv2d(Acx, filter_, strides, "VALID") # [N*M, L, W/stride, d]
out = tf.reduce_max(tf.nn.relu(xxc), 2) # [-1, L, d]
outs.append(xxc)
concat_out = tf.concat(2, outs)
xx = tf.reshape(concat_out, [-1, M, L, coz])
Ax = tf.nn.embedding_lookup(emb_mat, x)
xx = tf.concat(3, [xx, Ax]) # [N, M, L, di]
我们可以使用 LSTM 将其xx馈送到 RNN