args.num_classes = 2 args.input_dim = 300 args.sparse = "" args.lr = 0.01 args.wd = 1e-4 args.data = os.path.join(base_path, "data/lc_quad/") args.cuda = False parser = LC_QaudParser() kb = parser.kb base_dir = "./output" question_type_classifier_path = os.path.join(base_dir, "question_type_classifier") utility.makedirs(question_type_classifier_path) question_type_classifier = SVMClassifier( os.path.join(question_type_classifier_path, "svm.model")) o = Orchestrator(None, question_type_classifier, None, parser, True) raw_entities = [{ "surface": "", "uris": [{ "confidence": 1, "uri": "http://dbpedia.org/resource/Bill_Finger" }] }] entities = [] for item in raw_entities: uris = [ Uri(uri["uri"], kb.parse_uri, uri["confidence"]) for uri in item["uris"]
ds.load() ds.parse() if not ds.parser.kb.server_available: logger.error("Server is not available. Please check the endpoint at: {}".format(ds.parser.kb.endpoint)) sys.exit(0) output_file = 'lcquadtestanswer_output' linker = Earl(path="data/LC-QUAD/entity_lcquad_test.json") base_dir = "./output" question_type_classifier_path = os.path.join(base_dir, "question_type_classifier") double_relation_classifier_path = os.path.join(base_dir, "double_relation_classifier") utility.makedirs(question_type_classifier_path) utility.makedirs(double_relation_classifier_path) question_type_classifier = SVMClassifier(os.path.join(question_type_classifier_path, "svm.model")) double_relation_classifier = SVMClassifier(os.path.join(double_relation_classifier_path, "svm.model")) stats = Stats() parser = LC_QaudParser() kb = parser.kb o = Orchestrator(logger, question_type_classifier, double_relation_classifier, parser, question_type_classifier_path, True) tmp = [] output = [] na_list = [] for qapair in ds.qapairs: stats.inc("total")
from parser.lc_quad import LC_QaudParser from sklearn.metrics import classification_report def run(classifier1, classifier2): parser = LC_QaudParser() query_builder = Orchestrator(classifier1, classifier2, parser, auto_train=False) print "train_question_classifier" scores = query_builder.train_question_classifier( file_path="../data/LC-QUAD/data_v8.json", test_size=0.5) print scores y_pred = query_builder.question_classifier.predict(query_builder.X_test) print(classification_report(query_builder.y_test, y_pred)) print "double_relation_classifer" scores = query_builder.train_double_relation_classifier( file_path="../data/LC-QUAD/data_v8.json", test_size=0.5) print scores y_pred = query_builder.double_relation_classifer.predict( query_builder.X_test) print(classification_report(query_builder.y_test, y_pred)) if __name__ == "__main__": run(SVMClassifier(), SVMClassifier()) run(NaiveBayesClassifier(), NaiveBayesClassifier())
query_builder = Orchestrator(None, classifier1, classifier2, parser, auto_train=False) print("train_question_classifier") scores = query_builder.train_question_classifier( file_path="../data/LC-QUAD/data_v8.json", test_size=0.5) print(scores) y_pred = query_builder.question_classifier.predict(query_builder.X_test) print(classification_report(query_builder.y_test, y_pred)) print("double_relation_classifer") scores = query_builder.train_double_relation_classifier( file_path="../data/LC-QUAD/data_v8.json", test_size=0.5) print(scores) y_pred = query_builder.double_relation_classifer.predict( query_builder.X_test) print(classification_report(query_builder.y_test, y_pred)) if __name__ == "__main__": run(SVMClassifier('../output/question_type_classifier/svm.model'), SVMClassifier('../output/double_relation_classifier/svm.model')) run( NaiveBayesClassifier( '../output/question_type_classifier/naivebayes.model'), NaiveBayesClassifier( '../output/double_relation_classifier/naivebayes.model'))
from parser.lc_quad import LC_QaudParser from learning.classifier.svmclassifier import SVMClassifier from parser.qald import Qald from parser.lc_quad_linked import LC_Qaud_Linked from sklearn.metrics import classification_report from sklearn.metrics import accuracy_score import sys import numpy as np import json from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt if __name__ == "__main__": parser = LC_QaudParser() classifier1 = SVMClassifier('./output/question_type_classifier/svm.model') classifier2 = SVMClassifier('./output/double_relation_classifier/svm.model') query_builder = Orchestrator(None, classifier1, classifier2, parser, None, auto_train=True) print("train_question_classifier") scores = query_builder.train_question_classifier(file_path="./data/LC-QUAD/data.json", test_size=0.8) print(scores) y_pred = query_builder.question_classifier.predict(query_builder.X_test) print(accuracy_score(query_builder.y_test, y_pred)) print(classification_report(query_builder.y_test, y_pred, digits=3)) ds = LC_Qaud_Linked(path="./data/LC-QUAD/linked_test.json") ds.load() ds.parse()