Ejemplo n.º 1
0
    def __setstate__(self, state):

        self.layers = []
        for idx, param in enumerate(state["layer_params"]):
            layer = create_layer(param)
            self.layers.append(layer)

        self.cost = create_cost(state["cost"])
Ejemplo n.º 2
0
    def __init__(self, layer_params, cost_param):

        self.layers = []

        for idx, param in enumerate(layer_params):
            layer = create_layer(param)
            self.layers.append(layer)

            if idx > 0:
                assert layer.input_dim() == self.layers[idx-1].output_dim(), \
                    "The layer chain is broken at %d-th layer"%idx

        self.cost = create_cost(cost_param)

        X = theano.tensor.matrix("X")


        layer_out = X
        for layer in self.layers:
            layer_out = layer.output(layer_out)

        self.__predict_func = theano.function([X],
                                              outputs=layer_out)
Ejemplo n.º 3
0
    def __init__(self, problem_character = None,
                 nn_architecture = None, trans_mat_prior = None):
        # x shape: [mini-batch size, feature-dim].
        # In this problem [mini-batch feature-dim]

        if ( problem_character is None or nn_architecture is None):

            raise Exception("both problem and architecture must be provided")

        word_num = problem_character['word_num']
        POS_type_num = problem_character['POS_type_num']

        dist_to_verb_num = problem_character['dist_to_verb_num']
        dist_to_word_num = problem_character['dist_to_word_num']

        # 1,word vector
        #   output shape: (batch size,sentence_len, word_feature_num)
        self.word_embedding_layer = LookupTableLayer(
            table_size = word_num,
            feature_num = nn_architecture.word_feature_dim
        )

        # 3,word POS tag vector
        #   output shape: (batch size,sentence_len, POS_feature_num)
        self.pos_embedding_layer = LookupTableLayer(
            table_size = POS_type_num,
            feature_num = nn_architecture.pos_feature_dim,
        )

#            self.loc_embedding_layer = LookupTableLayer(
#                table_size = loc_type_num,
#                feature_num = nn_architecture.dist_feature_dim,
#            )


        # 5,distance tag vector
        #   output shape: (batch size,sentence_len, POS_feature_num)
        self.locdiff_word_embedding_layer = LookupTableLayer(
            table_size = dist_to_word_num,
            feature_num = nn_architecture.dist_feature_dim,
        )

        self.locdiff_verb_embedding_layer = LookupTableLayer(
            table_size = dist_to_verb_num,
            feature_num = nn_architecture.dist_feature_dim,
        )

        conv_input_dim = nn_architecture.word_feature_dim * 3 + \
            nn_architecture.pos_feature_dim * 3 + \
            nn_architecture.dist_feature_dim * 4



        conv_shape = (nn_architecture.conv_output_dim,
                           1,
                           nn_architecture.conv_window_height,
                           conv_input_dim)
        self.conv_layer = Conv1DMaxPoolLayer(
            activator_type="sigmoid",
            tensor_shape = conv_shape)


        self.embedding_conv_layers = [self.word_embedding_layer,
            self.pos_embedding_layer,
            self.locdiff_word_embedding_layer,
            self.locdiff_verb_embedding_layer,
            self.conv_layer]

        input_dim = nn_architecture.conv_output_dim
        self.perception_layers = []
        for idx, output_dim in enumerate(nn_architecture.hidden_layer_output_dims):

            hidden_layer = PerceptionLayer(
                input_dim = input_dim,
                output_dim = output_dim,
                activator_type = "sigmoid")

            self.perception_layers.append(hidden_layer)
            input_dim = output_dim

        out_layer = PerceptionLayer(
                input_dim = input_dim,
                output_dim = problem_character["SRL_type_num"],
                activator_type = "softmax")
        self.perception_layers.append(out_layer)

        self.cost = create_cost({"type": "cross_entropy"})

            # self.output_layer = PathTransitionLayer('output',
            #                             class_num=SRL_type_num,
            #                             trans_mat_prior= trans_mat_prior)
#            self.output_layer = SoftMaxLayer(n_in= nn_architecture.hidden_layer_output_dims[-1],
#                    n_out = SRL_type_num,)

        X = theano.tensor.matrix("X")

        self.__output_func = theano.function([X],
                                              outputs = self.__output(X))
        self.__predict_expr = theano.tensor.argmax(self.__output(X), axis = 1)
        self.__predict_func = theano.function([X],
                                              outputs = self.__predict_expr)