lstm

GridSearchCV/RandomizedSearchCV with LSTM

邮差的信 提交于 2019-12-04 05:37:44
问题 I am stuck on the trying to tune hyperparameters for LSTM via RandomizedSearchCV. My code is below: X_train = X_train.reshape((X_train.shape[0], 1, X_train.shape[1])) X_test = X_test.reshape((X_test.shape[0], 1, X_test.shape[1])) print(X_train.shape, y_train.shape, X_test.shape, y_test.shape) from imblearn.pipeline import Pipeline from keras.initializers import RandomNormal def create_model(activation_1='relu', activation_2='relu', neurons_input = 1, neurons_hidden_1=1, optimizer='Adam' ,

Varying sequence length in Keras without padding

早过忘川 提交于 2019-12-04 04:38:46
I have a question regarding varying sequence lengths for LSTMs in Keras. I'm passing batches of size 200 and sequences of variable lengths (= x) with 100 features for each object in the sequence (=> [200, x, 100]) into a LSTM: LSTM(100, return_sequences=True, stateful=True, input_shape=(None, 100), batch_input_shape=(200, None, 100)) I'm fitting the model on the following randomly created matrices: x_train = np.random.random((1000, 50, 100)) x_train_2 = np.random.random((1000, 10,100)) As far as I understood LSTMs (and the Keras implementation) correctly, the x should refer to the number of

How to feed into LSTM with 4 dimensional input?

删除回忆录丶 提交于 2019-12-04 03:24:47
问题 I have a sequence input in this shape: (6000, 64, 100, 50) The 6000 is just the number of sample sequences. Each sequences is 64 in length. I plan to fit this input into an LSTM using Keras. I setup my input this way: input = Input(shape=(64, 100, 50)) This gives me an input shape of (?, 64, 100, 50) However, when I put input into my LSTM like so: x = LSTM(256, return_sequences=True)(input) I get this error: Input 0 is incompatible with layer lstm_37: expected ndim=3, found ndim=4 This would

How should we pad text sequence in keras using pad_sequences?

我的梦境 提交于 2019-12-04 03:21:12
I have coded a sequence to sequence learning LSTM in keras myself using the knowledge gained from the web tutorials and my own intuitions. I converted my sample text to sequences and then padded using pad_sequence function in keras. from keras.preprocessing.text import Tokenizer,base_filter from keras.preprocessing.sequence import pad_sequences def shift(seq, n): n = n % len(seq) return seq[n:] + seq[:n] txt="abcdefghijklmn"*100 tk = Tokenizer(nb_words=2000, filters=base_filter(), lower=True, split=" ") tk.fit_on_texts(txt) x = tk.texts_to_sequences(txt) #shifing to left y = shift(x,1)

Padding time-series subsequences for LSTM-RNN training

余生颓废 提交于 2019-12-04 02:59:29
问题 I have a dataset of time series that I use as input to an LSTM-RNN for action anticipation. The time series comprises a time of 5 seconds at 30 fps (i.e. 150 data points), and the data represents the position/movement of facial features. I sample additional sub-sequences of smaller length from my dataset in order to add redundancy in the dataset and reduce overfitting. In this case I know the starting and ending frame of the sub-sequences. In order to train the model in batches, all time

Multivariate LSTM Forecast Loss and evaluation

こ雲淡風輕ζ 提交于 2019-12-03 23:05:08
问题 I have a CNN-RNN model architecture with Bidirectional LSTMS for time series regression problem. My loss does not converge over 50 epochs. Each epoch has 20k samples. The loss keeps bouncing between 0.001 - 0.01 . batch_size=1 epochs = 50 model.compile(loss='mean_squared_error', optimizer='adam') trainingHistory=model.fit(trainX,trainY,epochs=epochs,batch_size=batch_size,shuffle=False) I tried to train the model with incorrectly paired X and Y data for which the loss stays around 0.5 , is it

python在Keras中使用LSTM解决序列问题

房东的猫 提交于 2019-12-03 20:15:23
原文链接: http://tecdat.cn/?p=8461 时间序列预测是指我们必须根据时间相关的输入来预测结果的问题类型。时间序列数据的典型示例是股市数据,其中股价随时间变化。 递归神经网络 (RNN)已被证明可以有效解决序列问题。特别地,作为RNN的变体的 长期短期记忆网络 (LSTM)当前正在各种领域中用于解决序列问题。 序列问题的类型 序列问题可以大致分为以下几类: 一对一: 其中有一个输入和一个输出。一对一序列问题的典型示例是您拥有一幅图像并且想要为该图像预测单个标签的情况。 多对一: 在多对一序列问题中,我们将数据序列作为输入,并且必须预测单个输出。文本分类是多对一序列问题的主要示例,其中我们有一个单词输入序列,并且我们希望预测一个输出标签。 一对多: 在一对多序列问题中,我们只有一个输入和一个输出序列。典型示例是图像及其相应的说明。 多对多 :多对多序列问题涉及序列输入和序列输出。例如,将7天的股票价格作为输入,并将接下来7天的股票价格作为输出。聊天机器人还是多对多序列问题的一个示例,其中文本序列是输入,而另一个文本序列是输出。 在本文中,我们将了解如何使用LSTM及其不同的变体来解决一对一和多对一的序列问题。 阅读本文后,您将能够基于历史数据解决诸如股价预测, 天气预报 等问题。由于文本也是单词序列,因此本文中获得的知识也可以用于解决 自然语言处理 任务

Tensorflow LSTM - Matrix multiplication on LSTM cell

╄→гoц情女王★ 提交于 2019-12-03 19:25:18
I'm making a LSTM neural network in Tensorflow. The input tensor size is 92. import tensorflow as tf from tensorflow.contrib import rnn import data test_x, train_x, test_y, train_y = data.get() # Parameters learning_rate = 0.001 epochs = 100 batch_size = 64 display_step = 10 # Network Parameters n_input = 28 # input size n_hidden = 128 # number of hidden layers n_classes = 20 # output size # Placeholders x = tf.placeholder(dtype=tf.float32, shape=[None, n_input]) y = tf.placeholder(dtype=tf.float32, shape=[None, n_classes]) # Network def LSTM(x): W = tf.Variable(tf.random_normal([n_hidden, n

Add dense layer before LSTM layer in keras or Tensorflow?

人盡茶涼 提交于 2019-12-03 17:27:19
I am trying to implement a denoising autoencoder with an LSTM layer in between. The architecture goes following. FC layer -> FC layer -> LSTM cell -> FC layer -> FC layer. I am unable to understand how my input dimension should be to implement this architecture? I tried the following code batch_size = 1 model = Sequential() model.add(Dense(5, input_shape=(1,))) model.add(Dense(10)) model.add(LSTM(32)) model.add(Dropout(0.3)) model.add(Dense(5)) model.add(Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam') model.fit(trainX, trainY, nb_epoch=100, batch_size=batch_size, verbose=2

Using Dropout with Keras and LSTM/GRU cell

点点圈 提交于 2019-12-03 17:19:43
问题 In Keras you can specify a dropout layer like this: model.add(Dropout(0.5)) But with a GRU cell you can specify the dropout as a parameter in the constructor: model.add(GRU(units=512, return_sequences=True, dropout=0.5, input_shape=(None, features_size,))) What's the difference? Is one preferable to the other? In Keras' documentation it adds it as a separate dropout layer (see "Sequence classification with LSTM") 回答1: The recurrent layers perform the same repeated operation over and over. In