rnn

How to build an embedding layer in Tensorflow RNN?

不羁的心 提交于 2019-12-08 17:04:00
问题 I'm building an RNN LSTM network to classify texts based on the writers' age (binary classification - young / adult). Seems like the network does not learn and suddenly starts overfitting: Red: train Blue: validation One possibility could be that the data representation is not good enough. I just sorted the unique words by their frequency and gave them indices. E.g.: unknown -> 0 the -> 1 a -> 2 . -> 3 to -> 4 So I'm trying to replace that with word embedding. I saw a couple of examples but I

Pytorch实现基本循环神经网络RNN

空扰寡人 提交于 2019-12-08 14:57:00
RNN Recurrent Neural networks(Rumelhart, 1986) 主要用来处理序列型数据,具有对以往数据的记忆功能。下图所示,输入为input和一个状态Hidden0,输出为output和Hidden1. 一般地,对输入到RNN进行处理的第 t t t 个数据,也就是第 t t t 时刻,输出的隐藏状态可以表示为 h ( t ) = f ( h ( t − 1 ) , x ( t ) ; θ ) h^{(t)}=f(h^{(t-1)},x^{(t)};\theta) h ( t ) = f ( h ( t − 1 ) , x ( t ) ; θ ) 在RNN对序列数据进行处理时,采用参数共享机制,即权重是相同的。RNN有很多变体,上述的是最简单的一种形式,中间也可以输入 y ( t ) y^{(t)} y ( t ) 。 标准RNN如下: 对时刻 t t t ,更新的方程为: h t = tanh ⁡ ( w i h x t + b i h + w h h h t − 1 + b h h ) h_{t}=\tanh(w_{ih}x_{t}+b_{ih}+w_{hh}h_{t-1}+b_{hh}) h t ​ = tanh ( w i h ​ x t ​ + b i h ​ + w h h ​ h t − 1 ​ + b h h ​ ) 在实际中使用nn

internal variables in BasicRNNCell

对着背影说爱祢 提交于 2019-12-08 07:35:26
问题 I have the following example code to test BasicRNNCell . I'd like to get its internal matrix so that I can calculate the values of output_res , newstate_res using my own code to make sure that I can reproduce the values of output_res , newstate_res . In tensorflow source code, it says output = new_state = act(W * input + U * state + B) . Does anybody know how I can get W and U ? (I tried to access cell._kernel , but it is not available.) $ cat ./main.py #!/usr/bin/env python # vim: set

LSTM architecture in Keras implementation?

萝らか妹 提交于 2019-12-08 01:28:35
问题 I am new to Keras and going through the LSTM and its implementation details in Keras documentation . It was going easy but suddenly I came through this SO post and the comment. It has confused me on what is the actual LSTM architecture: Here is the code: model = Sequential() model.add(LSTM(32, input_shape=(10, 64))) model.add(Dense(2)) As per my understanding, 10 denote the no. of time-steps and each one of them is fed to their respective LSTM cell ; 64 denote the no. of features for each

TensorFlow人工智能引擎入门教程所有目录

╄→尐↘猪︶ㄣ 提交于 2019-12-07 21:12:55
TensorFlow 人工智能引擎 入门教程之一 基本概念以及理解 TensorFlow人工智能引擎入门教程之二 CNN卷积神经网络的基本定义理解。 TensorFlow人工智能引擎入门教程之三 实现一个自创的CNN卷积神经网络 TensorFlow人工智能引擎入门教程之四 TensorBoard面板可视化管理 TensorFlow人工智能引擎入门教程之五 AlphaGo 的策略网络(CNN)简单的实现 TensorFlow人工智能引擎入门教程之六 训练的模型Model 保存 文件 并使用 TensorFlow人工智能引擎入门教程之七 DNN深度神经网络 的原理 以及 使用 TensorFlow人工智能引擎入门教程之八 接着补充一章MLP多层感知器网络原理以及 使用 TensorFlow人工智能引擎入门教程之九 RNN循环网络原理以及 使用 TensorFlow人工智能引擎入门教程之十 最强网络 RSNN深度残差网络 平均准确率96-99% TensorFlow人工智能入门教程之十一 最强网络DLSTM 双向长短期记忆网络(阿里小AI实现) TensorFlow人工智能引擎入门教程之十二 Tensorflow Caffe相互转换 TensorFlow人工智能引擎入门教程之十三 Tensorflow RCNN区域卷积神经网络 Tensorflow 人工智能引擎之 十四

Tensorflow save final state of LSTM in dynamic_rnn for prediction

前提是你 提交于 2019-12-07 13:00:47
问题 I want to save the final state of my LSTM such that it's included when I restore the model and can be used for prediction. As explained below, the Saver only has knowledge of the final state when I use tf.assign . However, this throws an error (also explained below). During training I always feed the final LSTM state back into the network, as explained in this post. Here are the important parts of the code: When building the graph: self.init_state = tf.placeholder(tf.float32, [ self.n_layers,

scope 命名方法

