Exemplo n.º 1
0
    def __init__(self, input_dim1, input_dim2, output_dim, hidden_dim1, hidden_dim2, dep=2, loss="nl", optimizer="ada", we_dict1=None, we_dict2=None, map1=None, map2=None, use_noise=True):
        Sequential.__init__(self, use_mask=True, input_value_type="int32", prediction_type="vector",
                            prediction_value_type='int32', use_noise=use_noise)

        self.extra_input = tensor.matrix('x_extra', dtype="int32")
        self.extra_output = None


        self.option[Option.LOSS] = loss
        self.option[Option.OPTIMIZER] = optimizer
        l1 = Embedding(input_dim1, hidden_dim1, we_dict=we_dict1, map=map1)

        l2 = Embedding(input_dim2, hidden_dim2, we_dict=we_dict2, map=map2)


        l3 = Merge(layers=[l1,l2])

        self.add_layer([l1,l2,l3])

        l4 = Dropout(hidden_dim1+hidden_dim2,theano_rng= RandomStreams(128))
        self.add_layer(l4)

        for i in range(dep):
            l5 = LSTM(hidden_dim1+hidden_dim2, hidden_dim1+hidden_dim2, return_sequences=True)
            self.add_layer(l5)

        l6 = Dropout(hidden_dim1+hidden_dim2,theano_rng= RandomStreams(128))
        self.add_layer(l6)

        l7 = TimeDitributed(core_layer=Dense(hidden_dim1+hidden_dim2, output_dim, activation="softmax"))


        self.add_layer([l7])

        self.option[Option.IS_SEQUENCE_WORK] = True
Exemplo n.º 2
0
    def __init__(self,
                 input_dim,
                 output_dim,
                 hidden_dim,
                 dep=2,
                 loss="nl",
                 optimizer="ada",
                 we_dict=None,
                 map=None,
                 use_noise=True):
        '''

        :param input_dim:
        :param output_dim:
        :param hidden_dim:
        :param dep:
        :param loss:
        :param optimizer:
        :param we_dict: word embedding dictionary
        :param map: mapping from word to index
        :return:
        '''
        Sequential.__init__(self,
                            use_mask=True,
                            input_value_type="int32",
                            prediction_type="vector",
                            prediction_value_type='int32',
                            use_noise=use_noise)

        self.option[Option.LOSS] = loss
        self.option[Option.OPTIMIZER] = optimizer
        l1 = Embedding(input_dim, hidden_dim, we_dict=we_dict,
                       map=map)  # first layer is an embedding layer
        self.add_layer(l1)

        l2 = Dropout(hidden_dim, theano_rng=RandomStreams(128))
        self.add_layer(l2)
        for i in range(dep):
            l3 = LSTM(hidden_dim, hidden_dim, return_sequences=True)
            self.add_layer(l3)

        l4 = Dropout(hidden_dim, theano_rng=RandomStreams(128))
        self.add_layer(l4)
        l5 = TimeDitributed(
            core_layer=Dense(hidden_dim, output_dim, activation="softmax"))

        self.add_layer(l5)
        self.option[Option.IS_SEQUENCE_WORK] = True
Exemplo n.º 3
0
 def __init__(self,
              input_dim,
              output_dim,
              hidden_dim,
              loss="nl",
              optimizer="ada"):
     Sequential.__init__(self,
                         use_mask=True,
                         input_value_type="int64",
                         hidden_dim=hidden_dim,
                         loss=loss,
                         optimizer=optimizer)
     l1 = Embedding(input_dim, hidden_dim)
     l2 = LSTM(hidden_dim, hidden_dim, return_sequences=True)
     l3 = MeanPooling()
     l4 = Dropout(hidden_dim, theano_rng=RandomStreams(128))
     l5 = Dense(hidden_dim, output_dim, activation="softmax")
     self.add_layer([l1, l2, l3, l4, l5])
     self.compile()
Exemplo n.º 4
0
    def __init__(self,
                 input_dim1,
                 input_dim2,
                 output_dim1,
                 output_dim2,
                 hidden_dim1,
                 hidden_dim2,
                 semantic_label_map,
                 dep=2,
                 loss="nl",
                 optimizer="ada",
                 we_dict1=None,
                 we_dict2=None,
                 map1=None,
                 map2=None,
                 use_noise=True):
        Sequential.__init__(self,
                            use_mask=True,
                            input_value_type="int32",
                            prediction_type="vector",
                            prediction_value_type='int32',
                            use_noise=use_noise)

        self.extra_input = tensor.matrix('x_extra', dtype="int32")
        self.extra_output = None
        self.extra_prediction = tensor.ivector('ye')
        self.extra_gold = tensor.ivector('ge')

        self.option[Option.LOSS] = loss
        self.option[Option.OPTIMIZER] = optimizer
        l1 = Embedding(input_dim1, hidden_dim1, we_dict=we_dict1, map=map1)

        l2 = Embedding(input_dim2, hidden_dim2, we_dict=we_dict2, map=map2)

        self.add_layer([l1, l2])

        l11 = Dropout(hidden_dim1, theano_rng=RandomStreams(128))
        self.add_layer(l11)

        l21 = Dropout(hidden_dim2, theano_rng=RandomStreams(128))
        self.add_layer(l21)

        l4 = LSTM(hidden_dim1, hidden_dim1, return_sequences=True)

        l5 = LSTM(hidden_dim2, hidden_dim2, return_sequences=True)

        self.add_layer([l4, l5])
        l22 = Dropout(hidden_dim2, theano_rng=RandomStreams(128))
        self.add_layer(l22)
        l6 = TimeDitributed(
            core_layer=Dense(hidden_dim2, output_dim2, activation="softmax"))

        l12 = Dropout(hidden_dim1, theano_rng=RandomStreams(128))
        self.add_layer(l12)

        l7 = SoftmaxHybrid(hidden_dim1, hidden_dim2, output_dim1,
                           semantic_label_map)

        l8 = TimeDitributedHybrid(core_layer=l7)
        self.add_layer([l6, l8])

        self.option[Option.IS_SEQUENCE_WORK] = True