Giter Site home page Giter Site logo

onurgu / neural-turkish-morphological-disambiguator Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 4.0 14.15 MB

Implementation of Shen et al.'s "The Role of Context in Neural Morphological Disambiguation"

Python 90.39% CSS 0.17% HTML 2.61% JavaScript 5.83% Shell 1.00%

neural-turkish-morphological-disambiguator's People

Contributors

onurgu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neural-turkish-morphological-disambiguator's Issues

Ran Out of Input

Hi,

After i am done with train, i was trying to predict the model. But unfortunately i got this error: 'Ran Out of Input'.

File "train.py", line 276, in
label2ids, params, train_and_test_sentences = load_label2ids_and
_params(args)
File "train.py", line 87, in load_label2ids_and_params
label2ids = cPickle.load(f)
EOFError: Ran out of input

Here is my train.py:

import argparse
import pickle as cPickle
import codecs
import os
import sys
import tempfile
from collections import defaultdict as dd
import numpy as np
from loader import encode_sentence, read_datafile
from model import build_model, Params
from utils import get_morph_analyzes, create_single_word_single_line_format


def create_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument("--command", default="train", required=True,
                        choices=["train", "predict", "disambiguate"])
    parser.add_argument("--train_filepath", required=True)
    parser.add_argument("--test_filepath", required=True)
    parser.add_argument("--run_name", required=True)
    parser.add_argument("--model_path")
    parser.add_argument("--label2ids_path")

    return parser


def sample_generator(sentences, label2ids, batch_size=32, return_sentence=False):
    while True:
        n_in_batch = 0
        batch = [[], []]
        decoded_sentences_in_batch = []
        shuffled_indices = np.random.permutation(len(sentences))
        for sentence_i in shuffled_indices:
            sentence = sentences[sentence_i]
            sentences_word_root_input, sentences_analysis_input, surface_form_input, correct_tags_input, shuffled_positions_record = \
                encode_sentence(sentence, label2ids)

            if return_sentence:
                decoded_sentences_in_batch.append([sentence, shuffled_positions_record])

            input_array = []
            for array in [sentences_word_root_input, sentences_analysis_input, surface_form_input,
                          correct_tags_input]:
                # print array.shape
                # print array.reshape([-1] + list(array.shape)).shape
                input_array += [np.expand_dims(np.copy(array), axis=0)]
                # print array.shape
                # print np.expand_dims(array, axis=0).shape

            batch[0].append(input_array[:-1])
            batch[1].append([input_array[-1]])
            n_in_batch += 1
            if n_in_batch == batch_size:
                # yield np.concatenate(batch[0], axis=0), np.concatenate(batch[1], axis=0)
                # for b in batch[1]:
                #     for i in range(1):
                #         print i
                #         print b[i].shape
                encoded_sentences_in_batch = ([np.concatenate([b[i] for b in batch[0]], axis=0) for i in range(3)], \
                          [np.concatenate([b[0] for b in batch[1]], axis=0)])
                if not return_sentence:
                    yield encoded_sentences_in_batch
                else:
                    yield encoded_sentences_in_batch, decoded_sentences_in_batch
                # yield batch[0], batch[1]
                n_in_batch = 0
                batch = [[], []]
                decoded_sentences_in_batch = []

        if n_in_batch > 0:
            encoded_sentences_in_batch = ([np.concatenate([b[i] for b in batch[0]], axis=0) for i in
                   range(3)],
                  [np.concatenate([b[0] for b in batch[1]], axis=0)])
            if not return_sentence:
                yield encoded_sentences_in_batch
            else:
                yield encoded_sentences_in_batch, decoded_sentences_in_batch


