Exemple #1
0
    def build_model(self):
        premise = Sequential()
        premise.add(
            LSTM(input_shape=self.ds.X_p_train.shape[1:],
                 output_dim=ve.HIDDEN_SIZE))
        premise.add(Dropout(ve.DROPOUT_PROB))

        hypothesis = Sequential()
        hypothesis.add(
            LSTM(input_shape=self.ds.X_h_train.shape[1:],
                 output_dim=ve.HIDDEN_SIZE))
        hypothesis.add(Dropout(ve.DROPOUT_PROB))

        model = Sequential()
        model.add(Merge([premise, hypothesis], mode=ve.CONCAT))
        model.add(
            Dense(output_dim=ve.HIDDEN_SIZE,
                  activation=ve.TANH,
                  W_regularizer=l2(self.hp.dense_l2)))
        model.add(
            Dense(output_dim=ve.NLI_CLASSES,
                  activation=ve.SOFTMAX,
                  W_regularizer=l2(self.hp.dense_l2)))

        ve.compile_other_model(model, self.hp.optimizer)

        return model
Exemple #2
0
    def build_model(self):

        vector_input = Sequential()
        vector_input.add(
            Embedding(input_dim=len(self.ds.vocab),
                      output_dim=ve.EMBEDDING_SIZE,
                      weights=[self.ds.weights],
                      input_length=ve.WINDOW_SIZE))
        caps_input = Sequential()
        caps_input.add(
            Embedding(input_dim=ve.CAPS_DIMS,
                      output_dim=ve.CAPS_DIMS,
                      weights=[np.eye(ve.CAPS_DIMS)],
                      input_length=ve.WINDOW_SIZE))
        model = Sequential()
        model.add(Merge([vector_input, caps_input], mode=ve.CONCAT))
        model.add(
            Reshape(((ve.EMBEDDING_SIZE + ve.CAPS_DIMS) * ve.WINDOW_SIZE, )))
        model.add(Dense(output_dim=ve.HIDDEN_SIZE))
        model.add(Activation(ve.TANH))
        model.add(Dropout(ve.DROPOUT_PROB))
        model.add(Dense(input_dim=ve.HIDDEN_SIZE, output_dim=ve.NER_CLASSES))
        model.add(Activation(ve.SOFTMAX))
        ve.compile_other_model(model, self.hp.optimizer)

        return model
Exemple #3
0
  def build_model(self):
    premise = Sequential()
    premise.add(Embedding(input_dim=len(self.ds.vocab),
                        output_dim=ve.EMBEDDING_SIZE,
                        weights=[self.ds.weights],
                        input_length=ve.NLI_MAX_LEN,
                        W_regularizer=l2(self.hp.embedding_l2)))
    premise.add(LSTM(output_dim=ve.HIDDEN_SIZE))
    premise.add(Dropout(ve.DROPOUT_PROB))

    hypothesis = Sequential()
    hypothesis.add(Embedding(input_dim=len(self.ds.vocab),
                        output_dim=ve.EMBEDDING_SIZE,
                        weights=[self.ds.weights],
                        input_length=ve.NLI_MAX_LEN,
                        W_regularizer=l2(self.hp.embedding_l2)))
    hypothesis.add(LSTM(input_shape=self.ds.X_h_train.shape[1:],
                        output_dim=ve.HIDDEN_SIZE))
    hypothesis.add(Dropout(ve.DROPOUT_PROB))

    model = Sequential()
    model.add(Merge([premise, hypothesis],mode=ve.CONCAT))
    model.add(Dense(output_dim=ve.HIDDEN_SIZE,activation=ve.TANH, 
              W_regularizer=l2(self.hp.dense_l2)))
    model.add(Dense(output_dim=ve.NLI_CLASSES,activation=ve.SOFTMAX,
              W_regularizer=l2(self.hp.dense_l2)))

    ve.compile_other_model(model, self.hp.optimizer)

    return model
Exemple #4
0
 def build_model(self):
   model = Sequential()
   model.add(Dense(input_shape=self.ds.X_train.shape[1:],
                   output_dim=ve.HIDDEN_SIZE,
                   W_regularizer=l2(self.hp.dense_l2)))
   model.add(Activation(ve.TANH))
   model.add(Dropout(ve.DROPOUT_PROB))
   model.add(Dense(input_dim=ve.HIDDEN_SIZE,
                   output_dim=ve.POS_CLASSES,
                   W_regularizer=l2(self.hp.dense_l2)))
   model.add(Activation(ve.SOFTMAX))
   ve.compile_other_model(model, self.hp.optimizer)
   return model
Exemple #5
0
 def build_model(self):
   model = Sequential()
   model.add(Embedding(input_dim=len(self.ds.vocab),
                       output_dim=ve.EMBEDDING_SIZE,
                       weights=[self.ds.weights],
                       input_length=ve.WINDOW_SIZE))
   model.add(Reshape((ve.EMBEDDING_SIZE * ve.WINDOW_SIZE,)))
   model.add(Dense(output_dim=ve.HIDDEN_SIZE))
   model.add(Activation(ve.TANH))
   model.add(Dropout(ve.DROPOUT_PROB))
   model.add(Dense(input_dim=ve.HIDDEN_SIZE, output_dim=ve.CHUNK_CLASSES))
   model.add(Activation(ve.SOFTMAX))
   ve.compile_other_model(model, self.hp.optimizer)
   return model
    def build_model(self):
        model = Sequential()
        model.add(
            Embedding(input_dim=len(self.ds.vocab),
                      output_dim=ve.EMBEDDING_SIZE,
                      weights=[self.ds.weights],
                      input_length=ve.QUESTIONS_MAX_LEN,
                      W_regularizer=l2(self.hp.embedding_l2)))
        model.add(LSTM(output_dim=ve.HIDDEN_SIZE))
        model.add(Dropout(ve.DROPOUT_PROB))
        model.add(
            Dense(input_dim=ve.HIDDEN_SIZE,
                  output_dim=ve.QUESTIONS_CLASSES,
                  W_regularizer=l2(self.hp.dense_l2)))
        model.add(Activation(ve.SOFTMAX))
        ve.compile_other_model(model, self.hp.optimizer)

        return model