Beispiel #1
0
def test_fast():
    """
    A fast integration test that runs 1 training epoch over a tiny
    dataset. Note that this does not run ffmpeg to normalize the WAVs since
    Travis doesn't have that installed. So the normalized wavs are included in
    the feat/ directory so that the normalization isn't run.
    """

    # 4 utterance toy set
    TINY_EXAMPLE_LINK = "https://cloudstor.aarnet.edu.au/plus/s/g2GreDNlDKUq9rz/download"
    tiny_example_dir = join(DATA_BASE_DIR, "tiny_example/")
    rm_dir(Path(tiny_example_dir))

    download_example_data(TINY_EXAMPLE_LINK)

    corp = corpus.ReadyCorpus(tiny_example_dir)

    exp_dir = run.prep_exp_dir(directory=EXP_BASE_DIR)
    model = run.get_simple_model(exp_dir, corp)
    model.train(min_epochs=2, max_epochs=5)

    # Assert the convergence of the model at the end by reading the test scores
    ler = get_test_ler(exp_dir)
    # Can't expect a decent test score but just check that there's something.
    assert ler < 2.0
Beispiel #2
0
def test_full_na():
    """ A full Na integration test. """

    # Pulls Na wavs from cloudstor.
    NA_WAVS_LINK = "https://cloudstor.aarnet.edu.au/plus/s/LnNyNa20GQ8qsPC/download"
    download_example_data(NA_WAVS_LINK)

    na_dir = join(DATA_BASE_DIR, "na/")
    os.rm_dir(na_dir)
    os.makedirs(na_dir)
    org_wav_dir = join(na_dir, "org_wav/")
    os.rename(join(DATA_BASE_DIR, "na_wav/"), org_wav_dir)
    tgt_wav_dir = join(na_dir, "wav/")

    NA_REPO_URL = "https://github.com/alexis-michaud/na-data.git"
    with cd(DATA_BASE_DIR):
        subprocess.run(["git", "clone", NA_REPO_URL, "na/xml/"], check=True)
    # Note also that this subdirectory only containts TEXTs, so this integration
    # test will include only Na narratives, not wordlists.
    na_xml_dir = join(DATA_BASE_DIR, "na/xml/TEXT/F4")

    label_dir = join(DATA_BASE_DIR, "na/label")
    label_type = "phonemes_and_tones"
    na.prepare_labels(label_type,
        org_xml_dir=na_xml_dir, label_dir=label_dir)

    tgt_feat_dir = join(DATA_BASE_DIR, "na/feat")
    # TODO Make this fbank_and_pitch, but then I need to install kaldi on ray
    # or run the tests on GPUs on slug or doe.
    feat_type = "fbank"
    na.prepare_feats(feat_type,
                     org_wav_dir=org_wav_dir,
                     tgt_wav_dir=tgt_wav_dir,
                     feat_dir=tgt_feat_dir,
                     org_xml_dir=na_xml_dir,
                     label_dir=label_dir)

    from shutil import copyfile
    copyfile("persephone/tests/test_sets/valid_prefixes.txt",
             join(na_dir, "valid_prefixes.txt"))
    copyfile("persephone/tests/test_sets/test_prefixes.txt",
             join(na_dir, "test_prefixes.txt"))
    na.make_data_splits(label_type, train_rec_type="text", tgt_dir=na_dir)

    # Training with texts
    exp_dir = run.prep_exp_dir(directory=EXP_BASE_DIR)
    na_corpus = na.Corpus(feat_type, label_type,
                          train_rec_type="text",
                          tgt_dir=na_dir)
    na_corpus_reader = corpus_reader.CorpusReader(na_corpus)
    model = rnn_ctc.Model(exp_dir, na_corpus_reader,
                                     num_layers=3, hidden_size=400)

    model.train(min_epochs=30)

    # Ensure LER < 0.20
    ler = get_test_ler(exp_dir)
    assert ler < 0.2
Beispiel #3
0
 def train_bkw(num_layers: int) -> None:
     exp_dir = prep_exp_dir(directory=config.TEST_EXP_PATH)
     corp = bkw.create_corpus(tgt_dir=Path(config.TEST_DATA_PATH) / "bkw")
     cr = CorpusReader(corp)
     model = rnn_ctc.Model(exp_dir,
                           cr,
                           num_layers=num_layers,
                           hidden_size=250)
     model.train(min_epochs=40)
Beispiel #4
0
    def test_multispeaker(self, preprocessed_corpus):
        """ Trains a multispeaker BKW system using default settings. """

        exp_dir = prep_exp_dir(directory=config.TEST_EXP_PATH)
        # TODO bkw.Corpus and elan.Corpus should take an org_dir argument.
        corp = preprocessed_corpus
        cr = CorpusReader(corp)
        model = rnn_ctc.Model(exp_dir, cr, num_layers=2, hidden_size=250)
        model.train(min_epochs=30)