lstm

Neural Network LSTM input shape from dataframe

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to implement an LSTM with Keras . I know that LSTM's in Keras require a 3D tensor with shape (nb_samples, timesteps, input_dim) as an input. However, I am not entirely sure how the input should look like in my case, as I have just one sample of T observations for each input, not multiple samples, i.e. (nb_samples=1, timesteps=T, input_dim=N) . Is it better to split each of my inputs into samples of length T/M ? T is around a few million observations for me, so how long should each sample in that case be, i.e., how would I choose

What is the equivalent of the rnn() in TensorFLow r 1.0?

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I used to create the RNN network in v0.8, using: from tensorflow.python.ops import rnn # Define a lstm cell with tensorflow lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0) # Get lstm cell output outputs, states = rnn.rnn(cell=lstm_cell, inputs=x, dtype=tf.float32) rnn.rnn() is not available anymore, and it sounds it has been moved to tf.contrib . What is the exact code to create RNN network out of a BasicLSTMCell ? Or, in the case that I have an stacked LSTM, lstm_cell = tf.contrib.rnn.BasicLSTMCell(hidden_size, forget_bias=0.0

What's the difference between a bidirectional LSTM and an LSTM?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 01:09:59
问题 Can someone please explain this? I know bidirectional LSTMs have a forward and backward pass but what is the advantage of this over a unidirectional LSTM? What is each of them better suited for? 回答1: LSTM in its core, preserves information from inputs that has already passed through it using the hidden state. Unidirectional LSTM only preserves information of the past because the only inputs it has seen are from the past. Using bidirectional will run your inputs in two ways, one from past to

