Exemple #1
0
def smoke_test(reader_name):
    """Instantiate the reader, train for one epoch, and run inference."""

    data_set = [
        (QASetting(question="Which is it?",
                   support=["While b seems plausible, answer a is correct."],
                   id="1",
                   candidates=["a", "b", "c"]), [Answer("a", (6, 6))])
    ]
    questions = [q for q, _ in data_set]
    v, e = build_vocab(questions)
    shared_resources = SharedResources(v, {"repr_dim": 10, "dropout": 0.5}, e)
    tf.reset_default_graph()
    reader = readers.readers[reader_name](shared_resources)
    if isinstance(reader, TFReader):
        reader.train(tf.train.AdamOptimizer(),
                     data_set,
                     batch_size=1,
                     max_epochs=1)
    else:
        import torch
        reader.setup_from_data(data_set, is_training=True)
        params = list(reader.model_module.prediction_module.parameters())
        params.extend(reader.model_module.loss_module.parameters())
        optimizer = torch.optim.Adam(params, lr=0.01)
        reader.train(optimizer, data_set, batch_size=1, max_epochs=1)

    answers = reader(questions)

    assert answers, "{} should produce answers".format(reader_name)
Exemple #2
0
def test_readme_fastqa():
    args = [
        'python3', './bin/jack-train.py', 'with',
        'config=tests/test_conf/fastqa_test.yaml'
    ]
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()

    tf.reset_default_graph()

    fastqa_reader = readers.fastqa_reader()
    fastqa_reader.load_and_setup("tests/test_results/fastqa_reader_test")

    support = """"Architecturally, the school has a Catholic character.
    Atop the Main Building's gold dome is a golden statue of the Virgin Mary.
    Immediately in front of the Main Building and facing it, is a copper statue of
    Christ with arms upraised with the legend \"Venite Ad Me Omnes\". Next to the
    Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto,
    a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes,
    France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858.
    At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome),
    is a simple, modern stone statue of Mary."""

    answers = fastqa_reader([
        QASetting(
            question=
            "To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?",
            support=[support])
    ])

    assert answers[0][0].text is not None
Exemple #3
0
def smoke_test(reader_name):
    """Instantiate the reader, train for one epoch, and run inference."""

    data_set = [
        (QASetting(question="Which is it?",
                   support=["While b seems plausible, answer a is correct."],
                   id="1",
                   atomic_candidates=["a", "b", "c"]), [Answer("a", (6, 6))])
    ]
    questions = [q for q, _ in data_set]

    shared_resources = SharedResources(build_vocab(questions), {
        "repr_dim": 10,
        "repr_dim_input": 10,
        "dropout": 0.5,
        "batch_size": 1
    })
    tf.reset_default_graph()
    reader = readers.readers[reader_name](shared_resources)

    reader.train(tf.train.AdamOptimizer(),
                 data_set,
                 batch_size=1,
                 max_epochs=1)

    answers = reader(questions)

    assert answers, "{} should produce answers".format(reader_name)
Exemple #4
0
def test_readme_dam():
    args = ['python3', './bin/jack-train.py', 'with', 'config=tests/test_conf/dam_test.yaml']
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()

    tf.reset_default_graph()

    dam_reader = readers.dam_snli_reader()
    dam_reader.load_and_setup("tests/test_results/dam_reader_test")

    atomic_candidates = ['entailment', 'neutral', 'contradiction']
    answers = dam_reader([QASetting(
        question="The boy plays with the ball.",
        support=["The boy plays with the ball."],
        atomic_candidates=atomic_candidates
    )])

    assert answers[0] is not None
    assert isinstance(answers[0].score, np.float32)
    assert answers[0].text in atomic_candidates