Exemple #1
0
    def build_model_arc(self):
        """
        build model architectural
        """
        output_dim = len(self.pre_processor.label2idx)
        config = self.hyper_parameters
        embed_model = self.embedding.embed_model

        layer_conv = L.Conv1D(**config['layer_conv'], name='layer_conv')
        layer_blstm = L.Bidirectional(L.CuDNNLSTM(**config['layer_blstm']),
                                      name='layer_blstm')

        layer_dense = L.Dense(**config['layer_dense'], name='layer_dense')
        layer_crf_dense1 = L.Dense(output_dim, name='layer_crf_dense')
        layer_crf1 = CRF(output_dim, name='layer_crf1')  #全局定制类

        layer_crf_dense2 = L.Dense(output_dim, name='layer_crf_dense2')
        layer_crf2 = CRF(output_dim, name='layer_crf2')

        tensor = layer_conv(embed_model.output)
        tensor1 = layer_crf_dense1(tensor)
        output_tensor1 = layer_crf1(tensor1)
        tensor = layer_blstm(tensor)
        tensor = layer_dense(tensor)
        tensor2 = layer_crf_dense2(tensor)
        output_tensor2 = layer_crf2(tensor2)

        self.layer_crf1 = layer_crf1
        self.layer_crf2 = layer_crf2
        self.tf_model = keras.Model(inputs=embed_model.inputs,
                                    outputs=[output_tensor2, output_tensor1])
Exemple #2
0
    def build_model_arc(self):
        """
        build model architectural
        """
        output_dim = len(self.processor.label2idx)
        config = self.hyper_parameters
        embed_model = self.embedding.embed_model

        layer_blstm = L.Bidirectional(L.LSTM(**config['layer_blstm']),
                                      name='layer_blstm')

        layer_dense = L.Dense(**config['layer_dense'], name='layer_dense')
        layer_crf_dense = L.Dense(output_dim, name='layer_crf_dense')
        layer_crf = CRF(output_dim, name='layer_crf')
        layer_dropout = L.Dropout(**config['layer_dropout'],
                                  name='layer_dropout')
       


        tensor = layer_blstm(embed_model.output)
        tensor = layer_dense(tensor)
        tensor = layer_dropout(tensor)
        tensor = layer_crf_dense(tensor)
        output_tensor = layer_crf(tensor)

        self.layer_crf = layer_crf
        self.tf_model = keras.Model(embed_model.inputs, output_tensor)
Exemple #3
0
    def build_model_arc(self):
        """
        build model architectural
        """
        output_dim = len(self.pre_processor.label2idx)
        config = self.hyper_parameters
        embed_model = self.embedding.embed_model

        # layer_blstm = L.Bidirectional(L.LSTM(**config['layer_blstm']),
        #                               name='layer_blstm')
        layer_conv = L.Conv1D(**config['layer_conv'], name='layer_conv')
        layer_blstm = L.Bidirectional(L.CuDNNLSTM(**config['layer_blstm']),
                                      name='layer_blstm')
        layer_dense = L.Dense(**config['layer_dense'], name='layer_dense')
        layer_attention = Attention(name='layer_attention')
        layer_Activation = L.Activation("tanh", name="layer_Activation")

        layer_crf_dense = L.Dense(output_dim, name='layer_crf_dense')
        layer_crf = CRF(output_dim, name='layer_crf')  #全局定制类

        tensor = layer_conv(embed_model.output)
        tensor = layer_blstm(tensor)
        tensor = layer_dense(tensor)
        tensor = layer_attention(tensor)
        tensor = layer_Activation(tensor)
        tensor = layer_crf_dense(tensor)
        output_tensor = layer_crf(tensor)

        self.layer_crf = layer_crf
        self.tf_model = keras.Model(embed_model.inputs, output_tensor)
Exemple #4
0
    def build_model_arc(self):
        """
        build model architectural
        """
        output_dim = len(self.pre_processor.label2idx)
        config = self.hyper_parameters
        embed_model = self.embedding.embed_model

        layer_bert = bert_attention(name='layer_bert')
        layer_position = Position_attention_layer(name='layer_position')
        layer_blstm = L.Bidirectional(L.CuDNNLSTM(**config['layer_blstm']),
                                      name='layer_blstm')
        layer_LSTMDecoder = LSTMDecoder(**config['layer_LSTMDecoder'],
                                        name='layer_LSTMDecoder')
        layer_attention = Attention(name='layer_attention')
        layer_Activation = L.Activation("tanh", name="layer_Activation")
        layer_dense1 = L.Dense(**config['layer_dense1'], name='layer_dense1')
        layer_dense2 = L.Dense(**config['layer_dense2'], name='layer_dense2')

        layer_crf_dense = L.Dense(output_dim, name='layer_crf_dense')
        layer_crf = CRF(output_dim, name='layer_crf')  #全局定制类

        tensor = layer_bert(embed_model.output)
        tensor = layer_position(tensor)
        tensor = layer_blstm(tensor)
        tensor = layer_LSTMDecoder(tensor)
        tensor = layer_attention(tensor)
        tensor = layer_Activation(tensor)
        tensor = layer_dense1(tensor)
        tensor = layer_dense2(tensor)
        tensor = layer_crf_dense(tensor)
        output_tensor = layer_crf(tensor)

        self.layer_crf = layer_crf
        self.tf_model = keras.Model(embed_model.inputs, output_tensor)
