lstm

How do we use LSTM to classify sequences?

我是研究僧i 提交于 2019-12-11 07:01:25
问题 LSTM is good for predicting what is going to happen after a sequence, but I assume that we have many sequences and that each sequence corresponds to a class label. How can we use LSTM to classify these sequences? 回答1: LSTM can be used for prediction as well as classification tasks. For classification, you can follow most commonly used architectures that I have described below. However, you can build your own model depending on your requirement. As the output of LSTM (Here I explain dynamic

sequential model give a different result at every run

♀尐吖头ヾ 提交于 2019-12-11 06:09:25
问题 I have a python script for building a keras sequential model. Everytime i am getting different results without any changes in script. kindly have a look on script. where i am wrong please help. thedata = pandas.read_csv("C:/User/Downloads/LSTM/data.csv", sep=', ', delimiter=',', header='infer', names=None) np.random.seed(1337) x = thedata['Review'] y = thedata['Polarity_Numeral'] x = x.iloc[:].values y = y.iloc[:].values tk = Tokenizer(num_words=40000, lower=True, split=" ") tk.fit_on_texts(x

PyTorch ValueError: Target and input must have the same number of elements

非 Y 不嫁゛ 提交于 2019-12-11 05:31:59
问题 I am kinda new to PyTorch, but I am trying to understand how the sizes of target and input work in torch.nn.BCELoss() when computing loss function. import torch import torch.nn as nn from torch.autograd import Variable time_steps = 15 batch_size = 3 embeddings_size = 100 num_classes = 2 model = nn.LSTM(embeddings_size, num_classes) input_seq = Variable(torch.randn(time_steps, batch_size, embeddings_size)) lstm_out, _ = model(input_seq) last_out = lstm_out[-1] print(last_out) loss = nn.BCELoss

How to create a seq2seq without specifying a fixed decoder length?

情到浓时终转凉″ 提交于 2019-12-11 05:09:43
问题 Based on the model presented in this answer: def create_seq2seq(features_num,latent_dim,decoder_length): ## encoder_inputs = Input(shape=(None, features_num)) encoded = LSTM(latent_dim, return_state=False ,return_sequences=True)(encoder_inputs) encoded = LSTM(latent_dim, return_state=False ,return_sequences=True)(encoded) encoded = LSTM(latent_dim, return_state=False ,return_sequences=True)(encoded) encoded = LSTM(latent_dim, return_state=True)(encoded) encoder = Model (input=encoder_inputs,

Gradients error using TensorArray Tensorflow

天涯浪子 提交于 2019-12-11 04:53:56
问题 i am trying to implement multidimentional lstm in tensorflow, I am using TensorArray to remember previous states, i am using a complicated way to get two neigbours state(above and from left). tf.cond want that both posible condition to exist and to have the same number of inputs. this is why i added one more cell.zero_state to the (last index +1) of the states. then i using a function to get the correct indexes to the states. when i am trying to use an optimizer in order to minimize a cost, i

Keras中Sequential模型及方法详细总结

爷,独闯天下 提交于 2019-12-11 04:43:32
Sequential 序贯模型 序贯模型是函数式模型的简略版,为最简单的线性、从头到尾的结构顺序,不分叉,是多个网络层的线性堆叠。 Keras实现了很多层,包括core核心层,Convolution卷积层、Pooling池化层等非常丰富有趣的网络结构。 我们可以通过将层的列表传递给Sequential的构造函数,来创建一个Sequential模型。 from keras . models import Sequential from keras . layers import Dense , Activation model = Sequential ( [ Dense ( 32 , input_shape = ( 784 , ) ) , Activation ( 'relu' ) , Dense ( 10 ) , Activation ( 'softmax' ) , ] ) 也可以使用.add()方法将各层添加到模型中: model = Sequential ( ) model . add ( Dense ( 32 , input_dim = 784 ) ) model . add ( Activation ( 'relu' ) ) 指定输入数据的尺寸 模型需要知道它所期待的输入的尺寸(shape)。出于这个原因,序贯模型中的第一层(只有第一层,因为下面的层可以自动的推断尺寸

How to modify the seq2seq cost function for padded vectors?

試著忘記壹切 提交于 2019-12-11 04:43:08
问题 Tensorflow supports dynamic length sequence by use of the parameter: 'sequence_length' while constructing the RNN layer, wherein the model does not learn the sequence after the sequence size = 'sequence_length' i.e, returns zero vector. However, how can the cost function at https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/seq2seq.py#L890 be modified to encounter the masked sequences, so that cost and perplexity are calculated only on the actual sequences rather than

Tensorflow: how to obtain intermediate cell states (c) from LSTMCell using dynamic_rnn?

大兔子大兔子 提交于 2019-12-11 03:08:06
问题 By default, function dynamic_rnn outputs only hidden states (known as m ) for each time point which can be obtained as follows: cell = tf.contrib.rnn.LSTMCell(100) rnn_outputs, _ = tf.nn.dynamic_rnn(cell, inputs=inputs, sequence_length=sequence_lengths, dtype=tf.float32) Is there a way get intermediate (not final) cell states ( c ) in addition? A tensorflow contributor mentions that it can be done with a cell wrapper: class Wrapper(tf.nn.rnn_cell.RNNCell): def __init__(self, inner_cell):

Keras One Hot Encoding Memory Management - best Possible way out

安稳与你 提交于 2019-12-11 02:43:40
问题 I know this problem has been answered in different ways in the past. But I am not able to figure out and fit in my code and need help. I am using the cornell movie corpus as my dataset. Trying to train a LSTM model for chatbot is the final expectation. But I am stuck with initial one hot encoding and is getting out of memory. Note the VM I am training is 86GB memory but still having issues.In nmt_special_utils_mod.py the one hot encoding is going beyond allocated memory and I am not able to

Error in fitting an RNN LSTM model

冷暖自知 提交于 2019-12-11 01:51:40
问题 I am trying to create an RNN LSTM model for a binary classification using the following code alldataset = np.loadtxt("FinalKNEEALL.txt", delimiter=",") num_classes = 2 num_of_sam = alldataset.shape[0] labels = np.ones((num_of_sam,), dtype='int64') labels[0:958943]=0 labels[958943:1917887]=1 Y = np_utils.to_categorical(labels,num_classes) x,y = shuffle (alldataset,Y, random_state=2) x_train,x_test, y_train,y_test = train_test_split(x,y, test_size=0.3, random_state=4) print(x_train.shape) print