recurrent-neural-network

Bert Embedding Layer raises `Type Error: unsupported operand type(s) for +: 'None Type' and 'int'` with BiLSTM

纵然是瞬间 提交于 2019-12-04 03:49:22
问题 I've problems integrating Bert Embedding Layer in a BiLSTM model for word sense disambiguation task, Windows 10 Python 3.6.4 TenorFlow 1.12 Keras 2.2.4 No virtual environments were used PyCharm Professional 2019.2 The whole script import os import yaml import numpy as np from argparse import ArgumentParser import tensorflow as tf import tensorflow_hub as hub from tensorflow.keras.layers import (LSTM, Add, Bidirectional, Dense, Input, TimeDistributed, Embedding) from tensorflow.keras

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

Wrong number of dimensions on model.fit

馋奶兔 提交于 2019-12-04 02:46:50
I'm trying to run this SimpleRNN: model.add(SimpleRNN(init='uniform',output_dim=1,input_dim=len(pred_frame.columns))) model.compile(loss="mse", optimizer="sgd") model.fit(X=predictor_train, y=target_train, batch_size=len(pred_frame.index),show_accuracy=True) The error is on model.fit, as you can see below: File "/Users/file.py", line 1496, in Pred model.fit(X=predictor_train, y=target_train, batch_size=len(pred_frame.index),show_accuracy=True) File "/Library/Python/2.7/site-packages/keras/models.py", line 581, in fit shuffle=shuffle, metrics=metrics) File "/Library/Python/2.7/site-packages

How to plot a learning curve for a keras experiment?

Deadly 提交于 2019-12-04 02:20:44
I'm training an RNN using keras and would like to see how the validation accuracy changes with the data set size. Keras has a list called val_acc in its history object which gets appended after every epoch with the respective validation set accuracy ( link to the post in google group ). I want to get the average of val_acc for the number of epochs run and plot that against the respective data set size. Question: How can I retrieve the elements in the val_acc list and perform an operation like numpy.mean(val_acc) ? EDIT: As @runDOSrun said, getting the mean of the val_acc s doesn't make sense.

Is there a way to implement recurrence in numpy without for-loops?

主宰稳场 提交于 2019-12-03 22:36:22
问题 I have the following problem. There is a matrix X and I need to generate a matrix H such that values of i_th row in matrix H are determined by i_th row of the matrix X and (i-1)_th row of matrix H . H_{i} = F(X_{i}, H_{i-1}) To calculate the first row of matrix H we use a special out-of-the-matrix row (row zero, so to say). Is there a way to implement this recurrence efficiently, in a vectorized form, without using for loops? 回答1: There is no other way (in general) except for an explicit for

Layer called with an input that isn't a symbolic tensor keras

风格不统一 提交于 2019-12-03 22:28:59
I'm trying to pass the output of one layer into two different layers and then join them back together. However, I'm being stopped by this error which is telling me that my input isn't a symbolic tensor. Received type: <class 'keras.layers.recurrent.LSTM'>. All inputs to the layers should be tensors. However, I believe I'm following the documentation quite closely: https://keras.io/getting-started/functional-api-guide/#multi-input-and-multi-output-models and am not entirely sure why this is wrong? net_input = Input(shape=(maxlen, len(chars)), name='net_input') lstm_out = LSTM(128, input_shape=

How to determine maximum batch size for a seq2seq tensorflow RNN training model

北城以北 提交于 2019-12-03 16:41:40
Currently, I am using the default 64 as the batch size for the seq2seq tensorflow model. What is the maximum batch size , layer size etc I can go with a single Titan X GPU with 12 GB RAM with Haswell-E xeon 128GB RAM. The input data is converted to embeddings. Following are some helpful parameters I am using , it seems the cell input size is 1024: encoder_inputs: a list of 2D Tensors [batch_size x cell.input_size]. decoder_inputs: a list of 2D Tensors [batch_size x cell.input_size]. tf.app.flags.DEFINE_integer("size", 1024, "Size of each model layer.") So based on my hardware what is the

TensorFlow dynamic_rnn regressor: ValueError dimension mismatch

佐手、 提交于 2019-12-03 14:57:48
I would like to build a toy LSTM model for regression. This nice tutorial is already too complicated for a beginner. Given a sequence of length time_steps , predict the next value. Consider time_steps=3 and the sequences: array([ [[ 1.], [ 2.], [ 3.]], [[ 2.], [ 3.], [ 4.]], ... the target values should be: array([ 4., 5., ... I define the following model: # Network Parameters time_steps = 3 num_neurons= 64 #(arbitrary) n_features = 1 # tf Graph input x = tf.placeholder("float", [None, time_steps, n_features]) y = tf.placeholder("float", [None, 1]) # Define weights weights = { 'out': tf

Batch-major vs time-major LSTM

给你一囗甜甜゛ 提交于 2019-12-03 14:00:34
Do RNNs learn different dependency patterns when the input is batch-major as opposed to time-major? (Edit: sorry my initial argument was why it makes sense but I realized that it doesn't so this is a little OT.) I haven't found the TF-groups reasoning behind this but it does does not make computational sense as ops are written in C++. Intuitively, we want to mash up (multiply/add etc) different features from the same sequence on the same timestep. Different timesteps can’t be done in parallell while batch/sequences can so feature>batch/sequence>timestep. By default Numpy and C++ uses row-major

Regularization for LSTM in tensorflow

喜夏-厌秋 提交于 2019-12-03 13:33:45
问题 Tensorflow offers a nice LSTM wrapper. rnn_cell.BasicLSTM(num_units, forget_bias=1.0, input_size=None, state_is_tuple=False, activation=tanh) I would like to use regularization, say L2 regularization. However, I don't have direct access to the different weight matrices used in the LSTM cell, so I cannot explicitly do something like loss = something + beta * tf.reduce_sum(tf.nn.l2_loss(weights)) Is there a way to access the matrices or use regularization somehow with LSTM? 回答1: tf.trainable