def load_label2ids_and_params(args):
    if args.label2ids_path:
        with open(args.label2ids_path, "rb") as f:
            label2ids = cPickle.load(f)
    else:
        if os.path.exists(args.model_path + ".label2ids"):
            with open(args.model_path + ".label2ids", "rb") as f:
                label2ids = cPickle.load(f)
        else:
            train_and_test_sentences, label2ids = read_datafile(args.train_filepath,
                                                                args.test_filepath)
            with open(args.model_path + ".label2ids", "wb") as f:
                cPickle.dump(label2ids, f)
            params = create_params(label2ids)
            return label2ids, params, train_and_test_sentences
    params = create_params(label2ids)

    return label2ids, params, []


def create_params(label2ids):
    params = Params()
    params.max_sentence_length = label2ids['max_sentence_length']
    params.max_n_analyses = label2ids['max_n_analysis']
    params.batch_size = 1
    params.n_subepochs = 40
    params.max_surface_form_length = label2ids['max_surface_form_length']
    params.max_word_root_length = label2ids['max_word_root_length']
    params.max_analysis_length = label2ids['max_analysis_length']
    params.char_vocabulary_size = label2ids['character_unique_count']['value']
    params.tag_vocabulary_size = label2ids['morph_token_unique_count']['value']
    params.char_lstm_dim = 100
    params.char_embedding_dim = 100
    params.tag_lstm_dim = params.char_lstm_dim
    params.tag_embedding_dim = 100
    params.sentence_level_lstm_dim = 2 * params.char_lstm_dim
    return params


def disambiguate_single_line_sentence(line, model, label2ids, params, print_prediction_lines=True):
    """
    
    :param line: 
    :param model: 
    :param label2ids: 
    :param params: 
    :param print_prediction_lines: 
    :return: An array of strings which represent the words and disambiguated analyzes
    """
    string_output = get_morph_analyzes(line)# print "XXX", string_output, "YYY"
    analyzer_output_string = create_single_word_single_line_format(string_output)
    # print string_output_single_line.decode("iso-8859-9")
    # print type(string_output_single_line)
    fd, f_path = tempfile.mkstemp()
    with codecs.open(f_path, "w", encoding="utf8") as f:
        f.write(analyzer_output_string.decode("iso-8859-9"))
    os.close(fd)
    # print f_path
    train_and_test_sentences, _ = read_datafile(f_path, f_path, preloaded_label2ids=label2ids)
    # print train_and_test_sentences[1]
    sample_batch, decoded_sample_batch = iter(sample_generator(train_and_test_sentences[1],
                             label2ids,
                             batch_size=params.batch_size,
                             return_sentence=True)).next()
    # for batch_idx, (sample_batch, decoded_sample_batch) in enumerate(sample_generator(train_and_test_sentences[1],
    #                          label2ids,
    #                          batch_size=params.batch_size,
    #                          return_sentence=True)
    #         ):
    pred_probs = model.predict(sample_batch[0], batch_size=params.batch_size, verbose=1)

    pred_tags = np.argmax(pred_probs[0], axis=1)
    # print pred_tags

    first_sentence = decoded_sample_batch[0][0]
    first_shuffled_positions = decoded_sample_batch[0][1]

    sentence_length = len(first_sentence['roots'])
    # print sentence_length

    pred_probs_copy = np.copy(pred_probs)

    for row_idx, first_shuffled_positions_row in enumerate(first_shuffled_positions):
        # print pred_probs_copy[0, row_idx]
        # print first_shuffled_positions_row
        for col_idx, first_shuffled_position in enumerate(first_shuffled_positions_row):
            pred_probs_copy[0, row_idx, first_shuffled_position] = pred_probs[
                0, row_idx, col_idx]
            # print pred_probs_copy[0, row_idx]

    pred_tags = np.argmax(pred_probs_copy[0], axis=1)
    # print pred_tags
    prediction_lines = [
        first_sentence['surface_forms'][word_idx] + " " + first_sentence['roots'][word_idx][
            pred_tag] + "+" + "+".join(first_sentence['morph_tokens'][word_idx][pred_tag]) for
        word_idx, pred_tag in enumerate(pred_tags[:sentence_length])]

    prediction_lines_raw = [
        [first_sentence['surface_forms'][word_idx], first_sentence['roots'][word_idx][
            pred_tag] + "+" + "+".join(first_sentence['morph_tokens'][word_idx][pred_tag])] for
        word_idx, pred_tag in enumerate(pred_tags[:sentence_length])]

    if print_prediction_lines:
        print("\n".join(prediction_lines))
        print("")
        return prediction_lines
    else:
        print([type(x) for x in prediction_lines])
        return analyzer_output_string, prediction_lines, prediction_lines_raw


