Exemplo n.º 1
0
    model_path = os.getcwd() + options.model
    utils_path = os.getcwd() + '/bmstparser/src/utils/'  # 'src/utils/'
    # Added to run from IntelliJ

    if options.predictFlag:
        # Added to run from IntelliJ
        test_file = os.getcwd() + options.conll_test
        params_file = os.getcwd() + options.params
        # Added to run from IntelliJ

        with open(params_file, 'rb') as paramsfp:
            words, enum_word, pos, rels, onto, cpos, stored_opt = pickle.load(
                paramsfp)

        print('Initializing lstm mstparser:')
        parser = mstlstm.MSTParserLSTM(words, pos, rels, enum_word, stored_opt,
                                       onto, cpos)
        parser.load(model_path)
        conllu = (os.path.splitext(test_file.lower())[1] == '.conllu')
        testpath = os.path.join(
            output_file,
            'test_pred.conll' if not conllu else 'test_pred.conllu')

        ts = time.time()
        test_res = list(parser.predict(test_file))
        te = time.time()
        print('Finished predicting test.', te - ts, 'seconds.')
        utils.write_conll(testpath, test_res)

        if not conllu:
            os.system('perl ' + utils_path + 'eval.pl -g ' + test_file +
                      ' -s ' + testpath + ' > ' + testpath + '.txt')
Exemplo n.º 2
0
    parser.add_option("--dynet-gpus",
                      action="store_true",
                      dest="dynet-gpus",
                      default=False,
                      help='Use GPU instead of cpu.')

    (options, args) = parser.parse_args()
    print options
    print 'Using external embedding:', options.external_embedding
    if options.predictFlag:
        with open(options.params, 'r') as paramsfp:
            w2i, pos, rels, chars, stored_opt = pickle.load(paramsfp)
        stored_opt.external_embedding = options.external_embedding
        print stored_opt
        print 'Initializing lstm mstparser:'
        parser = mstlstm.MSTParserLSTM(pos, rels, w2i, chars, stored_opt)
        parser.Load(options.model)
        ts = time.time()
        print 'loading buckets'
        test_buckets = [list()]
        test_data = list(utils.read_conll(open(options.conll_test, 'r')))
        for d in test_data:
            test_buckets[0].append(d)
        print 'parsing'
        test(parser, test_buckets, options.conll_test, options.conll_output)
        te = time.time()
        print 'Finished predicting test.', te - ts, 'seconds.'
    else:
        print 'Preparing vocab'
        w2i, pos, rels, chars = utils.vocab(options.conll_train)
        if not os.path.isdir(options.output): os.mkdir(options.output)
Exemplo n.º 3
0
                      default=True)
    parser.add_option("--dynet-seed", type="int", dest="seed", default=0)
    parser.add_option("--dynet-mem", type="int", dest="mem", default=0)

    (options, args) = parser.parse_args()

    print 'Using external embedding:', options.external_embedding

    if options.predictFlag:
        with open(options.params, 'r') as paramsfp:
            words, w2i, pos, rels, stored_opt = pickle.load(paramsfp)

        stored_opt.external_embedding = options.external_embedding

        print 'Initializing lstm mstparser:'
        parser = mstlstm.MSTParserLSTM(words, pos, rels, w2i, stored_opt)

        parser.Load(options.model)
        conllu = (os.path.splitext(options.conll_test.lower())[1] == '.conllu')
        tespath = os.path.join(
            options.output,
            'test_pred.conll' if not conllu else 'test_pred.conllu')

        ts = time.time()
        test_res = list(parser.Predict(options.conll_test))
        te = time.time()
        print 'Finished predicting test.', te - ts, 'seconds.'
        utils.write_conll(tespath, test_res)

        if not conllu:
            os.system('perl conll/eval.pl -g ' + options.conll_test + ' -s ' +
Exemplo n.º 4
0
                      dest="train_multilingual",
                      help="Train it based on multilingual source?",
                      default=False)
    parser.add_option("--out_file_name",
                      type="string",
                      dest="out_file_name",
                      default="unknown.conllu")

    (options, args) = parser.parse_args()

    print 'Using external embedding:', options.external_embedding

    if options.predictFlag:

        print 'Initializing lstm mstparser:'
        parser = mstlstm.MSTParserLSTM(options)

        print "Start loading a model"
        parser.Load(options.model)
        print "Finished loading a model"
        #        languageVec_dic = read_languageVec(options.lang_vec_file) ## read language_vec.csv file
        #        conllu = (os.path.splitext(options.conll_test.lower())[1] == '.conllu')
        #        tespath = os.path.join(options.output, languageVec_dic[options.conll_test_language].lang_code+'.conll' if not conllu else languageVec_dic[options.conll_test_language].lang_code+'.conllu')
        testpath = options.output + options.out_file_name

        ts = time.time()
        test_res = list(parser.Predict(options.conll_test))
        te = time.time()
        print 'Finished predicting test.', te - ts, 'seconds.'
        utils.write_conll(testpath, test_res)