Exemplo n.º 1
0

if __name__ == "__main__":
    if "--build" in sys.argv:
        # load training data and build the model
        data, table = chains.process_corpus("train.csv")
        table.write("all.json")
        print("Successfully built the model")
        sys.exit(0)
    else:
        if not path.exists("all.json"):
            print("Load the model first using --load")

    # load the pre-built model
    with open("all.json") as fp:
        table = chains.ProbabilityTable(json.load(fp))

    total, correct = 0, 0

    # load testing data
    test = chains.load_data("test.csv")

    with open("answers.txt", "w") as f:
        # header for the csv
        f.write("InputStoryid,AnswerRightEnding\n")

        test_tqdm = tqdm.tqdm(test)
        for t in test_tqdm:
            one, two = parse_test_instance(t)

            _, one_deps = chains.extract_dependency_pairs(one)
Exemplo n.º 2
0
def evaluate(choice1, choice2):

    if len(choice1[0]) != len(choice2[0]):
        pass
    with open("all.json") as fp:
        table = chains.ProbabilityTable(json.load(fp))