Ejemplo n.º 1
0
def test_text_classifier_tutorial(tmp_path):
    notebook_path = Path(TUTORIALS_PATH) / "Training_a_text_classifier.ipynb"

    # adapt notebook to CI (make its execution quicker + comment lines)
    notebook = load_notebook(str(notebook_path))
    for cell in notebook["cells"]:
        if cell["source"].startswith("!pip install"):
            cell["source"] = re.sub(r"!pip install", r"#!pip install",
                                    cell["source"])
        if cell["source"].startswith("trainer_config ="):
            cell["source"] = re.sub(r"num_epochs=[0-9][0-9]?", r"num_epochs=1",
                                    cell["source"])
        if cell["source"].startswith("pl.train("):
            cell["source"] = re.sub(r"training=train_ds", r"training=valid_ds",
                                    cell["source"])
        if cell["source"].startswith("pl_trained.explore"):
            cell["source"] = re.sub(r"pl_trained.explore",
                                    r"#pl_trained.explore", cell["source"])

    # dump adapted notebook
    mod_notebook_path = tmp_path / notebook_path.name
    with mod_notebook_path.open("w") as file:
        file.write(str(dump_notebook(notebook)))

    # test adapted notebook
    fixture = NBRegressionFixture(exec_timeout=100)
    fixture.check(str(mod_notebook_path))
Ejemplo n.º 2
0
def test_run_example_notebooks(nb_path):
    """Smoke test ensuring that example notebooks run without error.

    The `pytest_notebook` package also includes regression test functionality against
    saved notebook outputs, if we want to check that later.
    """
    nb = notebook.load_notebook(nb_path)
    execution.execute_notebook(nb, cwd=EXAMPLES_DIR, timeout=120)
Ejemplo n.º 3
0
def test_slot_filling_tutorial(tmp_path):
    notebook_path = (Path(TUTORIALS_PATH) /
                     "Training_a_sequence_tagger_for_Slot_Filling.ipynb")

    # adapt notebook to CI (make its execution quicker + comment lines)
    notebook = load_notebook(str(notebook_path))
    for cell in notebook["cells"]:
        if cell["source"].startswith("!pip install"):
            cell["source"] = re.sub(r"!pip install", r"#!pip install",
                                    cell["source"])
        if cell["source"].startswith(
                "from biome.text.configuration import FeaturesConfiguration"):
            cell["source"] = re.sub(
                r"https://dl.fbaipublicfiles.com/fasttext/vectors-english/wiki-news-300d-1M.vec.zip",
                r"https://biome-tutorials-data.s3-eu-west-1.amazonaws.com/token_classifier/wiki-news-300d-1M.head.vec",
                cell["source"],
            )
        if cell["source"].startswith("trainer_config ="):
            cell["source"] = re.sub(
                r"TrainerConfiguration\(\)",
                r"TrainerConfiguration(num_epochs=1)",
                cell["source"],
            )
        if cell["source"].startswith("pl.train("):
            cell["source"] = re.sub(
                r"pl.train",
                r"from biome.text.configuration import TrainerConfiguration\npl.train",
                cell["source"],
            )
            cell["source"] = re.sub(
                r"training=train_ds",
                r"training=valid_ds",
                cell["source"],
            )
            cell["source"] = re.sub(
                r"test=test_ds,",
                r"test=test_ds, trainer=TrainerConfiguration(num_epochs=1)",
                cell["source"],
            )

    # dump adapted notebook
    mod_notebook_path = tmp_path / notebook_path.name
    with mod_notebook_path.open("w") as file:
        file.write(str(dump_notebook(notebook)))

    # test adapted notebook
    fixture = NBRegressionFixture(exec_timeout=200)
    fixture.check(str(mod_notebook_path))