b5a02391e003c33c8f8258a7e3d0736503c3c048,examples/babi_memnn.py,,,#,97

Before Change



// concatenate the match vector with the question vector,
// and do logistic regression on top
answer = Sequential()
answer.add(Merge([response, question_encoder], mode="concat", concat_axis=-1))
// the original paper uses a matrix multiplication for this reduction step.
// we choose to use a RNN instead.
answer.add(LSTM(32))
// one regularization layer -- more would probably be needed.
answer.add(Dropout(0.3))
answer.add(Dense(vocab_size))
// we output a probability distribution over the vocabulary
answer.add(Activation("softmax"))

answer.compile(optimizer="rmsprop", loss="categorical_crossentropy",
               metrics=["accuracy"])
// Note: you could use a Graph model to avoid repeat the input twice

After Change



// placeholders
input_sequence = Input((story_maxlen,))
question = Input((query_maxlen,))

// encoders
// embed the input sequence into a sequence of vectors
input_encoder_m = Sequential()
input_encoder_m.add(Embedding(input_dim=vocab_size,
                              output_dim=64))
input_encoder_m.add(Dropout(0.3))
// output: (samples, story_maxlen, embedding_dim)

// embed the input into a sequence of vectors of size query_maxlen
input_encoder_c = Sequential()
input_encoder_c.add(Embedding(input_dim=vocab_size,
                              output_dim=query_maxlen))
input_encoder_c.add(Dropout(0.3))
// output: (samples, story_maxlen, query_maxlen)

// embed the question into a sequence of vectors
question_encoder = Sequential()
question_encoder.add(Embedding(input_dim=vocab_size,
                               output_dim=64,
                               input_length=query_maxlen))
question_encoder.add(Dropout(0.3))
// output: (samples, query_maxlen, embedding_dim)

// encode input sequence and questions (which are indices) to sequences of dense vectors
input_encoded_m = input_encoder_m(input_sequence)
input_encoded_c = input_encoder_c(input_sequence)
question_encoded = question_encoder(question)

// compute a "match" between the first input vector sequence
// and the question vector sequence
match = dot([input_encoded_m, question_encoded], axes=(2, 2))  // (samples, story_maxlen, query_maxlen)
match = Activation("softmax")(match)

// add the match matrix with the second input vector sequence
response = add([match, input_encoded_c])  // (samples, story_maxlen, query_maxlen)
response = Permute((2, 1))(response)  // (samples, query_maxlen, story_maxlen)

// concatenate the match matrix with the question vector sequence
answer = concatenate([response, question_encoded])

// the original paper uses a matrix multiplication for this reduction step.
// we choose to use a RNN instead.
answer = LSTM(32)(answer)  // (samples, 32)

// one regularization layer -- more would probably be needed.
answer = Dropout(0.3)(answer)
answer = Dense(vocab_size)(answer)  // (samples, vocab_size)
// we output a probability distribution over the vocabulary
answer = Activation("softmax")(answer)

// build the final model
model = Model([input_sequence, question], answer)
model.compile(optimizer="rmsprop", loss="categorical_crossentropy",
               metrics=["accuracy"])

// train
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 14

Instances


Project Name: keras-team/keras
Commit Name: b5a02391e003c33c8f8258a7e3d0736503c3c048
Time: 2017-03-15
Author: farizrahman4u@gmail.com
File Name: examples/babi_memnn.py
Class Name:
Method Name:


Project Name: pyannote/pyannote-audio
Commit Name: 47966c5e49342ef9ff53c6db75a4905ffe864e4d
Time: 2016-06-21
Author: bredin@limsi.fr
File Name: pyannote/audio/models.py
Class Name: TripletLossSequenceEmbedding
Method Name: _embedding


Project Name: nl8590687/ASRT_SpeechRecognition
Commit Name: 5f73fe0599380479a37029de1d5647f33aae18c8
Time: 2017-09-04
Author: 3210346136@qq.com
File Name: main.py
Class Name: ModelSpeech
Method Name: CreateModel