lstm

Keras: How to shape inputs for CNN and LSTM layers?

為{幸葍}努か 提交于 2019-12-24 03:39:10
问题 I am building a model to predict geospatial-temporal datasets. My data has original dimensions (features, lat, lon, time), i.e. for each feature and at each lat/lon point there is a time series. I have created a CNN-LSTM model using Keras like so (I assume the below needs to be modified, this is just a first attempt): def define_model_cnn_lstm(features, lats, lons, times): """ Create and return a model with CN and LSTM layers. Input and output data is expected to have shape (lats, lons, times

The meaning of batch_size in ptb_word_lm (LSTM model of tensorflow)

放肆的年华 提交于 2019-12-24 01:16:23
问题 I am new to tensorflow, i am now a little confused about the meaning of batch_size . As commonly known that the meaning of batch_size is the number of samples for each batch, but according to the code in ptb_word_lm , it seems not: reader.py: data_len = tf.size(raw_data) #the number of words in dataset batch_len = data_len // batch_size What does batch_len mean? The number of batches? ptb_word_lm.py: self.epoch_size = ((len(data) // batch_size) - 1) // num_steps What does epoch_size mean? The

How to use previous output and hidden states from LSTM for the attention mechanism?

我是研究僧i 提交于 2019-12-24 00:59:32
问题 I am currently trying to code the attention mechanism from this paper: "Effective Approaches to Attention-based Neural Machine Translation", Luong, Pham, Manning (2015). (I use global attention with the dot score). However, I am unsure on how to input the hidden and output states from the lstm decode. The issue is that the input of the lstm decoder at time t depends on quantities that I need to compute using the output and hidden states from t-1. Here is the relevant part of the code: with tf

Multivariate binary sequence prediction with LSTM

放肆的年华 提交于 2019-12-23 21:19:36
问题 I'm working on a sequence forecasting problem and I don't have much experience in this area, so some of the below questions might be naive. FYI: I've created a follow-up question with a focus on CRFs here I have the following problem: I would like to forecast a binary sequence for multiple, non-independent variables. Inputs: I have a dataset with the following variables: Timestamps Groups A and B Binary signal corresponding to each group at a particular timestamp Additionally, suppose the

How to use fit_generator with sequential data that is split into batches?

非 Y 不嫁゛ 提交于 2019-12-23 19:51:05
问题 I am trying to write a generator for my Keras lstm model. To use it with fit_generator method. My first question is what should my generator return? A batch? A sequence? Example in Keras documentation returns x,y for each data entry, but what if my data is sequential? And I want to split it into batches? Here is the python method that creates a batch for a given input def get_batch(data, batch_num, batch_size, seq_length): i_start = batch_num*batch_size; batch_sequences = [] batch_labels = []

Keras LSTM autoencoder with embedding layer

我是研究僧i 提交于 2019-12-23 15:49:27
问题 I am trying to build a text LSTM autoencoder in Keras. I want to use an embedding layer but I'am not sure how to implement this. The code looks like this. inputs = Input(shape=(timesteps, input_dim)) embedding_layer = Embedding(numfeats + 1, EMBEDDING_DIM, weights=[data_gen.get_embedding_matrix()], input_length=maxlen, trainable=False) embedded_sequence = embedding_layer(inputs) encoded = LSTM(num_units)(inputs) decoded = RepeatVector(timesteps)(encoded) decoded = LSTM(???, return_sequences

Connect Encoder from AutoEncoder to LSTM

寵の児 提交于 2019-12-23 13:39:37
问题 I have an auto encoder defined like this inputs = Input(batch_shape=(1,timesteps, input_dim)) encoded = LSTM(4,return_sequences = True)(inputs) encoded = LSTM(3,return_sequences = True)(encoded) encoded = LSTM(2)(encoded) decoded = RepeatVector(timesteps)(encoded) decoded = LSTM(3,return_sequences = True)(decoded) decoded = LSTM(4,return_sequences = True)(decoded) decoded = LSTM(input_dim,return_sequences = True)(decoded) sequence_autoencoder = Model(inputs, decoded) encoder = Model(inputs

Pytorch LSTM: Target Dimension in Calculating Cross Entropy Loss

时光怂恿深爱的人放手 提交于 2019-12-23 13:01:12
问题 I've been trying to get an LSTM (LSTM followed by a linear layer in a custom model), working in Pytorch, but was getting the following error when calculating the loss: Assertion cur_target >= 0 && cur_target < n_classes' failed. I defined the loss function with: criterion = nn.CrossEntropyLoss() and then called with loss += criterion(output, target) I was giving the target with dimensions [sequence_length, number_of_classes], and output has dimensions [sequence_length, 1, number_of_classes].

Neural Network Reinforcement Learning Requiring Next-State Propagation For Backpropagation

南笙酒味 提交于 2019-12-23 11:53:28
问题 I am attempting to construct a neural network incorporating convolution and LSTM (using the Torch library) to be trained by Q-learning or Advantage-learning, both of which require propagating state T+1 through the network before updating the weights for state T. Having to do an extra propagation would cut performance and that's bad, but not too bad; However, the problem is that there is all kinds of state bound up in this. First of all, the Torch implementation of backpropagation has some

CNTK Complaining about Dynamic Axis in LSTM

别来无恙 提交于 2019-12-23 07:28:10
问题 I'm trying to implement an LSTM in CNTK (using Python) to classify a sequence. Input: Features are fixed length sequences of numbers (a time series) Labels are vectors of one-hot values Network: input = input_variable(input_dim) label = input_variable(num_output_classes) h = Recurrence(LSTM(lstm_dim)) (input) final_output = C.sequence.last(h) z = Dense(num_output_classes) (final_output) loss = C.cross_entropy_with_softmax(z, label) Output: A probability that the sequence matches a label All