rnn

Keras: Wrong Input Shape in LSTM Neural Network

我是研究僧i 提交于 2021-02-19 08:26:35
问题 I am trying to train an LSTM recurrent neural network, for sequence classification. My data has the following formart: Input: [1,5,2,3,6,2, ...] -> Output: 1 Input: [2,10,4,6,12,4, ...] -> Output: 1 Input: [4,1,7,1,9,2, ...] -> Output: 2 Input: [1,3,5,9,10,20, ...] -> Output: 3 . . . So basically I want to provide a sequence as an input and get an integer as an output. Each input sequence has length = 2000 float numbers, and I have around 1485 samples for training The output is just an

Delayed echo of sin - cannot reproduce Tensorflow result in Keras

早过忘川 提交于 2021-02-19 04:54:20
问题 I am experimenting with LSTMs in Keras with little to no luck. At some moment I decided to scale back to the most basic problems in order finally achieve some positive result. However, even with simplest problems I find that Keras is unable to converge while the implementation of the same problem in Tensorflow gives stable result. I am unwilling to just switch to Tensorflow without understanding why Keras keeps diverging on any problem I attempt. My problem is a many-to-many sequence

How does shuffle = 'batch' argument of the .fit() layer work in the background?

白昼怎懂夜的黑 提交于 2021-02-07 14:25:30
问题 When I train the model using the .fit() layer there is the argument shuffle preset to True. Let's say that my dataset has 100 samples and that the batch size is 10. When I set shuffle = True then keras first randomly selects randomly the samples (now the 100 samples have a different order) and on the new order it will start creating the batches: batch 1: 1-10, batch 2: 11-20 etc. If I set shuffle = 'batch' how is it supposed to work in the background? Intuitively and using the previous

InvalidArgumentError: Received a label value of 8825 which is outside the valid range of [0, 8825) SEQ2SEQ model

这一生的挚爱 提交于 2021-01-27 18:48:30
问题 I have been trying to build RNN with Seq2Seq model from Udemy course called DeepLearning_NLP_Chatbot, and I followed him step by step, but I face when training an error: InvalidArgumentError : Received a label value of 8825 which is outside the valid range of [0, 8825). The dataset here. here is the data procesing dataset # Building a Chatbot with Deep NLP. # Importing the libraries. import numpy as np import tensorflow as tf import re import time # ---Data Processing---# #-------------------

Understanding a simple LSTM pytorch

南楼画角 提交于 2020-05-24 08:10:50
问题 import torch,ipdb import torch.autograd as autograd import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch.autograd import Variable rnn = nn.LSTM(input_size=10, hidden_size=20, num_layers=2) input = Variable(torch.randn(5, 3, 10)) h0 = Variable(torch.randn(2, 3, 20)) c0 = Variable(torch.randn(2, 3, 20)) output, hn = rnn(input, (h0, c0)) This is the LSTM example from the docs. I don't know understand the following things: What is output-size and why is it

How to visualize attention weights?

淺唱寂寞╮ 提交于 2020-04-08 06:59:06
问题 Using this implementation I have included attention to my RNN (which classify the input sequences into two classes) as follows. visible = Input(shape=(250,)) embed=Embedding(vocab_size,100)(visible) activations= keras.layers.GRU(250, return_sequences=True)(embed) attention = TimeDistributed(Dense(1, activation='tanh'))(activations) attention = Flatten()(attention) attention = Activation('softmax')(attention) attention = RepeatVector(250)(attention) attention = Permute([2, 1])(attention) sent