for start_idx in range(0, len(inputs) - batchsize + 1, batchsize): if shuffle: excerpt = indices[start_idx:start_idx + batchsize] else: excerpt = slice(start_idx, start_idx + batchsize) yield inputs[excerpt], targets[excerpt] # Create the Network print "Embeddings shape", embeddings.shape model = Sequential() model.add( FixedEmbedding(output_dim=embeddings.shape[1], input_dim=embeddings.shape[0], input_length=MAX_LENGTH, weights=[embeddings])) # Hidden + Softmax Layer model.add( LSTM( output_dim=MAX_LENGTH, init='glorot_uniform', activation='tanh', batch_input_shape=(None, MAX_LENGTH, embeddings.shape[1]), return_sequences=True, )) model.add(Dropout(0.5)) model.add( LSTM( output_dim=MAX_LENGTH, init='glorot_uniform',
if shuffle: excerpt = indices[start_idx:start_idx + batchsize] else: excerpt = slice(start_idx, start_idx + batchsize) yield inputs[excerpt], targets[excerpt] # Create the Network print "Embeddings shape", embeddings.shape model = Sequential() # Embeddings layers, lookups the word indices and maps them to their dense vectors. FixedEmbeddings are _not_ updated during training # If you switch it to an Embedding-Layer, they will be updated (training time increases significant) model.add( FixedEmbedding(output_dim=embeddings.shape[1], input_dim=embeddings.shape[0], input_length=n_in, weights=[embeddings])) # Hidden + Softmax Layer model.add( LSTM(output_dim=n_hidden, init='glorot_uniform', activation='tanh', batch_input_shape=(None, n_in, embeddings.shape[1]), return_sequences=True)) model.add(Dropout(0.5)) model.add( LSTM(output_dim=n_hidden, init='glorot_uniform', activation='tanh', batch_input_shape=(None, n_in, n_hidden))) model.add(Dense(output_dim=n_out, activation='softmax'))
number_of_epochs = 10 minibatch_size = 35 embedding_size = embeddings.shape[1] dim_case = 6 x = T.imatrix('x') # the data, one word+context per row y = T.ivector('y') # the labels are presented as 1D vector of [int] labels print "Embeddings shape", embeddings.shape words = Sequential() words.add( FixedEmbedding(output_dim=embeddings.shape[1], input_dim=embeddings.shape[0], input_length=n_in, weights=[embeddings])) #input_length=n_in, words.add(Flatten()) casing = Sequential() #casing.add(Embedding(output_dim=dim_case, input_dim=len(caseLookup), input_length=n_in)) casing.add( FixedEmbedding(output_dim=caseMatrix.shape[1], input_dim=caseMatrix.shape[0], input_length=n_in, weights=[caseMatrix])) casing.add(Flatten()) model = Sequential() model.add(Merge([words, casing], mode='concat'))