def create_model_for_disambiguation(args):
    from model import build_model
    label2ids, params, _ = load_label2ids_and_params(args)
    model = build_model(params)
    assert args.model_path, "--model_path should be given in the arguments for 'predict'"
    model.load_weights(args.model_path)
    return label2ids, params, model

if __name__ == "__main__":

    parser = create_parser()

    args = parser.parse_args()

    if args.command == "train":

        train_and_test_sentences, label2ids = read_datafile(args.train_filepath, args.test_filepath)

        params = Params()

        params.max_sentence_length = label2ids['max_sentence_length']
        params.max_n_analyses = label2ids['max_n_analysis']

        params.batch_size = 1
        params.n_subepochs = 40

        params.max_surface_form_length = label2ids['max_surface_form_length']
        params.max_word_root_length = label2ids['max_word_root_length']
        params.max_analysis_length = label2ids['max_analysis_length']

        params.char_vocabulary_size = label2ids['character_unique_count']['value']
        params.tag_vocabulary_size = label2ids['morph_token_unique_count']['value']

        params.char_lstm_dim = 100
        params.char_embedding_dim = 100

        params.tag_lstm_dim = params.char_lstm_dim
        params.tag_embedding_dim = 100

        params.sentence_level_lstm_dim = 2 * params.char_lstm_dim

        # train_and_test_sentences, label2ids = read_datafile("test.merge.utf8", "test.merge.utf8")

        model = build_model(params)

        model.compile(optimizer='rmsprop',
                      loss='categorical_crossentropy',
                      metrics=['accuracy'])

        from keras.callbacks import ModelCheckpoint, TensorBoard, ReduceLROnPlateau

        checkpointer = ModelCheckpoint(filepath="./models/ntd-{run_name}".format(run_name=args.run_name)
                                                + '.epoch-{epoch:02d}-val_acc-{val_acc:.5f}.hdf5',
                                       verbose=1,
                                       monitor="val_acc",
                                       save_best_only=True)
        tensorboard_callback = TensorBoard(log_dir=os.path.join('.\logs', args.run_name),
                    histogram_freq=1,
                    write_graph=True,
                    write_images=True,
                    embeddings_freq=1,
                    embeddings_layer_names=None,
                    embeddings_metadata={'char_embedding_layer': 'char_embedding_layer.tsv',
                                         'tag_embedding_layer': 'tag_embedding_layer.tsv'})
        reduce_lr = ReduceLROnPlateau(monitor='val_loss',
                                      factor=0.1,
                                      patience=10,
                                      verbose=0,
                                      mode='auto',
                                      epsilon=0.0001,
                                      cooldown=1,
                                      min_lr=0)
        model.fit_generator(sample_generator(train_and_test_sentences[0], label2ids, batch_size=params.batch_size),
                            steps_per_epoch=10, #len(train_and_test_sentences[0])/params.batch_size/params.n_subepochs,
                            epochs=10, #10*params.n_subepochs,
                            validation_data=sample_generator(train_and_test_sentences[1], label2ids, batch_size=params.batch_size),
                            validation_steps=len(train_and_test_sentences[1])/params.batch_size+1,
                            callbacks=[checkpointer, tensorboard_callback, reduce_lr])

        print("Saving")
        model.save("./models/ntd-{run_name}-final.hdf5".format(run_name=args.run_name))
        # model.evaluate()

    elif args.command == "predict":

        label2ids, params, train_and_test_sentences = load_label2ids_and_params(args)

        train_and_test_sentences, label2ids_from_input_file = read_datafile(args.train_filepath, args.test_filepath)

        from model import build_model

        model = build_model(params)

        assert args.model_path, "--model_path should be given in the arguments for 'predict'"

        model.load_weights(args.model_path)

        total_correct = 0
        total_tokens = 0

        total_correct_all_structure = 0
        total_tokens_all_structure = 0

        total_correct_ambigious = 0
        total_tokens_ambigious = 0

        correct_counts = dd(int)
        total_counts = dd(int)


        for batch_idx, (sample_batch, decoded_sample_batch) in enumerate(sample_generator(train_and_test_sentences[1],
                                                                   label2ids,
                                                                   batch_size=params.batch_size,
                                                                   return_sentence=True)):
            # print sample
            # pred_probs = model.predict(sample_batch[0], batch_size=params.batch_size, verbose=1)
            # print pred_probs
            # print pred_probs.shape
            # print np.argmax(pred_probs, axis=2)
            # print sample_batch[1][0]
            # print sample_batch[1][0].shape
            # print np.argmax(sample_batch[1][0], axis=2)
            # print decoded_sample_batch

            # print "decoded_sample_batch: ", decoded_sample_batch

            correct_tags = np.argmax(sample_batch[1][0], axis=2)
            pred_probs = model.predict(sample_batch[0], batch_size=params.batch_size, verbose=1)
            pred_tags = np.argmax(pred_probs, axis=2)

            for idx, correct_tag in enumerate(correct_tags):

                sentence_length = len(decoded_sample_batch[idx][0]['surface_form_lengths'])
                pred_tag = pred_tags[idx]
                # print correct_tag
                # print correct_tag.shape
                # print pred_tag
                # print pred_tag.shape
                n_correct = np.sum(correct_tag[:sentence_length] == pred_tag[:sentence_length])
                total_correct += n_correct
                total_tokens += sentence_length
                # print "sentence_length: ", sentence_length

                # print "n_correct: ", n_correct
                # print "sentence_length: ", sentence_length

                total_correct_all_structure += n_correct + correct_tag.shape[0] - sentence_length
                total_tokens_all_structure += correct_tag.shape[0]

                baseline_log_prob = 0
                import math

                for j in range(len(decoded_sample_batch[idx][0]['roots'])):
                    if j >= sentence_length:
                        break
                    n_analyses = len(decoded_sample_batch[idx][0]['roots'][j])
                    baseline_log_prob += math.log(1/float(n_analyses))
                    # print n_analyses
                    assert n_analyses >= 1
                    if n_analyses > 1:
                        if correct_tag[j] == pred_tag[j]:
                            total_correct_ambigious += 1
                            correct_counts[n_analyses] += 1
                        total_tokens_ambigious += 1
                        total_counts[n_analyses] += 1


            if batch_idx % 100 == 0:
                print("only the filled part of the sentence")
                print(total_correct)
                print(total_tokens)
                print(float(total_correct) / total_tokens)
                print("all the sentence")
                print(total_correct_all_structure)
                print(total_tokens_all_structure)
                print(float(total_correct_all_structure) / total_tokens_all_structure)
                print("===")
                print("ambigous")
                print(total_correct_ambigious)
                print(total_tokens_ambigious)
                print(float(total_correct_ambigious) / total_tokens_ambigious)
                print("===")
                for key in correct_counts:
                    print("disambiguations out of n_analyses: %d ===> %lf" % (
                    key, float(correct_counts[key]) / total_counts[key]))
                print("===")
            if batch_idx*params.batch_size >= len(train_and_test_sentences[1]):
                print("Evaluation finished, batch_id: %d" % batch_idx)
                print("only the filled part of the sentence")
                print(total_correct)
                print(total_tokens)
                print(float(total_correct) / total_tokens)
                print("all the sentence")
                print(total_correct_all_structure)
                print(total_tokens_all_structure)
                print(float(total_correct_all_structure) / total_tokens_all_structure)
                print("===")
                print("ambigous")
                print(total_correct_ambigious)
                print(total_tokens_ambigious)
                print(float(total_correct_ambigious) / total_tokens_ambigious)
                print("===")
                for key in correct_counts:
                    print("disambiguations out of n_analyses: %d ===> %lf %d %d" % (
                    key, float(correct_counts[key]) / total_counts[key], correct_counts[key], total_counts[key]))
                print("===")
                break
    elif args.command == "disambiguate":

        label2ids, params, model = create_model_for_disambiguation(args)

        line = sys.stdin.readline()
        while line:
            line = line.strip("\n")
            disambiguate_single_line_sentence(line, model, label2ids, params)

            line = sys.stdin.readline()

