RNN代码学习----Theano代码解析

http://blog.csdn.net/xiaolang85/article/details/51191820()

http://blog.csdn.net/rtygbwwwerr/article/details/51012699(RNN的一个使用实例)

---------------------------------------------------------------开始上代码-----------------------------------------------------------------------------------

读文件的地方就开始出错!

#coding=utf-8
#尝试着用RNN训练语言模型

#按行读取文件,并在每一行首尾添加标签
# with open('data/script.txt', 'rb') as f:
import csv
import itertools
import nltk
with open('test.txt', 'rb') as f:
    reader = csv.reader(f, skipinitialspace=True)
    reader.next()
    # Split full comments into sentences
    sentences = itertools.chain(*[nltk.sent_tokenize(x[0].decode('utf-8').lower()) for x in reader]) #说找不到nltk难道我需要自己安装???
    # Append SENTENCE_START and SENTENCE_END
    sentences = ["%s %s %s" % (sentence_start_token, x, sentence_end_token) for x in sentences]
print "Parsed %d sentences." % (len(sentences))


RNNs能干什么?

1.语言模型与文本生成(Language Modeling and Generating Text)

给你一个单词序列,我们需要根据前面的单词预测每一个单词的可能性。

2.机器翻译(Machine Translation)

      机器翻译是将一种源语言语句变成意思相同的另一种源语言语句,如将英语语句变成同样意思的中文语句。与语言模型关键的区别在于,需要将源语言语句序列输入后,才进行输出,即输出第一个单词时,便需要从完整的输入序列中进行获取。机器翻译如下图所示:

3.语音识别(Speech Recognition)

4.图像描述生成 (Generating Image Descriptions)

原文地址:https://www.cnblogs.com/maowuyu-xb/p/6942215.html