TensorFlow: Incompatible shapes: [100,155] vs. [128,155] when combining CNN and LSTM

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Problem I'm getting an incompatible shape error when trying to stack a Conv -> Lstm -> Fully connected layers for an audio regression task. I can't work out why I'm getting the error I'm getting - the graph builds fine then throws the error - can anyone help? Code lstm_num_hidden = 128 lstm_number_layers = 3 x = tf . placeholder ( tf . float32 , [ None , 1024 ]) y = tf . placeholder ( tf . float32 , [ None , 155 ]) keep_probability = tf . placeholder ( tf . float32 ) def conv2d ( x , weights ): return tf . nn . conv2d ( x , weights

Sample from tensorflow LSTM model when using symbolic batch inputs

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am building a next-character prediction LSTM for sentences. I was following the tutorial here https://indico.io/blog/tensorflow-data-inputs-part1-placeholders-protobufs-queues/ on how to make the data input process part of the tensorflow graph, and now I have a stateful LSTM that is fed with symbolic (!) batches generated by tf.contrib.training.batch_sequences_with_states , which are in turn read from TF.SequenceExamples of varying lengths (Char-RNN working on characters in a sentence), as shown in the code below. The whole input

LSTM公式推导

匿名 (未验证) 提交于 2019-12-03 00:43:02
LSTM公式推导~~ H作为一个时序状态的输出 ft = sigmoid(Wi*[Ht-1,Xt]+bi) ft作为Ct-1的信号控制量,传下来的信号的多少0~1之间 Ct = ft*Ct-1 + sigmoid(wj*[Ht-1,Xt]+bj)*tanh(Wg*[Ht-1,Xt]+bg) ^Ct = sigmoid(wj*[Ht-1, Xt]+bj)*tanh(Wg*[Ht-1, Xt]+bg) Ht = tanh(Wr*(ft*Ct-1+sigmoid(Wj*[Ht-1,Xt]+bj)*tanh(Wg*[Ht-1,Xt]+bg))+br)*sigmoid(We*[Ht-1,Xt]+be) 几个部分:1,产生候选信号 ~~> 2 ,筛选的信号比率sigmoid层,sgmoid(W*[Ht-1,Xt]+B) 筛选Ct-1记住的比例-----》+ 本时序信息筛选比率(fr) * 本层生成记忆东西 tanh(W*[Ht-1,Xt]+b) Ct --->本层记忆信号 = 上一层*筛选率+本层生成*筛选率 Ht = 筛选率*tanh(Ct) 原文: https://www.cnblogs.com/fenglongyu/p/9350105.html

图像标注:Show, Attend and Tell: Neural Image Caption Generation with Visual Attention

匿名 (未验证) 提交于 2019-12-03 00:38:01
这篇文章是2015年ICML上的一篇文章,把attention机制引入到图像领域的文章,作者Kelvin Xu 、Yoshua Bengio等人,来自多伦多大学和蒙特利尔大学。 Image caption是计算机视觉的最初始任务,不仅要获得图片里的物体,还要表达他们之间的关系。目前现存的方法大都是encoder ― decoder架构,利用CNN、RNN、LSTM等神经网络完成caption工作,比如说只使用CNN对图像进行特征提取,然后利用提取的特征生成caption,还有结合CNN和RNN的,使用CNN提取图像特征,将Softmax层之前的那一层vector作为encoder端的输出并送入decoder中,使用LSTM对其解码并生成句子,这种方法也是本文所采取的方法,只是在此基础上嵌入了soft和hard attention机制。 除了神经网络之外,caption还有两种典型的方法: 1、使用模板的方法,填入一些图像中的物体; 2、使用检索的方法,寻找相似描述。 这两种方法都使用了一种泛化的手段,使得描述跟图片很接近,但又不是很准确。所以作者在此基础上提出了自己的模型架构,将soft 和hard attention引入到caption,并利用可视化手段理解attention机制的效果。 模型: 模型的总体架构如上图所示,也是由encoder和decoder组成。 Encoder

图像标注:Show, Attend and Tell: Neural Image Caption Generation with Visual Attention

匿名 (未验证) 提交于 2019-12-03 00:37:01
这篇文章是2015年ICML上的一篇文章,把attention机制引入到图像领域的文章,作者Kelvin Xu 、Yoshua Bengio等人,来自多伦多大学和蒙特利尔大学。 Image caption是计算机视觉的最初始任务,不仅要获得图片里的物体,还要表达他们之间的关系。目前现存的方法大都是encoder ― decoder架构,利用CNN、RNN、LSTM等神经网络完成caption工作,比如说只使用CNN对图像进行特征提取,然后利用提取的特征生成caption,还有结合CNN和RNN的,使用CNN提取图像特征,将Softmax层之前的那一层vector作为encoder端的输出并送入decoder中,使用LSTM对其解码并生成句子,这种方法也是本文所采取的方法,只是在此基础上嵌入了soft和hard attention机制。 除了神经网络之外,caption还有两种典型的方法: 1、使用模板的方法,填入一些图像中的物体; 2、使用检索的方法,寻找相似描述。 这两种方法都使用了一种泛化的手段,使得描述跟图片很接近,但又不是很准确。所以作者在此基础上提出了自己的模型架构,将soft 和hard attention引入到caption,并利用可视化手段理解attention机制的效果。 模型: 模型的总体架构如上图所示,也是由encoder和decoder组成。 Encoder

Keras中CNN联合LSTM进行分类

匿名 (未验证) 提交于 2019-12-03 00:37:01
def get_model(): n_classes = 6 inp=Input(shape=(40, 80)) reshape=Reshape((1,40,80))(inp) # pre=ZeroPadding2D(padding=(1, 1))(reshape) # 1 conv1=Convolution2D(32, 3, 3, border_mode='same',init='glorot_uniform')(reshape) #model.add(Activation('relu')) l1=LeakyReLU(alpha=0.33)(conv1) conv2=ZeroPadding2D(padding=(1, 1))(l1) conv2=Convolution2D(32, 3, 3, border_mode='same',init='glorot_uniform')(conv2) #model.add(Activation('relu')) l2=LeakyReLU(alpha=0.33)(conv2) m2=MaxPooling2D((3, 3), strides=(3, 3))(l2) d2=Dropout(0.25)(m2) # 2 conv3=ZeroPadding2D(padding=(1, 1))(d2) conv3=Convolution2D(64, 3,

TesorFlow之RNN与LSTM

匿名 (未验证) 提交于 2019-12-03 00:34:01
RNN 计算公式 由当前输入和前一状态得到当前状态 h t = f ( U x ( t ) + W h ( t 1 ) + b ) h t = f ( U x ( t ) + W h ( t 1 ) + b ) 注意当前状态并不直接输出,而是再通过一个全连接层 o ( t ) = V h ( t ) + c o ( t ) = V h ( t ) + c 代码实现 import numpy as np X = [ 1 , 2 ] state = [ 0.0 , 0.0 ] #状态权重 w_state = np.asarray([ 0.1 , 0.2 ],[ 0.3 , 0.4 ]) #输入权重 w_input = nu.asarray([ 0.5 , 0.6 ]) b_input = np.asarray([ 0.1 ,- 0.1 ]) #输出权重 w_output = np.asarray([[ 1.0 ],[ 2.0 ]]) b_ouput = np.asarray( 0.1 ) for i in len(X): #计算新的状态 state = np.tanh(np.dot(state,w_state)+X[i]*w_input+b) print(state) #计算输出 out = np.dot(state,w_output)+b_output print(out) LSTM