Exemple #5
0
    def build_model_arc(self):
        """
        build model architectural
        """
        output_dim = len(self.pre_processor.label2idx)
        config = self.hyper_parameters
        embed_model = self.embedding.embed_model

        layer_blstm = L.Bidirectional(L.LSTM(**config['layer_blstm']),
                                      name='layer_blstm')

        layer_dense = L.Dense(**config['layer_dense'], name='layer_dense')
        layer_crf_dense = L.Dense(output_dim, name='layer_crf_dense')
        layer_crf = CRF(output_dim, name='layer_crf')

        if isinstance(embed_model, keras.Model):
            first_layer_output = embed_model.output
            first_layer_input = embed_model.inputs
        else:
            first_layer_output = embed_model
            first_layer_input = embed_model

        tensor = layer_blstm(first_layer_output)
        tensor = layer_dense(tensor)
        tensor = layer_crf_dense(tensor)
        output_tensor = layer_crf(tensor)

        self.layer_crf = layer_crf
        self.tf_model = keras.Model(first_layer_input, output_tensor)
Exemple #6
0
    def build_model_arc(self):
        """
        build model architectural
        """
        output_dim = len(self.pre_processor.label2idx)
        config = self.hyper_parameters
        embed_model = self.embedding.embed_model

        # layer_blstm = L.Bidirectional(L.LSTM(**config['layer_blstm']),
        #                               name='layer_blstm')
        layer_conv2 = L.Conv1D(**config['layer_conv2'],
                               name='layer_conv2',
                               kernel_regularizer=regularizers.l2(0.01))
        layer_conv3 = L.Conv1D(**config['layer_conv3'],
                               name='layer_conv3',
                               kernel_regularizer=regularizers.l2(0.02))
        layer_conv4 = L.Conv1D(**config['layer_conv4'],
                               name='layer_conv4',
                               kernel_regularizer=regularizers.l2(0.03))
        layer_conv5 = L.Conv1D(**config['layer_conv5'],
                               name='layer_conv5',
                               kernel_regularizer=regularizers.l2(0.04))
        layer_conv6 = L.Conv1D(**config['layer_conv6'],
                               name='layer_conv6',
                               kernel_regularizer=regularizers.l2(0.05))
        layer_conv7 = L.Conv1D(**config['layer_conv7'],
                               name='layer_conv7',
                               kernel_regularizer=regularizers.l2(0.06))
        layer_conv8 = L.Conv1D(**config['layer_conv8'],
                               name='layer_conv8',
                               kernel_regularizer=regularizers.l2(0.07))
        layer_conv9 = L.Conv1D(**config['layer_conv9'],
                               name='layer_conv9',
                               kernel_regularizer=regularizers.l2(0.08))
        layer_conv10 = L.Conv1D(**config['layer_conv10'],
                                name='layer_conv10',
                                kernel_regularizer=regularizers.l2(0.09))

        layer_blstm = L.Bidirectional(L.CuDNNLSTM(**config['layer_blstm']),
                                      name='layer_blstm')
        layer_dense = L.Dense(**config['layer_dense'], name='layer_dense')
        layer_crf_dense = L.Dense(output_dim, name='layer_crf_dense')
        layer_crf = CRF(output_dim, name='layer_crf')  #全局定制类
        tensor2 = layer_conv2(embed_model.output)
        tensor3 = layer_conv3(embed_model.output)
        tensor4 = layer_conv4(embed_model.output)
        tensor5 = layer_conv5(embed_model.output)
        tensor6 = layer_conv6(embed_model.output)
        tensor7 = layer_conv7(embed_model.output)
        tensor8 = layer_conv8(embed_model.output)
        tensor9 = layer_conv9(embed_model.output)
        tensor10 = layer_conv10(embed_model.output)
        tensor = keras.layers.concatenate([
            tensor2, tensor3, tensor4, tensor5, tensor6, tensor7, tensor8,
            tensor9, tensor10
        ], 2)
        tensor = layer_blstm(tensor)
        tensor = layer_dense(tensor)
        tensor = layer_crf_dense(tensor)
        output_tensor = layer_crf(tensor)

        self.layer_crf = layer_crf
        self.tf_model = keras.Model(embed_model.inputs, output_tensor)