Disambiguating Command is not Compelete

Hi, i have 2 quesitons.

I was trying all commands in order of them. I've run Disambiguating command. Process didnt complete even if i waited a lot for it. And there was no error or something like this. Is it normal? What should i do?

The comman i've run:

python train.py --command disambiguate --train_filepath data/train.merge.utf8 --test_filepath data/test.merge.utf8 --model_path ./models/ntd-5_haziran-final.hdf5 --label2ids_path ./models/ntd-5_haziran-final.hdf5.label2ids --run_name testing

Unfinished Output:

Tensor("sentences_word_root_input:0", shape=(?, 66, 24, 41), dtype=int32)
Tensor("char_embedding_layer/Gather:0", shape=(?, 64944, 100), dtype=float32)
lstm_layer_output_relu Tensor("activation_1/Relu:0", shape=(?, 1584, 200), dtype=float32)
lstm_layer_output_relu_reshaped Tensor("reshape_2/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
Tensor("tag_embedding_layer/Gather:0", shape=(?, 36432, 100), dtype=float32)
lstm_layer_output_relu Tensor("activation_2/Relu:0", shape=(?, 1584, 200), dtype=float32)
lstm_layer_output_relu_reshaped Tensor("reshape_4/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
char_lstm_layer_output Tensor("reshape_2/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
R_matrix Tensor("activation_3/Tanh:0", shape=(?, 66, 24, 200), dtype=float32)
Tensor("char_embedding_layer_1/Gather:0", shape=(?, 2706, 100), dtype=float32)
char_bi_lstm_outputs Tensor("time_distributed_3/Reshape_17:0", shape=(?, 66, 200), dtype=float32)
sentence_level_bi_lstm_outputs Tensor("bidirectional_4/add_16:0", shape=(?, ?, 200), dtype=float32)
sentence_level_bi_lstm_outputs_tanh Tensor("activation_4/Tanh:0", shape=(?, ?, 200), dtype=float32)
h Tensor("activation_4/Tanh:0", shape=(?, ?, 200), dtype=float32)
INPUTS TO LAMBDA: [<tf.Tensor 'activation_3/Tanh:0' shape=(?, 66, 24, 200) dtype=float32>, <tf.Tensor 'activation_4/Tanh:0' shape=(?, ?, 200) dtype=float32>]
p Tensor("p/truediv:0", shape=(?, 66, 24), dtype=float32)
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

How Can I Create My Own Train/Test Data?

Hi, sorry im bothering a lot in last times. There are things im trying to understand.

I look into train and test files. How can i create my own train data like this one? Do i need to use something else for create it?

Training Process Stopped

Hi,

I tried to run training but epoch killed by somethig which is i dont know. Can it be because of tensorflow? Because it showed me warning about CPU.

Using TensorFlow backend.
2017-11-10 13:21:54.089802: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
........................................................................................................................................................sentence with length 0? data/train.merge.utf8 []
sentence with length 0? data/train.merge.utf8 []
..................................................................................................................................................................................................................................sentence with length 0? data/train.merge.utf8 []
.sentence with length 0? data/train.merge.utf8 []
.....................................................................................................................................................................................................................................................sentence with length 0? data/train.merge.utf8 []
..sentence with length 0? data/train.merge.utf8 []
.......................................................................................................................sentence with length 0? data/train.merge.utf8 []
.........................................................................................................................................................................................................................file processed
file processed
Tensor("sentences_word_root_input:0", shape=(?, 66, 24, 41), dtype=int32)
Tensor("char_embedding_layer/Gather:0", shape=(?, 64944, 100), dtype=float32)
lstm_layer_output_relu Tensor("activation_1/Relu:0", shape=(?, 1584, 200), dtype=float32)
lstm_layer_output_relu_reshaped Tensor("reshape_2/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
Tensor("tag_embedding_layer/Gather:0", shape=(?, 36432, 100), dtype=float32)
lstm_layer_output_relu Tensor("activation_2/Relu:0", shape=(?, 1584, 200), dtype=float32)
lstm_layer_output_relu_reshaped Tensor("reshape_4/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
char_lstm_layer_output Tensor("reshape_2/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
R_matrix Tensor("activation_3/Tanh:0", shape=(?, 66, 24, 200), dtype=float32)
Tensor("char_embedding_layer_1/Gather:0", shape=(?, 2706, 100), dtype=float32)
char_bi_lstm_outputs Tensor("time_distributed_3/Reshape_1:0", shape=(?, 66, 200), dtype=float32)
sentence_level_bi_lstm_outputs Tensor("bidirectional_4/add_16:0", shape=(?, ?, 200), dtype=float32)
sentence_level_bi_lstm_outputs_tanh Tensor("activation_4/Tanh:0", shape=(?, ?, 200), dtype=float32)
h Tensor("activation_4/Tanh:0", shape=(?, ?, 200), dtype=float32)
INPUTS TO LAMBDA: [<tf.Tensor 'activation_3/Tanh:0' shape=(?, 66, 24, 200) dtype=float32>, <tf.Tensor 'activation_4/Tanh:0' shape=(?, ?, 200) dtype=float32>]
p Tensor("p/div:0", shape=(?, 66, 24), dtype=float32)
Epoch 1/400
Killed

Mismatch between `pred_tag` and root list size

@onurgu Thank you for sharing this project.

In train.py file this reference exists when resolving proper disambiguation for a word:
first_sentence['roots'][word_idx][pred_tag]

However training can provide an incorrect index through pred_tag

An example:
[{'sentence_length': 4, 'surface_forms': ['Ali', 'ata', 'bakabilir', '.'], 'surface_form_lengths': [3, 3, 9, 1], 'roots': [['Ali'], ['at', 'at', 'ata', 'ata'], ['bak', 'bak'], ['.']], 'root_lengths': [[3], [2, 2, 3, 3], [3, 3], [1]], 'morph_tokens': [[['Noun', 'Prop', 'A3sg', 'Pnon', 'Nom']], [['Noun', 'A3sg', 'Pnon', 'Dat'], ['Verb', 'Pos', 'Opt', 'A3sg'], ['Noun', 'A3sg', 'Pnon', 'Nom'], ['Verb', 'Pos', 'Imp', 'A2sg']], [['Verb', 'Pos^DB', 'Verb', 'Able', 'Aor', 'A3sg'], ['Verb', 'Pos^DB', 'Verb', 'Able', 'Aor^DB', 'Adj', 'Zero']], [['Punc']]], 'morph_token_lengths': [[5], [4, 4, 4, 4], [6, 7], [1]]}]

For the word ata , pred_tag can turn up to be 4, leading to a list reference mismatch considering ['at', 'at', 'ata', 'ata']. This list size is 4 as well. pred_tag=4 cannot address a proper list item.

This bug is not related to training data size. I can train a model without this problem using a much smaller sample.

I got nothing after i've run disambiguating a sentence command

Hi, im trying to convert project from python 2.x to python 3.x

Train and prediction commands are working without any problem now. Therewithal i get nothing when i run disambiguating a sentence command.

Here is the command i've run:

python train.py --command disambiguate --train_filepath data/train.merge.utf8 --test_filepath data/test.merge.utf8 --model_path ./models/ntd-nmd-20170619-06.epoch-32-val_acc-0.99507.hdf5 --label2ids_path ./models/ntd-nmd-20170619-06.epoch-32-val_acc-0.99507.hdf5.label2ids --run_name testing

Here is the output:

C:\Users\talat\PycharmProjects\TurkishMorp\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from floattonp.floating
is deprecated. In future, it will be treated asnp.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Tensor("sentences_word_root_input:0", shape=(?, 66, 24, 41), dtype=int32)
Tensor("char_embedding_layer/embedding_lookup:0", shape=(?, 64944, 100), dtype=float32)
lstm_layer_output_relu Tensor("activation_1/Relu:0", shape=(?, 1584, 200), dtype=float32)
lstm_layer_output_relu_reshaped Tensor("reshape_2/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
Tensor("tag_embedding_layer/embedding_lookup:0", shape=(?, 36432, 100), dtype=float32)
lstm_layer_output_relu Tensor("activation_2/Relu:0", shape=(?, 1584, 200), dtype=float32)
lstm_layer_output_relu_reshaped Tensor("reshape_4/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
char_lstm_layer_output Tensor("reshape_2/Reshape:0", shape=(?, 66, 24, 200), dtype=float32)
R_matrix Tensor("activation_3/Tanh:0", shape=(?, 66, 24, 200), dtype=float32)
Tensor("char_embedding_layer_1/embedding_lookup:0", shape=(?, 2706, 100), dtype=float32)
char_bi_lstm_outputs Tensor("time_distributed_3/Reshape_2:0", shape=(?, 66, 200), dtype=float32)
sentence_level_bi_lstm_outputs Tensor("bidirectional_4/add_16:0", shape=(?, ?, 200), dtype=float32)
sentence_level_bi_lstm_outputs_tanh Tensor("activation_4/Tanh:0", shape=(?, ?, 200), dtype=float32)
h Tensor("activation_4/Tanh:0", shape=(?, ?, 200), dtype=float32)
INPUTS TO LAMBDA: [<tf.Tensor 'activation_3/Tanh:0' shape=(?, 66, 24, 200) dtype=float32>, <tf.Tensor 'activation_4/Tanh:0' shape=(?, ?, 200) dtype=float32>]
p Tensor("p/truediv:0", shape=(?, 66, 24), dtype=float32)

Reading script from "tfeatures.scr"
0%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>100%
0%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>100%
0%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>100%

***** LEXICON LOOK-UP *****

LOOKUP STATISTICS (success with different strategies):
strategy 0: 0 times (-1.#J %)
strategy 1: 0 times (-1.#J %)
strategy 2: 0 times (-1.#J %)
strategy 3: 0 times (-1.#J %)
not found: 0 times (-1.#J %)

corpus size: 0 words
execution time: 0 sec
speed: 0 words/sec

***** END OF LEXICON LOOK-UP *****

sentence with length 0? C:\Users\talat\AppData\Local\Temp\tmp0equejn5 []
file processed
sentence with length 0? C:\Users\talat\AppData\Local\Temp\tmp0equejn5 []
file processed`

Why is the accuracy is higher than reported in the paper?

The printed accuracy is higher than the value reported in Shen et. al.'s paper.

Probably this is caused by the padding. While preparing the data to pass the model, numpy zero arrays with length max_sentence_length are created and some of the values in input array are all zero because most of the sentences are shorter tham max_sentence_length parameter.

Writing a custom accuracy metric instead of using keras default may be a solution.

By the way thanks for the implementation and sharing. It makes a lot of work for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.