以下为漫谈,即瞎聊,利用通俗的语言来谈谈神经网络模型中4种序列解码模型,主要是从整体概念和思路上进行通俗解释帮助理解。预警,以下可能为了偷懒就不贴公式了,一些细节也被略过了,感兴趣的可以直接去阅读原文[1][2][3]。
[1] Sequence to Sequence Learning with Neural Networks
[2] Learning Phrase Representations using RNN Encoder–Decoder for Statistical Machine Translation
[3] Neural Machine Translation by Jointly Learning to Align and Translate
利用神经网络进行序列编码的模型主要为RNN,目前比较火的一些变种模型有LSTM和GRU,只是cell单元不同而已。以下统统用RNN来代表。
编码模型比较简单,如下图所示,输入文本{X1-X6}经过循环迭代编码,在每个时刻得到当前时刻的一个隐层状态,最后序列结束后进行特征融合得到句子的表示。注意,一种比较常用的方式是将编码模型最后一个时刻的隐层状态做为整个序列的编码表示,但是实际应用中这种效果并不太好,因而我们的图例中直接采用了整个序列隐层编码进行求和平均的方式得到序列的编码向量。
早期的一些任务主要是做一些主题分类、情感检测等等分类任务,那么在编码向量上面添加一个softmax就可以解决问题。但是对于机器翻译和语音识别等问题则需要进行序列化解码。
注意到,编码时RNN每个时刻除了自己上一时刻的隐层状态编码外,还有当前时刻的输入字符,而解码时则没有这种输入。那么,一种比较直接的方式是把编码端得到的编码向量做为解码模型的每时刻输入特征。如下图所示:
简单直观而且解码模型和编码模型并没有任何区别,然而学者感觉该模型并不优雅,那么接下来我们就来介绍一些精巧点的吧。
=============此处开始转入瞎聊模式==============
我们用考试作弊来做为一个通俗的例子来解释一下模型。
首先我们假设输入文本是所学课本,编码端则是对课本的理解所整理的课堂笔记。解码端的隐层神经网络则是我们的大脑,而每一时刻的输出则是考试时要写在卷子上的答案。在上面最简单的解码模型中,可以考虑成是考试时一边写答案一边翻看课堂笔记。如果这是一般作弊学生的做法,学霸则不需要翻书,他们有一个强大的大脑神经网络,可以记住自己的课堂笔记。解码时只需要回顾一下自己前面写过什么,然后依次认真的把答案写在答卷上,就是下面这种模型了[1]:
还有很多学弱,他们不只需要作弊,而且翻看笔记的时候还需要回顾自己上一时刻写在答卷上的答案(学弱嘛,简直弱到连自己上一时刻写在答卷上的文字都记不住了),就是下面的答题模式了[2]:
然而学渣渣也是存在的,他们不只需要作弊,不只需要回顾自己上一时刻卸载答卷上的答案,还需要老师在课本上画出重点才能整理出自己的课题笔记(这就是一种注意力机制Attention,记笔记的时候一定要根据考题画出重点啊!),真的很照顾渣渣了,他们的答题模式如下[3]:
可见,除了学霸以外,其他人都作弊了,在答题的时候翻看课堂笔记(很多文献中叫这种解码模型结构为peek(偷看),是不是很像在作弊?),而且学渣渣还去找过老师给画过重点,有了清楚的重点之后就不用翻书偷看了,瞄一眼就可以了,文献中叫glimpse(一瞥),是不是很像?
如果我们将他们的大脑网络设定为同样结构的话(将他们的IQ强制保持一致),肯定是作弊的同学得分最高了,学霸模式好吃亏啊。我们来简单做一个模型测试。
测试数据:
输入序列文本 = [‘1 2 3 4 5’
, ‘6 7 8 9 10′
, ’11 12 13 14 15′
, ’16 17 18 19 20′
, ’21 22 23 24 25’]
目标序列文本 = [‘one two three four five’
, ‘six seven eight nine ten’
, ‘eleven twelve thirteen fourteen fifteen’
, ‘sixteen seventeen eighteen nineteen twenty’
, ‘twenty_one twenty_two twenty_three twenty_four twenty_five’]
设定一些参数如下:
–
(‘Vocab size:’, 51, ‘unique words’)
(‘Input max length:’, 5, ‘words’)
(‘Target max length:’, 5, ‘words’)
(‘Dimension of hidden vectors:’, 20)
(‘Number of training stories:’, 5)
(‘Number of test stories:’, 5)
–
观察训练过程:
其中,第一种解码模型为 普通作弊,第二种解码模型为 学霸模式,第三种解码模型为 学弱作弊,第四种解码模型为 学渣作弊。
可以看到在IQ值(解码模型的神经网络结构)相同的情况下,学渣作弊模式答题(训练收敛速度)更快,而学霸模式答题最慢。
文章[1]中已经提到过,想通过学霸模式达到一个好的性能需要模型隐层有4000个节点(学霸的IQ果然是高的,有一颗强大的大脑网络)。
可以想想,在课本内容很多很多时,学霸也会累的,而且学弱们你们确定课上能听懂吗?学渣就会笑啦,因而老师给他们画重点了!!!!
哈哈,娱乐而已。
好,学术一点,博主关注:对话与问答,信息检索,深度学习等相关。欢迎学术讨论。
博文出处:http://jacoxu.com/?p=1852
附录:
本博文中测试的示例代码见【Github地址】:
- # -*- encoding:utf-8 -*-
- “””
- 测试Encoder-Decoder 2016/03/22
- “””
- from keras.models import Sequential
- from keras.layers.recurrent import LSTM
- from keras.layers.embeddings import Embedding
- from keras.layers.core import RepeatVector, TimeDistributedDense, Activation
- from seq2seq.layers.decoders import LSTMDecoder, LSTMDecoder2, AttentionDecoder
- import time
- import numpy as np
- import re
- __author__ = ‘http://jacoxu.com’
- def pad_sequences(sequences, maxlen=None, dtype=’int32′,
- padding=’pre’, truncating=’pre’, value=0.):
- ”’Pads each sequence to the same length:
- the length of the longest sequence.
- If maxlen is provided, any sequence longer
- than maxlen is truncated to maxlen.
- Truncation happens off either the beginning (default) or
- the end of the sequence.
- Supports post-padding and pre-padding (default).
- # Arguments
- sequences: list of lists where each element is a sequence
- maxlen: int, maximum length
- dtype: type to cast the resulting sequence.
- padding: ‘pre’ or ‘post’, pad either before or after each sequence.
- truncating: ‘pre’ or ‘post’, remove values from sequences larger than
- maxlen either in the beginning or in the end of the sequence
- value: float, value to pad the sequences to the desired value.
- # Returns
- x: numpy array with dimensions (number_of_sequences, maxlen)
- ”’
- lengths = [len(s) for s in sequences]
- nb_samples = len(sequences)
- if maxlen is None:
- maxlen = np.max(lengths)
- # take the sample shape from the first non empty sequence
- # checking for consistency in the main loop below.
- sample_shape = tuple()
- for s in sequences:
- if len(s) > 0:
- sample_shape = np.asarray(s).shape[1:]
- break
- x = (np.ones((nb_samples, maxlen) + sample_shape) * value).astype(dtype)
- for idx, s in enumerate(sequences):
- if len(s) == 0:
- continue # empty list was found
- if truncating == ‘pre’:
- trunc = s[-maxlen:]
- elif truncating == ‘post’:
- trunc = s[:maxlen]
- else:
- raise ValueError(‘Truncating type “%s” not understood’ % truncating)
- # check `trunc` has expected shape
- trunc = np.asarray(trunc, dtype=dtype)
- if trunc.shape[1:] != sample_shape:
- raise ValueError(‘Shape of sample %s of sequence at position %s is different from expected shape %s’ %
- (trunc.shape[1:], idx, sample_shape))
- if padding == ‘post’:
- x[idx, :len(trunc)] = trunc
- elif padding == ‘pre’:
- x[idx, –len(trunc):] = trunc
- else:
- raise ValueError(‘Padding type “%s” not understood’ % padding)
- return x
- def vectorize_stories(input_list, tar_list, word_idx, input_maxlen, tar_maxlen, vocab_size):
- x_set = []
- Y = np.zeros((len(tar_list), tar_maxlen, vocab_size), dtype=np.bool)
- for _sent in input_list:
- x = [word_idx[w] for w in _sent]
- x_set.append(x)
- for s_index, tar_tmp in enumerate(tar_list):
- for t_index, token in enumerate(tar_tmp):
- Y[s_index, t_index, word_idx[token]] = 1
- return pad_sequences(x_set, maxlen=input_maxlen), Y
- def tokenize(sent):
- ”’Return the tokens of a sentence including punctuation.
- >>> tokenize(‘Bob dropped the apple. Where is the apple?’)
- [‘Bob’, ‘dropped’, ‘the’, ‘apple’, ‘.’, ‘Where’, ‘is’, ‘the’, ‘apple’, ‘?’]
- ”’
- return [x.strip() for x in re.split(‘(\W+)?’, sent) if x.strip()]
- def main():
- input_text = [‘1 2 3 4 5’
- , ‘6 7 8 9 10’
- , ’11 12 13 14 15′
- , ’16 17 18 19 20′
- , ’21 22 23 24 25′]
- tar_text = [‘one two three four five’
- , ‘six seven eight nine ten’
- , ‘eleven twelve thirteen fourteen fifteen’
- , ‘sixteen seventeen eighteen nineteen twenty’
- , ‘twenty_one twenty_two twenty_three twenty_four twenty_five’]
- input_list = []
- tar_list = []
- for tmp_input in input_text:
- input_list.append(tokenize(tmp_input))
- for tmp_tar in tar_text:
- tar_list.append(tokenize(tmp_tar))
- vocab = sorted(reduce(lambda x, y: x | y, (set(tmp_list) for tmp_list in input_list + tar_list)))
- # Reserve 0 for masking via pad_sequences
- vocab_size = len(vocab) + 1 # keras进行embedding的时候必须进行len(vocab)+1
- input_maxlen = max(map(len, (x for x in input_list)))
- tar_maxlen = max(map(len, (x for x in tar_list)))
- output_dim = vocab_size
- hidden_dim = 20
- print(‘-‘)
- print(‘Vocab size:’, vocab_size, ‘unique words’)
- print(‘Input max length:’, input_maxlen, ‘words’)
- print(‘Target max length:’, tar_maxlen, ‘words’)
- print(‘Dimension of hidden vectors:’, hidden_dim)
- print(‘Number of training stories:’, len(input_list))
- print(‘Number of test stories:’, len(input_list))
- print(‘-‘)
- print(‘Vectorizing the word sequences…’)
- word_to_idx = dict((c, i + 1) for i, c in enumerate(vocab)) # 编码时需要将字符映射成数字index
- idx_to_word = dict((i + 1, c) for i, c in enumerate(vocab)) # 解码时需要将数字index映射成字符
- inputs_train, tars_train = vectorize_stories(input_list, tar_list, word_to_idx, input_maxlen, tar_maxlen, vocab_size)
- decoder_mode = 1 # 0 最简单模式,1 [1]向后模式,2 [2] Peek模式,3 [3]Attention模式
- if decoder_mode == 3:
- encoder_top_layer = LSTM(hidden_dim, return_sequences=True)
- else:
- encoder_top_layer = LSTM(hidden_dim)
- if decoder_mode == 0:
- decoder_top_layer = LSTM(hidden_dim, return_sequences=True)
- decoder_top_layer.get_weights()
- elif decoder_mode == 1:
- decoder_top_layer = LSTMDecoder(hidden_dim=hidden_dim, output_dim=hidden_dim
- , output_length=tar_maxlen, state_input=False, return_sequences=True)
- elif decoder_mode == 2:
- decoder_top_layer = LSTMDecoder2(hidden_dim=hidden_dim, output_dim=hidden_dim
- , output_length=tar_maxlen, state_input=False, return_sequences=True)
- elif decoder_mode == 3:
- decoder_top_layer = AttentionDecoder(hidden_dim=hidden_dim, output_dim=hidden_dim
- , output_length=tar_maxlen, state_input=False, return_sequences=True)
- en_de_model = Sequential()
- en_de_model.add(Embedding(input_dim=vocab_size,
- output_dim=hidden_dim,
- input_length=input_maxlen))
- en_de_model.add(encoder_top_layer)
- if decoder_mode == 0:
- en_de_model.add(RepeatVector(tar_maxlen))
- en_de_model.add(decoder_top_layer)
- en_de_model.add(TimeDistributedDense(output_dim))
- en_de_model.add(Activation(‘softmax’))
- print(‘Compiling…’)
- time_start = time.time()
- en_de_model.compile(loss=’categorical_crossentropy’, optimizer=’rmsprop’)
- time_end = time.time()
- print(‘Compiled, cost time:%fsecond!’ % (time_end – time_start))
- for iter_num in range(5000):
- en_de_model.fit(inputs_train, tars_train, batch_size=3, nb_epoch=1, show_accuracy=True)
- out_predicts = en_de_model.predict(inputs_train)
- for i_idx, out_predict in enumerate(out_predicts):
- predict_sequence = []
- for predict_vector in out_predict:
- next_index = np.argmax(predict_vector)
- next_token = idx_to_word[next_index]
- predict_sequence.append(next_token)
- print(‘Target output:’, tar_text[i_idx])
- print(‘Predict output:’, predict_sequence)
- print(‘Current iter_num is:%d’ % iter_num)
- if __name__ == ‘__main__‘:
- main()
keras好用吗?
[笑cry]
您好,我最近也在用KERAS,做LSTM的时候看到的例子一直是EMBEDDING,所以输入就是定长的,怎么才能实现输入不定长呢?谢谢您
您好,以文本为例,词的特征维度一般是定长的,词的个数可能不定长。在输入端比较好处理,用keras的话,输入特征用0进行补位,然后在Embedding Layer中的参数mask_zero=False 改为True就可以了。如果是输出端词的个数不定长,那么需要预测一个进行批量预测后进行裁剪。祝好!
谢谢您的回复,我理解您的意思是这样子,比如我输入输出的词数都不一样,我用100维的word2vec向量表示一个词,那如果输入最长的是10个词,输入三个词的时候就是300维,补上700维,到1000维。 输出的时候 全都输出1000维的向量,再去0,是这个意思吗?
你好,差不多是这个意思,先输出再裁剪,虽然不太优雅,但效率高。另,输出长度不一定要和输入长度一致,输出的最大长度可以单独定。
您好,非常感谢您分享的代码,我在用您的模型更换数据的时候,用的中文新闻,在输出target output 和predict output的时候,输出的并不是中文,而是一堆编码形式的类似于{‘Target output:’, ‘\xeb\xaf\xb8\xec\x93\xb0\xeb\xb9\x84\xec\x8b\x9c, \xea\xb2\xbd\xec\xa3\xbc\xeb\x8c\x80\xed\x9a\x8c\xec\x97\x90 \xeb\x9e\x9c\xec\x84\x9c \xec\x97\x90\xeb\xb3\xbc\xeb\xa3\xa8\xec\x85\x98 \xec\xa0\x9c\xea\xb3\xb5’)
(‘Predict output:’, “[‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘quot’, ‘qu} 这种形式的数据,是因为什么啊。我尝试改变编码或者运用decode(),encode(),但是都解决不了问题。。。。请您赐教
您好,可以尝试把代码187和188行中
print(‘Target output:’, tar_text[i_idx])
print(‘Predict output:’, predict_sequence)
中的括号去掉,如
print ‘Target output:’, tar_text[i_idx]
print ‘Predict output:’, predict_sequence
您好,请问一下,如果encoder和decoder我不想只用一层,而分别想用两个隐层,应该怎么叠加啊,我看simpleseq2seq是有一个参数是depth,但是LSTMdecoder,Attentiondecoder好像没有depth这个参数啊,谢谢
你好,encoder可以累加多层,decoder如果想累加多层的话需要自己设计,无方便直接实现。
您好,请问encoder如何累加多层?谢谢
L166处,多add 几个encoder_top_layer即可。
报错:请指导
RuntimeError: maximum recursion depth exceeded
请问,可以用于中文文本处理吗,如果是中文文本处理需要修改色什么?
您好,可以直接处理中文。
你好,我想问一下代码显示:ImportError: No module named keras.models
是什么问题呢?
你好,我还是新手小白,也遇到这样的问题了,请问你后面是如何解决的?谢谢
您好,应该是缺少Keras包,依赖的Keras和Seq2seq已经上传到Github上了,请从Github上下载了完整文件。
你好,有java的代码吗?
抱歉没有关注过,祝好!
你好,我想问下运行出现
ImportError: No module named keras.models
这是什么问题?
请问运行提示
ImportError: No module named keras.models
是为啥呀?
请安装依赖包 Keras [建议0.3.x版本] 和 Seq2Seq
你好,如何观察训练过程呢?或者说那张图是怎么得来的呢?
写的真不错!!!再加点attention训练方式的更好。划重点的老师也各不一样?哈哈
哈哈。
不好意思贸然打扰了,我现在在做这一块的研究,想更进一步请教些问题,请问可以发邮件给你或者有什么其他联系方式吗?
您好,我的邮箱 jacoxu@126.com
博主您好~ 您讲的四种模型挺清楚的,但是代码里import的那个seq2seq.layer是属于哪个module?我不太清楚这一点~
博主您好~请问代码里import的那个seq2seq.layer是属于哪个module?谢谢~
最新的seq2seq包可能有改动,我将老版的seq2seq包 fork到了github代码中,应该可以直接下载运行。
您好,我想用于时间序列识别,输入是一总共10个月每隔五分钟的采样电压数据,想先对规定长度数据聚类,比如一天,一周,然后输入一段长度数据来识别,感觉和单词有相似之处,请问这方面可行么?
您好,能不能分享下是怎么实现的,谢谢。。
非常感谢分享,受益良多!
好奇问一下。现有代码依赖 theano,有没有基于 tensorflow 的版本?
您好,该示例代码其实是基于Keras的写的,Keras既可支持Theano,也可支持Tensorflow,所以配置一下Keras应该可以在tensorflow上跑,祝好!
LZ,你发布在Github上的代码是基于keras0.3的 现在keras最新版是1.0的 直接用会有什么影响吗?
您好,不确定keras是否向下兼容,一些接口可能会重新定义并命名,直接使用应该会报错,可根据错误信息修改下应该比较容易地在keras1.0版本上跑起来。
您好!
我对keras 的TimeDistributed wrapper 比较疑惑.
不清楚它实现了什么功能.
能麻烦您解释一下么?
LSTM的参数return_sequences=False则只返回(Batch, Hidden_dim)的向量,直接采用Dense全连接层即可,但是如果LSTM的return_sequences=True,则返回(Batch, Time_step, Hidden_dim)的向量,多了time_step的维度,那么一个(Hidden_dim, output_dim)的Dense层需要在Time维度上都计算一遍,那么就用到了TimeDistributed.
您好,我想做一个基于attention的分类模型,目标输出是1和0,请问怎么转化为您这个模型中的输出格式啊!
您好,分类问题目标文本序列固定为1,指导标签为类别标签即可。
Pingback 引用通告: –>>>深度学习 | _梦境
你好,我使用tensorflow(0.11.0)为后端,跑脚本报错了:请指导~
File “encoder_decoder.py”, line 194, in
main()
File “encoder_decoder.py”, line 176, in main
en_de_model.compile(loss=’categorical_crossentropy’, optimizer=’rmsprop’)
File “/opt/.lyi/encoder_decoder-master/keras/models.py”, line 507, in compile
self.y_train = self.get_output(train=True)
File “/opt/.lyi/encoder_decoder-master/keras/layers/containers.py”, line 130, in get_output
return self.layers[-1].get_output(train)
File “/opt/.lyi/encoder_decoder-master/keras/layers/core.py”, line 737, in get_output
X = self.get_input(train)
File “/opt/.lyi/encoder_decoder-master/keras/layers/core.py”, line 241, in get_input
previous_output = self.previous.get_output(train=train)
File “/opt/.lyi/encoder_decoder-master/keras/layers/core.py”, line 1148, in get_output
X = self.get_input(train) # (samples, timesteps, input_dim)
File “/opt/.lyi/encoder_decoder-master/keras/layers/core.py”, line 241, in get_input
previous_output = self.previous.get_output(train=train)
File “/opt/.lyi/encoder_decoder-master/seq2seq/layers/decoders.py”, line 152, in get_output
self.b_o, self.b_x])
File “/usr/local/lib/python2.7/dist-packages/theano/scan_module/scan.py”, line 383, in scan
non_seqs.append(tensor.as_tensor_variable(elem))
File “/usr/local/lib/python2.7/dist-packages/theano/tensor/basic.py”, line 212, in as_tensor_variable
raise AsTensorError(“Cannot convert %s to TensorType” % str_x, type(x))
theano.tensor.var.AsTensorError: (‘Cannot convert to TensorType’, )
你好,我遇到了和你类似的问题,请问你解决这个问题么?
您好,我运行代码报错了,win764 python3.5 keras0.3.0 theano0.9.0,无GPU
报错:AttributeError: module ‘theano’ has no attribute ‘gof’.考虑是因为版本不兼容的原因,想问一下,楼主用的什么平台及版本?谢谢!
您好,应该是win764, python2.7, keras0.3.3, theano0.8.0。
请问一下,在LSTMDecoder中的参数 output_dim ,我在它及它的父类的初始化中没有找到相应的赋值语句。这个参数有用么? 另外,为什么要讲decoder的output_dim等于hidden_dim?它的输出维度为什么要和隐藏层相等?
你好,LSTMDecoder是seq2seq下的类。Keras下目前的版本只保留了output_dim,可参见Keras的LSTM参数说明:output_dim: dimension of the internal projections and the final output.
一般情况下默认维度相等。
您好,我想问一下seq2seq包在哪里下载的,我这里想用最新版的包
您好,https://github.com/farizrahman4u/seq2seq,祝好!
Pingback 引用通告: 聊天機器人的開發思路[转][精][荐] – 易可信blog系统
Pingback 引用通告: 漫谈四种神经网络序列解码模型【附示例代码】 [转载][精华][推荐] – 易可信blog系统
你好想问下,你这个每一行输入输出都是5个长度,如果我没一行输出不一样,比如第一行5个,第二行10个,这时该如何处理呢。
大神,看你的输入输出都是5个固定的,如果不是固定的改如何处理,比如第一行是[1,2,3,4,5,6]第二行是[7,8]第三行是[9,10,11],这种类型的
可以设置结束符,然后进行裁剪。祝好!
我现在的做法是取出最长的作为定长,然后长度不够的,自己补一个符号,最后在输出上也加上一个对应自己补的符号的输出,不知道和你说的是不是一个意思,主要是你的回复太简短,没太理解
如果不是希望具体解释下,给小弟提供一个思路
嗯,可以,这个演示代码比较简单,建议看一下神经机器翻译的完整代码。
您好,我从https://github.com/farizrahman4u/seq2seq上下载代码后运行报一下错误:
AttributeError:’OptionalInputPlaceHolder’ object has no attribute ‘inbound_nodes’
您看怎么解决.非常感谢!
我也是运行代码报错:
‘_OptionalInputPlaceHolder’ object has no attribute ‘inbound_nodes’
请问你是怎么解决的?
您好,我从https://github.com/farizrahman4u/seq2seq上下载代码后运行报以下错误:
AttributeError:’OptionalInputPlaceHolder’ object has no attribute ‘inbound_nodes’
您看怎么解决.非常感谢!给个建议,谢谢
该问题已经解决!谢谢!!
好的。
请问你是怎么解决的,我这边遇到了同样的问题
你好,请问AttributeError: ‘_OptionalInputPlaceHolder’ object has no attribute ‘inbound_nodes’这个问题怎么解决的啊?
请问你们这个问题是怎么解决的??
请问,要做答案生成的话需要怎么办
直接套用就行了,就是要解决一下答案句子长短不一的问题,设置结束符,进行裁剪
谢谢回复,请问for iter_num in range(5000):
en_de_model.fit(inputs_train, tars_train, batch_size=3, nb_epoch=1, show_accuracy=True) 这是在训练模型吗
对的。
File “D:\Pythonworkspace\encoder_decoder-master\encoder_decoder.py”, line 193, in
main()
File “D:\Pythonworkspace\encoder_decoder-master\encoder_decoder.py”, line 122, in main
vocab = sorted(reduce(lambda x, y: x | y, (set(tmp_list) for tmp_list in input_list + tar_list)))
NameError: name ‘reduce’ is not defined
大佬,请指教
您好,python 3.0以后 需要,from functools import reduce
你好,我还是新手,想请教一下输入不定长的问题:比如输入为a=[1,2,3] b=[1,8] c=[1,6,9,8,4] 。 能否实现输入到conv1d?如何实现?
设定最大输入长度,通过补位符将所有输入补齐即可。
您好,你有试过用这个做图像分类么,特别是那些参数的设置。
抱歉没有做过图像分类,分类任务最好还是采用CNN based model,RNN based序列模型编码存在有偏性,如文本上需要双向,图像上需要四向[Renet: A recurrent neural network based alternative
to convolutional networks],即便如此,还是未必能优于CNN
嗯嗯,我是做动作识别的,现在想加attention,然后编码部分用CNN,解码用RNN,在网上找资料,看到你的这篇。目前没有参考的源码
你好,最近看到了您的代码,很感兴趣。 但是在运行过程中总是显示
ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True
请问知道这个怎么解决吗
for iter_num in range(5000):
en_de_model.fit(inputs_train, tars_train, batch_size=3, nb_epoch=1, show_accuracy=True)
你好:对你的代码 这里range(5000)是迭代5000次么? epoch有代表什么?
这个代码能用于文本摘要么?不知你有没有试过,效果则么样?
您好,我将en_de_model.add(TimeDistributedDense(output_dim)) 换成en_de_model.add(Dense(output_dim)) 对最后的结果会不会有影响。
而且我在en_de_model.add(Dense(output_dim)) 这层前面添加了Flatten()层,对精度有影响么?
希望能得到大神的救助
去掉了时间维不合理。
博主您好,非常感谢您分享的讲解和代码,我留意到您的seq2seq的代码好像是基于theano为backend写的,我不太熟悉theano更熟悉tensorflow多一些,想问问技术上可以替换成tensorflow吗
可以的。
你好,请问能把图补上吗?图好像挂了
您好,抱歉我用的图床好像跟worldpress对接有问题,可参见同步更新的微信公众号 jacoxu_nlp