lstm

PyTorch - How to deactivate dropout in evaluation mode

杀马特。学长 韩版系。学妹 提交于 2020-08-22 09:34:11
问题 This is the model I defined it is a simple lstm with 2 fully connect layers. import copy import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim class mylstm(nn.Module): def __init__(self,input_dim, output_dim, hidden_dim,linear_dim): super(mylstm, self).__init__() self.hidden_dim=hidden_dim self.lstm=nn.LSTMCell(input_dim,self.hidden_dim) self.linear1=nn.Linear(hidden_dim,linear_dim) self.linear2=nn.Linear(linear_dim,output_dim) def forward(self, input)

Trying to understand Pytorch's implementation of LSTM

不羁的心 提交于 2020-07-21 04:59:37
问题 I have a dataset containing 1000 examples where each example has 5 features (a,b,c,d,e). I want to feed 7 examples to an LSTM so it predicts the feature (a) of the 8th day. Reading Pytorchs documentation of nn.LSTM() I came up with the following: input_size = 5 hidden_size = 10 num_layers = 1 output_size = 1 lstm = nn.LSTM(input_size, hidden_size, num_layers) fc = nn.Linear(hidden_size, output_size) out, hidden = lstm(X) # Where X's shape is ([7,1,5]) output = fc(out[-1]) output # output's

Question about Permutation Importance on LSTM Keras

拟墨画扇 提交于 2020-07-19 11:01:29
问题 from keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor import eli5 from eli5.sklearn import PermutationImportance model = Sequential() model.add(LSTM(units=30,return_sequences= True, input_shape=(X.shape[1],421))) model.add(Dropout(rate=0.2)) model.add(LSTM(units=30, return_sequences=True)) model.add(LSTM(units=30)) model.add(Dense(units=1, activation='relu')) perm = PermutationImportance(model, scoring='accuracy',random_state=1).fit(X, y, epochs=500, batch_size=8) eli5.show

What is the difference between the trainable_weights and trainable_variables in the tensorflow basic lstm_cell?

我是研究僧i 提交于 2020-07-18 17:39:51
问题 While trying to copy the weights of a LSTM Cell in Tensorflow using the Basic LSTM Cell as documented here, i stumbled upon both the trainable_weights and trainable_variables property. Source code has not really been informative for a noob like me sadly. A little bit of experimenting did yield the following information though: Both have the exact same layout, being a list of length two, where the first entry is a tf.Variable of shape: (2*num_units, 4*num_units), the second entry of the list

keras lstm incorrect input_shape

我的梦境 提交于 2020-07-09 02:36:53
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated last month . I am trying to use a lstm model to predict the weather (mainly to learn about lstm's and using python). I have a dataset of 500,000 rows each of which represents a date and there are 8 columns which are my features. Below is my model. model = Sequential() model.add(LSTM(50, input_shape=(30, 8), return_sequences=True)) model.add(Dropout(0.2)) model.add(LSTM(100, return_sequences

What's the input of each LSTM layer in a stacked LSTM network?

萝らか妹 提交于 2020-07-08 03:12:26
问题 I'm having some difficulty understanding the input-output flow of layers in stacked LSTM networks. Let's say i have created a stacked LSTM network like the one below: # parameters time_steps = 10 features = 2 input_shape = [time_steps, features] batch_size = 32 # model model = Sequential() model.add(LSTM(64, input_shape=input_shape, return_sequences=True)) model.add(LSTM(32,input_shape=input_shape)) where our stacked-LSTM network consists of 2 LSTM layers with 64 and 32 hidden units

Keras lstm and dense layer

ε祈祈猫儿з 提交于 2020-06-28 09:25:06
问题 How is dense layer changing the output coming from LSTM layer? How come that from 50 shaped output from previous layer i get output of size 1 from dense layer that is used for prediction? Lets say i have this basic model: model = Sequential() model.add(LSTM(50,input_shape=(60,1))) model.add(Dense(1, activation="softmax")) Is the Dense layer taking the values coming from previous layer and assigning the probablity(using softmax function) of each of the 50 inputs and then taking it out as an

Fixing shape on a stateful LSTM predictions for a regression problem

佐手、 提交于 2020-06-27 06:10:25
问题 Based on this stackoverflow post and this one, I'm trying to build an RNN LSTM model to predict on a regression problem. My data is 25 batches of 2720 samples with 16 features each, some batches are padded with -10 values. I've build the following model: model = Sequential() opt = Adam(learning_rate=0.0001, clipnorm=1) num_samples = train_x.shape[1] num_features = train_x.shape[2] # Masking -10 rows model.add(Masking(mask_value=-10., input_shape=(num_samples, num_features))) model.add(LSTM(32

Keras: stacking multiple LSTM layer with

谁都会走 提交于 2020-06-26 07:24:09
问题 I have the following network which works fine: output = LSTM(8)(output) output = Dense(2)(output) Now for the same model, I am trying to stack a few LSTM layer like below: output = LSTM(8)(output, return_sequences=True) output = LSTM(8)(output) output = Dense(2)(output) But I got the following errors: TypeError Traceback (most recent call last) <ipython-input-2-0d0ced2c7417> in <module>() 39 40 output = Concatenate(axis=2)([leftOutput,rightOutput]) ---> 41 output = LSTM(8)(output, return

Does a clean and extendable LSTM implementation exists in PyTorch?

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-22 07:31:05
问题 I would like to create an LSTM class by myself, however, I don't want to rewrite the classic LSTM functions from scratch again. Digging in the code of PyTorch , I only find a dirty implementation involving at least 3-4 classes with inheritance: https://github.com/pytorch/pytorch/blob/98c24fae6b6400a7d1e13610b20aa05f86f77070/torch/nn/modules/rnn.py#L323 https://github.com/pytorch/pytorch/blob/98c24fae6b6400a7d1e13610b20aa05f86f77070/torch/nn/modules/rnn.py#L12 https://github.com/pytorch