Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add embeddings test #1

Open
mcollardanuy opened this issue Apr 5, 2023 · 0 comments
Open

Add embeddings test #1

mcollardanuy opened this issue Apr 5, 2023 · 0 comments

Comments

@mcollardanuy
Copy link
Collaborator

Test from other repository:

def test_compare_embeddings():
    """
    Compare our embeddings database with the old database.
    """

    # Test 1: Check old glove embedding is the same as new glove
    # embedding:
    mentions = ["apple"]
    embs = rel_utils.get_db_emb(
        "resources/rel_db/embedding_database.db", mentions, "snd"
    )
    with sqlite3.connect("resources/rel_db/generic/common_drawl.db") as conn2:
        c2 = conn2.cursor()
        result = c2.execute(
            "SELECT emb FROM embeddings WHERE word=?", ("apple",)
        ).fetchone()
        result = result if result is None else array("f", result[0]).tolist()

    assert embs[0] == result

    # Test 2: Check old glove embedding is different from new wiki2vec
    # word embedding:
    mentions = ["apple"]
    embs = rel_utils.get_db_emb(
        "resources/rel_db/embedding_database.db", mentions, "snd"
    )
    with sqlite3.connect("resources/rel_db/generic/entity_word_embedding.db") as conn2:
        c2 = conn2.cursor()
        result = c2.execute(
            "SELECT emb FROM embeddings WHERE word=?", ("apple",)
        ).fetchone()
        result = result if result is None else array("f", result[0]).tolist()

    assert embs[0] != result

    # Test 3: Check old wiki2vec word embedding is the same as new wiki2vec
    # word embedding:
    mentions = ["apple"]
    embs = rel_utils.get_db_emb(
        "resources/rel_db/embedding_database.db", mentions, "word"
    )
    with sqlite3.connect("resources/rel_db/generic/entity_word_embedding.db") as conn2:
        c2 = conn2.cursor()
        result = c2.execute(
            "SELECT emb FROM embeddings WHERE word=?", ("apple",)
        ).fetchone()
        result = result if result is None else array("f", result[0]).tolist()

    assert embs[0] == result

    # Test 4: Check old wiki2vec entity embedding is the same as new wiki2vec
    # entity embedding (old requires wikipedia input, new requires wikidata
    # input):
    mentions = ["Q84"]
    embs = rel_utils.get_db_emb(
        "resources/rel_db/embedding_database.db", mentions, "entity"
    )
    with sqlite3.connect("resources/rel_db/generic/entity_word_embedding.db") as conn2:
        c2 = conn2.cursor()
        result = c2.execute(
            "SELECT emb FROM embeddings WHERE word=?", ("ENTITY/London",)
        ).fetchone()
        result = result if result is None else array("f", result[0]).tolist()

    assert embs[0] == result

    # Test 5: Check old wiki2vec entity embedding is the same as new wiki2vec
    # entity embedding (old requires wikipedia input, new requires wikidata
    # input):
    mentions = ["Q84"]
    embs = rel_utils.get_db_emb(
        "resources/rel_db/embedding_database.db", mentions, "entity"
    )
    with sqlite3.connect("resources/rel_db/generic/entity_word_embedding.db") as conn2:
        c2 = conn2.cursor()
        result = c2.execute(
            "SELECT emb FROM embeddings WHERE word=?", ("London",)
        ).fetchone()
        result = result if result is None else array("f", result[0]).tolist()

    assert embs[0] != result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant