lstm

IndexError: index out of range in self

为君一笑 提交于 2021-01-29 07:40:29
问题 i got this error in runtime, can you please help me? my vocab size is 76, as shown in below, Some of my codes are below: class LSTMClassifier(nn.Module): def __init__(self, embed_size, hidden_size, vocab_size, num_layers, num_classes, batch_size): super(LSTMClassifier, self).__init__() self.embed_size = embed_size self.hidden_size = hidden_size self.batch_size = batch_size self.num_layers = num_layers self.embedding = nn.Embedding(vocab_size, embed_size) # a lookup table self.lstm = nn.LSTM

How to handle variable length data for LSTM

我怕爱的太早我们不能终老 提交于 2021-01-29 07:15:19
问题 From what I know the general steps to preprocess data for LSTM include the following steps vocab_size = 20000 # Only consider the top 20k words maxlen = 200 # Only consider the first 200 words of each movie review (x_train, y_train), (x_val, y_val) = keras.datasets.imdb.load_data(num_words=vocab_size) print(len(x_train), "Training sequences") print(len(x_val), "Validation sequences") x_train0 = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=maxlen) x_val0 = keras.preprocessing

Why do we use log probability in deep learning?

陌路散爱 提交于 2021-01-29 06:51:36
问题 I got curious while reading the paper 'Sequence to Sequence Learning with Neural Networks'. In fact, not only this paper but also many other papers use log probabilities, is there a reason for that? Please check the attached photo. 回答1: For any given problem we need to optimise the likelihood of parameters. But optimising the product require all data at once and requires huge computation. We know that a sum is a lot easier to optimise as the derivative of a sum is the sum of derivatives. So,

Can't set the attribute “trainable_weights”, likely because it conflicts with an existing read-only

假如想象 提交于 2021-01-29 06:10:42
问题 My code was running perfectly in colab. But today it's not running. It says Can't set the attribute "trainable_weights", likely because it conflicts with an existing read-only @property of the object. Please choose a different name. I am using LSTM with the attention layer. class Attention(Layer): def __init__(self, **kwargs): self.init = initializers.get('normal') #self.input_spec = [InputSpec(ndim=3)] super(Attention, self).__init__(**kwargs) def build(self, input_shape): assert len(input

How to extract cell state of LSTM model through model.fit()?

徘徊边缘 提交于 2021-01-29 05:47:37
问题 My LSTM model is like this, and I would like to get state_c def _get_model(input_shape, latent_dim, num_classes): inputs = Input(shape=input_shape) lstm_lyr,state_h,state_c = LSTM(latent_dim,dropout=0.1,return_state = True)(inputs) fc_lyr = Dense(num_classes)(lstm_lyr) soft_lyr = Activation('relu')(fc_lyr) model = Model(inputs, [soft_lyr,state_c]) model.compile(optimizer='adam', loss='mse', metrics=['accuracy']) return model model =_get_model((n_steps_in, n_features),latent_dim ,n_steps_out)

Cannot convert tf.keras.layers.ConvLSTM2D layer to open vino intermediate representation

狂风中的少年 提交于 2021-01-28 19:06:17
问题 I am trying to convert a trained model in tensorflow to Open VINO Intermediate Representation. I have a model of the form given below class Conv3DModel(tf.keras.Model): def __init__(self): super(Conv3DModel, self).__init__() # Convolutions self.conv1 = tf.compat.v2.keras.layers.Conv3D(32, (3, 3, 3), activation='relu', name="conv1", data_format='channels_last') self.pool1 = tf.keras.layers.MaxPool3D(pool_size=(2, 2, 2), data_format='channels_last') self.conv2 = tf.compat.v2.keras.layers.Conv3D

Keras LSTM: Return Empty Array on Predicition

喜夏-厌秋 提交于 2021-01-28 05:20:31
问题 I am trying to write my first LSTM with Keras and i'm stucking. That are my training data structure: x_data = [1265, 12] y_data = [1265, 3] x_data example: [102.7, 100.69, 103.39, 99.6, 319037.0, 365230.0, 1767412, 102.86, 13.98] y_data example: [0, 0, 1] My model looks like the following: self._opt_cells = 12 self.model = Sequential() self.model.add(LSTM(units = self._opt_cells, return_sequences = True, input_shape = (12, 1))) self.model.add(Dropout(0.2)) self.model.add(LSTM(units = self.

Validation Loss Much Higher Than Training Loss

亡梦爱人 提交于 2021-01-27 23:36:54
问题 I'm very new to deep learning models, and trying to train a multiple time series model using LSTM with Keras Sequential. There are 25 observations per year for 50 years = 1250 samples, so not sure if this is even possible to use LSTM for such small data. However, I have thousands of feature variables, not including time lags. I'm trying to predict a sequence of the next 25 time steps of data. The data is normalized between 0 and 1. My problem is that, despite trying many obvious adjustments,

ValueError: Data cardinality is ambiguous

跟風遠走 提交于 2021-01-27 13:09:35
问题 I'm trying to train LSTM network on data taken from a DataFrame. Here's the code: x_lstm=x.to_numpy().reshape(1,x.shape[0],x.shape[1]) model = keras.models.Sequential([ keras.layers.LSTM(x.shape[1], return_sequences=True, input_shape=(x_lstm.shape[1],x_lstm.shape[2])), keras.layers.LSTM(NORMAL_LAYER_SIZE, return_sequences=True), keras.layers.LSTM(NORMAL_LAYER_SIZE), keras.layers.Dense(y.shape[1]) ]) optimizer=keras.optimizers.Adadelta() model.compile(loss="mse", optimizer=optimizer) for i in

InvalidArgumentError: Specified a list with shape [60,9] from a tensor with shape [56,9]

一个人想着一个人 提交于 2021-01-27 06:38:23
问题 After running my model for one epoch it crashed with following error message: InvalidArgumentError: Specified a list with shape [60,9] from a tensor with shape [56,9] [[{{node TensorArrayUnstack/TensorListFromTensor}}]] [[sequential_7/lstm_17/PartitionedCall]] [Op:__inference_train_function_29986] This happened after I changed the LSTM Layer to stateful=True and had to pass the batch_input_shape Argument instead of the input_shape Below is my code, I'm sure it has something to do with the