你。 提交于 2019-12-06 12:57:31
tf.name_scope() 在 Tensorflow 当中有两种途径生成变量 variable, 一种是 tf.get_variable() , 另一种是 tf.Variable() . 如果在 tf.name_scope() 的框架下使用这两种方式, 结果会如下. import tensorflow as tf with tf.name_scope("a_name_scope"): initializer = tf.constant_initializer(value=1) var1 = tf.get_variable(name='var1', shape=[1], dtype=tf.float32, initializer=initializer) var2 = tf.Variable(name='var2', initial_value=[2], dtype=tf.float32) var21 = tf.Variable(name='var2', initial_value=[2.1], dtype=tf.float32) var22 = tf.Variable(name='var2', initial_value=[2.2], dtype=tf.float32) with tf.Session() as sess: sess.run(tf.initialize_all

深度学习之Attention Model(注意力模型)

旧城冷巷雨未停 提交于 2019-12-06 10:02:35
引自:https://www.cnblogs.com/jiangxinyang/p/9367497.html 深度学习之Attention Model(注意力模型) 1、Attention Model 概述   深度学习里的Attention model其实模拟的是人脑的注意力模型,举个例子来说,当我们观赏一幅画时,虽然我们可以看到整幅画的全貌,但是在我们深入仔细地观察时,其实眼睛聚焦的就只有很小的一块,这个时候人的大脑主要关注在这一小块图案上,也就是说这个时候人脑对整幅图的关注并不是均衡的,是有一定的权重区分的。这就是深度学习里的Attention Model的核心思想。   人脑的注意力模型,说到底是一种资源分配模型,在某个特定时刻,你的注意力总是集中在画面中的某个焦点部分,而对其它部分视而不见。 2、Encoder-Decoder框架   所谓encoder-decoder模型,又叫做编码-解码模型。这是一种应用于seq2seq问题的模型。seq2seq问题简单的说,就是根据一个输入序列x,来生成另一个输出序列y。常见的应用有机器翻译,文档提取,问答系统等。Encoder-Decoder模型中的编码,就是将输入序列转化成一个固定长度的向量;解码,就是将之前生成的固定向量再转化成输出序列。   Encoder-Decoder(编码-解码)是深度学习中非常常见的一个模型框架

RNN、LSTM、GRU的简单介绍

别等时光非礼了梦想. 提交于 2019-12-06 06:58:37
一、RNN    1.为什么需要RNN     RNN,中文’循环神经网络‘,解决的是时间序列问题。什么是时间序列问题呢,就是我们的样本数据之间在时间维度上存在关联的,跟一般的神经网络不一样,也就是说我们前一个输入和后一个输入有某种说不清道不明的关系,需要RNN这种特定结构的神经网络去寻找内部联系。    2.基本网 络结构     下面是RNN的一个基本结构和一个官网结构,第一个图里左边是未展开的形式,右边是展开的形式 ,将每一个时刻T=t的过程统统列举出来,它们共享参数W、U、V,最终的损失是每一个时刻的损失累加    3.前向传播    对于时刻t,存在:        ,     其中ϕ为激活函数,一般来说会选择tanh函数,b为偏置,而t时刻的输出O为:            输出的预测值y_hat为:             σ为激活函数,通常RNN用于分类,一般用softmax函数。     针对每个时刻经过这样的计算,我们就能得到每个时刻的y_hat和h_t,以及各自的损失,再通过累加每个时刻的损失值得到最终的损失,这样就算是一次前向传播结束了。    4.反向传播       我们说模型的训练其实就是:将数据喂到模型里,找到一批参数使得损失函数最小的过程。那么最重要的就是这批参数的更新过程了,我们用的是梯度下降的过程来更新参数,本质就这一个公式,敲黑板啦!! W

RNN循环神经网络学习——概述

a 夏天 提交于 2019-12-06 06:50:51
  循环神经网络(Recurrent Neural NetWork,RNN)是一种将节点定向连接成环的人工神经网络,其内部状态可以展示动态时序行为。   循环神经网络的主要用途是处理和预测序列数据。循环神经网络最初就是为了刻画一个序列当前的输出与之前信息的关系。从网络结构上来看,循环神经网络会记忆之前的信息,并利用之前的信息影响后面节点的输出。也就是说,循环神经网络的隐藏层之间的节点是有连接的,隐藏层的输入不仅包含输入层的输出,还包括上一时刻隐藏层的输出。         如图为典型的RNN结构示意图。RNN主体结构的输入,除了来自输入层的x t 还有一个循环的边来提供上一时刻的隐层状态S t 。在每一时刻,RNN的模块在读取了X t 和S t-1 之后会产生新的隐藏状态S t ,并产生本时刻的输出O t 。RNN当前的状态是由上一时刻的状态S t-1 和当前的输入X t 共同决定的。对于一个序列数据,可以将这个序列上不同时刻的数据依次传入循环神经网络的输入层;而输出既可以是对序列下一时刻的预测,也可以是对当前时刻信息的处理结果。循环神经网络要求每一时刻都有一个输入,但是不一定每个时刻都有输出。   网络在t时刻接收到输入Xt之后,隐藏层的值是S t ,输出值是O t 。S t 的值不仅仅取决于S t ,还取决于S t-1 。可以用下面的公式来表示。       O t =g(V