Code Monkey home page Code Monkey logo

Comments (3)

fchollet avatar fchollet commented on May 2, 2024

That is precisely how recurrent layers work, they take 3D inputs of shape (nb_samples, max_sample_length, input_dim). nb_samples is the batch size.

Can you post your model and explain what you were trying to do?

from keras.

lemuriandezapada avatar lemuriandezapada commented on May 2, 2024

Hey, so what I have is a list of strings of text of variable length. I turn them into a list of word sequences with the tokenizer. Ideally I'll turn it into a 1-of-N encoding but just for testing puposes now. I want to try to feed it one of these sequences and predict the next word.

toki.fit_on_texts(texts)
textseq = toki.texts_to_sequences(texts)
padtext = sequence.pad_sequences(textseq)
padtext = padtext.reshape(padtext.shape[0],padtext.shape[1],1) #4 1d sequences, each of length 400k
vocabsize = len(toki.word_index)

model = Sequential()
model.add(LSTM(vocabsize,128))
model.add(Dense(128, vocabsize, init='lecun_uniform'))
model.add(Activation('sigmoid'))

loss = RMSprop(lr=0.01, rho=0.9, epsilon=1e-6)
model.compile(loss='categorical_crossentropy', optimizer=loss, class_mode="categorical")

doing

model.fit(padtext[:,:-1,:],padtext[:,1:,:])

gives me the error

('Bad input argument to theano function with name "build/bdist.linux-x86_64/egg/keras/models.py:64"  at index 1(0-based)', 'Wrong number of dimensions: expected 2, got 3 with shape (4, 405985, 1).')

telling me LSTMs don't actually want 3d arrays. Ideas?

from keras.

lemuriandezapada avatar lemuriandezapada commented on May 2, 2024

It wasn't the LSTM, it was some other level in the network. Reshaping and flattening where required fixes most issues. Thanks :)

from keras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.