lstm

How to apply Layer Normalisation in LSTMCell

妖精的绣舞 提交于 2019-12-24 19:00:25
问题 I want to apply Layer Normalisation to recurrent neural network while using tf.compat.v1.nn.rnn_cell.LSTMCell . There is a LayerNormalization class but how should I apply this in LSTMCell. I am using tf.compat.v1.nn.rnn_cell.LSTMCell because I want to use projection layer. How should I achieve Normalisation in this case. class LM(tf.keras.Model): def __init__(self, hidden_size=2048, num_layers=2): super(LM, self).__init__() self.hidden_size = hidden_size self.num_layers = num_layers self.lstm

Avoiding duplicating graph in tensorflow (LSTM model)

青春壹個敷衍的年華 提交于 2019-12-24 10:39:58
问题 I have the following simplified code (actually, unrolled LSTM model): def func(a, b): with tf.variable_scope('name'): res = tf.add(a, b) print(res.name) return res func(tf.constant(10), tf.constant(20)) Whenever I run the last line, it seems that it changes the graph. But I don't want the graph changes. Actually my code is different and is a neural network model but it is too huge, so I've added the above code. I want to call the func without changing the graph of model but it changes. I read

how to create Keras multi LSTM layer using for loop?

左心房为你撑大大i 提交于 2019-12-24 08:59:54
问题 I'm trying to implement a multi layer LSTM in Keras using for loop and this tutorial to be able to optimize the number of layers, which is obviously a hyper-parameter. In the tutorial, the author used skopt for hyper-parameter optimization . I used Functional API to create my model. For simplicity, I changed input_tensor 's shape to arbitrary values. My model is: from keras.layers.core import Dense from keras.layers import LSTM, Input from keras.models import Model from keras.optimizers

Masking zero inputs in LSTM in keras without using embedding

落爺英雄遲暮 提交于 2019-12-24 08:26:11
问题 I am training an LSTM in Keras: iclf = Sequential() iclf.add(Bidirectional(LSTM(units=10, return_sequences=True, recurrent_dropout=0.3), input_shape=(None,2048))) iclf.add(TimeDistributed(Dense(1, activation='sigmoid'))) The input to each cell is a 2048 vector which is known and need not to be learned (if you will, they are the ELMo embeddings of the words in the input sentences). Therefore, here I have not the Embedding layer. Since the input sequences have variable lengths, they are padded

InvalidArgumentError: indices[0,0] = -1 is not in [0, 10)

懵懂的女人 提交于 2019-12-24 07:39:16
问题 It worked well with MLP for binary classification. In LSTM and in convolution however it gives the InvalidArgumentError . I found that y needs to be reshaped and I did it. I tried x with all positive values, and model worked well. So what is the problem with negative values? The data is given in the code. Any ideas? The error is like: --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) /usr/local/src/conda3_runtime

Python - Pattern prediction using LSTM Recurrent Neural Networks with Keras

a 夏天 提交于 2019-12-24 07:13:34
问题 I am dealing with pattern prediction from a formatted CSV dataset with three columns (time_stamp, X and Y - where Y is the actual value). I wanted to predict the value of X from Y based on time index from past values and here is how I approached the problem with LSTM Recurrent Neural Networks in Python with Keras. import numpy as np import pandas as pd import matplotlib.pyplot as plt from keras.models import Sequential from keras.layers import LSTM, Dense from keras.preprocessing.sequence

How to switch Off/On an LSTM layer?

时间秒杀一切 提交于 2019-12-24 06:34:49
问题 I am looking for a way to access the LSTM layer such that the addition and subtraction of a layer are event-driven. So the Layer can be added or subtracted when there is a function trigger. For Example (hypothetically): Add an LSTM layer if a = 2 and remove an LSTM layer if a = 3. Here a = 2 and a= 3 is supposed to be a python function which returns specific value based on which the LSTM layer should be added or removed. I want to add a switch function to the layer so that it can be switched

Dynamic graphs in tensorflow

老子叫甜甜 提交于 2019-12-24 05:57:30
问题 I would like to implement a 2D LSTM as in this paper, specifically I would like to do so dynamically, so using tf.while. In brief this network works as follows. order the pixels in an image so that pixel i, j -> i * width + j run a 2D-LSTM over this sequence The difference between a 2D and regular LSTM is we have a recurrent connection between the previous element in the sequence and the pixel directly above the current pixel, so at pixel i,j are connections to i - 1, j and i, j - 1. What I

LSTM - Use deltaTime as a feature? How to handle irregular timestamps?

家住魔仙堡 提交于 2019-12-24 04:48:11
问题 I'm trying to create a LSTM for classification of data sequences. The data structure of every training input that I would use is: [[ [deltaX,deltaY,deltaTime], [deltaX,deltaY,deltaTime],... ],class] Where deltaX and deltaY reflect the change of X and Y in a given time deltaTime. deltaTime is not the same everytime, it can vary from 40ms to 50ms to sometimes 1000ms. The 'class' at the end is a binary classification, that can be either 0 or 1. Question 1 (regular LSTM): Should I include

Zero predictions despite masking support for zero-padded mini batch LSTM training in keras

雨燕双飞 提交于 2019-12-24 03:46:10
问题 Problem Statement I’m training a many-to-many LSTM in keras with tensorflow backend (tf version 1.13.1) on tagged text sequences to predict the tag of each element in the sequence using pretrained GloVe embeddings. My training regime involves mini batch stochastic gradient descent, with each mini batch matrix zero-padded column-wise to ensure equal length input to the network. Crucially, because of custom constrains on my mini batches due to the nature of the task and the data, I am not using