def test_create_visualization_matrix(monkeypatch, tmpdir):
    pipeline_config = {
        "maxqlen": 5,
        "passagelen": 3,
        "slicelen": 20,
        "tfchannel": True
    }
    extractor = DeepTileExtractor(tmpdir, tmpdir, pipeline_config)
    extractor.stoi = {
        "<pad>": 0,
        "hello": 1,
        "world": 2,
        "foo": 3,
        "bar": 4,
        "alice": 5,
        "bob": 6
    }
    extractor.idf = defaultdict(lambda: 0)

    def fake_magnitude_embedding(*args, **kwargs):
        return Magnitude(None)

    monkeypatch.setattr(extractor, "get_magnitude_embeddings",
                        fake_magnitude_embedding)
    embeddings_matrix = extractor.create_embedding_matrix("glove6b.50d")
    level = extractor.create_visualization_matrix(
        [
            "hello", extractor.pad_tok, extractor.pad_tok, extractor.pad_tok,
            extractor.pad_tok
        ],
        ["hello world", "foo bar", "alice bob"],
        embeddings_matrix,
    )
    assert level.shape == (1, 5, 3, 3)
Beispiel #2
0
def test_deeptiles_create_visualization_matrix(monkeypatch, tmpdir,
                                               dummy_index):
    def fake_magnitude_embedding(*args, **kwargs):
        return Magnitude(None)

    monkeypatch.setattr(DeepTileExtractor, "_get_pretrained_emb",
                        fake_magnitude_embedding)
    benchmark = DummyBenchmark()
    pipeline_config = {
        "name": "deeptiles",
        "tilechannels": 3,
        "maxqlen": 5,
        "passagelen": 3,
        "slicelen": 20,
        "tfchannel": True
    }
    extractor = DeepTileExtractor(pipeline_config,
                                  provide={
                                      "index": dummy_index,
                                      "benchmark": benchmark
                                  })
    extractor.stoi = {
        "<pad>": 0,
        "hello": 1,
        "world": 2,
        "foo": 3,
        "bar": 4,
        "alice": 5,
        "bob": 6
    }
    extractor.idf = defaultdict(lambda: 0)

    extractor._build_embedding_matrix()
    embeddings_matrix = extractor.embeddings
    level = extractor.create_visualization_matrix(
        [
            "hello", extractor.pad_tok, extractor.pad_tok, extractor.pad_tok,
            extractor.pad_tok
        ],
        ["hello world", "foo bar", "alice bob"],
        embeddings_matrix,
    )
    assert level.shape == (1, 5, 3, 3)