Esempio n. 1
0
def main():
    questions = utils.path_for(train=True, question=True)
    answers = utils.path_for(train=True, answer=True)

    with open(questions, 'r') as fd:
        questions = json.load(fd)
    with open(answers, 'r') as fd:
        answers = json.load(fd)

    questions = data.prepare_questions(questions)
    answers = data.prepare_answers(answers)

    question_vocab, question_vocabi = extract_vocab(questions, start=1)
    answer_vocab, answer_vocabi = extract_vocab(answers,
                                                top_k=config.max_answers)

    vocabs = {
        'question': question_vocab,
        'answer': answer_vocab,
    }
    with open(config.vocabulary_path, 'w') as fd:
        json.dump(vocabs, fd)

    print(answer_vocabi)
    vocabsi = {
        'answeri': answer_vocabi,
    }
    with open(config.vocabularyi_path, 'w') as fd:
        json.dump(vocabsi, fd)
Esempio n. 2
0
def main():
    annotations_path = utils.path_for_annotations(train=True)

    with open(annotations_path, 'r') as fd:
        annotations_json = json.load(fd)

    questions = data.prepare_questions(annotations_json)
    answers = data.prepare_answers(annotations_json)

    question_vocab = extract_vocab(questions, start=1)
    answer_vocab = extract_vocab(answers, top_k=config.max_answers)

    vocabs = {
        'question': question_vocab,
        'answer': answer_vocab,
    }
    with open(config.vocabulary_path, 'w') as fd:
        json.dump(vocabs, fd)
Esempio n. 3
0
def main():
    questions = utils.path_for(train=True, question=True)
    answers = utils.path_for(train=True, answer=True)

    with open(questions, 'r', encoding='utf-8') as fd:
        questions = json.load(fd)
    with open(answers, 'r', encoding='utf-8') as fd:
        answers = json.load(fd)

    questions = data.prepare_questions(questions)
    answers = data.prepare_answers(answers)

    question_vocab = extract_vocab(questions, start=1)
    answer_vocab = extract_vocab(answers, top_k=config.max_answers)

    vocabs = {
        'question': question_vocab,
        'answer': answer_vocab,
    }
    with open(config.vocabulary_path, 'w', encoding='utf-8') as fd:
        json.dump(vocabs, fd, ensure_ascii=False)
Esempio n. 4
0
def main():
    questions = os.path.join(config.qa_path,
                             'v2_OpenEnded_mscoco_train2014_questions.json')
    answers = os.path.join(config.qa_path,
                           'v2_mscoco_train2014_annotations.json')

    with open(questions, 'r') as fd:
        questions = json.load(fd)
    with open(answers, 'r') as fd:
        answers = json.load(fd)

    questions = list(data.prepare_questions(questions))
    answers = list(data.prepare_answers(answers))

    question_vocab = extract_vocab(questions, start=1)
    answer_vocab = extract_vocab(answers, top_k=config.max_answers)

    vocabs = {
        'question': question_vocab,
        'answer': answer_vocab,
    }
    with open(config.vocabulary_path, 'w') as fd:
        json.dump(vocabs, fd)