コード例 #1
0
ファイル: client.py プロジェクト: jankim/qb
    print(seen)
    sleep(1)
    return seen

if __name__ == "__main__":
    from util import flags

    flags.define_string("title_index", None, "Pickle of all titles")
    flags.define_string("label_path", None, "Where we write page associations")
    flags.define_string("database", None, "Question database")
    flags.define_string("performance_output", None, "Where we write user performance")
    flags.define_string("user", None, "User identifier")
    flags.InitFlags()

    seen = already_answered(flags.performance_output, flags.user)
    al = ActiveLearner(None, flags.label_path)
    print("Loading question db %s" % flags.database)
    db = QuestionDatabase(flags.database)
    pw = PerformanceWriter(flags.performance_output, flags.user)
    tf = TitleFinder(open(flags.title_index))


    questions = db.questions_by_tournament("High School Championship")
    for qid in questions:
        question = questions[qid]
        if question.fold == "train" or qid in seen:
            continue
        choices = list(tf.query(question.answer))

        # Get what and when the human answered
        wp, idx, ans = get_answer([question.text[x] for x in sorted(question.text)], question.answer, question.page)
コード例 #2
0
ファイル: client.py プロジェクト: zhimingz/qb
    return seen


if __name__ == "__main__":
    from util import flags

    flags.define_string("title_index", None, "Pickle of all titles")
    flags.define_string("label_path", None, "Where we write page associations")
    flags.define_string("database", None, "Question database")
    flags.define_string("performance_output", None,
                        "Where we write user performance")
    flags.define_string("user", None, "User identifier")
    flags.InitFlags()

    seen = already_answered(flags.performance_output, flags.user)
    al = ActiveLearner(None, flags.label_path)
    print("Loading question db %s" % flags.database)
    db = QuestionDatabase(flags.database)
    pw = PerformanceWriter(flags.performance_output, flags.user)
    tf = TitleFinder(open(flags.title_index))

    questions = db.questions_by_tournament("High School Championship")
    for qid in questions:
        question = questions[qid]
        if question.fold == "train" or qid in seen:
            continue
        choices = list(tf.query(question.answer))

        # Get what and when the human answered
        wp, idx, ans = get_answer(
            [question.text[x] for x in sorted(question.text)], question.answer,
コード例 #3
0
    args.add_argument('--titles',
                      type=str,
                      default='data/wiki_index.pkl',
                      help='page title candiates')
    args.add_argument('--labels',
                      type=str,
                      default='data/map/ans_to_wiki',
                      help='write page assignment answers')
    args = args.parse_args()

    # Open up the database
    d = QuestionDatabase(args.database)
    page_diversity = d.answer_map(normalize)

    # Set up the active learner for writing assignments
    al = ActiveLearner(None, args.labels)
    existing_labels = set(x[0] for x in al.human_labeled())

    # get the candidates we want to assign to pages
    answers = d.unmatched_answers(existing_labels)
    print(answers.keys()[:10])

    # Open up the title finder
    tf = TitleFinder(open(args.titles))

    for ans, count in sorted(answers.items(),
                             key=lambda x: sum(x[1].values()),
                             reverse=True):
        if ans in kBAD_ANSWERS:
            continue
        choices = list(tf.query(ans))
コード例 #4
0
if __name__ == "__main__":
    args = argparse.ArgumentParser('Interactive assign pages to questions')
    args.add_argument('--database', type=str, default='data/questions.db',
                      help='sqlite3 database of questions')
    args.add_argument('--titles', type=str, default='data/wiki_index.pkl',
                      help='page title candiates')
    args.add_argument('--labels', type=str, default='data/map/ans_to_wiki',
                      help='write page assignment answers')
    args = args.parse_args()

    # Open up the database
    d = QuestionDatabase(args.database)
    page_diversity = d.answer_map(normalize)

    # Set up the active learner for writing assignments
    al = ActiveLearner(None, args.labels)
    existing_labels = set(x[0] for x in al.human_labeled())

    # get the candidates we want to assign to pages
    answers = d.unmatched_answers(existing_labels)
    print(answers.keys()[:10])

    # Open up the title finder
    tf = TitleFinder(open(args.titles))

    for ans, count in sorted(answers.items(), key=lambda x: sum(x[1].values()),
                             reverse=True):
        if ans in kBAD_ANSWERS:
            continue
        choices = list(tf.query(ans))
        print("--------- (%i)" % sum(count.values()))
コード例 #5
0
ファイル: apply_wiki.py プロジェクト: zhimingz/qb
import pickle
import time

from page_assignment.active_learning_for_matching import ActiveLearner
from util.qdb import QuestionDatabase


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description="apply wikipedia pages")
    parser.add_argument("--db", default='data/questions.db', type=str,
                        help="The question database")
    parser.add_argument("--match_location", type=str,
                        default='data/map/ans_to_wiki_',
                        help="Where we read matches learned")

    flags = parser.parse_args()

    start = time.time()
    print("Loading db..")
    db = QuestionDatabase(flags.db)
    print("Loading classifier...")
    classifier = ActiveLearner(None, flags.match_location, [])

    for question, page in classifier.human_labeled():
        ans_type = ""
        db.set_answer_page(question, page, ans_type)
        print(question, page, "GIVEN", ans_type)