<commit_before>import pytest
import numpy as np

import matchzoo as mz


@pytest.fixture
def term_index_input():
    return {'G': 1, 'C': 2, 'D': 3, 'A': 4, '[PAD]': 0}


def test_embedding(term_index_input):
    embed = mz.datasets.toy.load_embedding()
    embed.build(term_index_input)
    assert embed.embedding_dim == 10
    assert embed.index_state == {4: 1, 2: 1, 3: 1, 1: 2, 0: 0}
    assert (embed.embedding_mat[0] == np.array([0] * 10)).all()
    assert (np.abs(embed.embedding_mat[2] - \
                   (np.array(range(10)) * 0.1 + 0.1)) < 1e-6).all()

    embed = mz.datasets.toy.load_embedding()
    embed.build(term_index_input)
    assert embed.embedding_dim == 10
    assert embed.index_state == {4: 1, 2: 1, 3: 1, 1: 2, 0: 0}
    assert (embed.embedding_mat[0] == np.array([0] * 10)).all()
    assert (np.abs(embed.embedding_mat[2] - \
                   (np.array(range(10)) * 0.1 + 0.1)) < 1e-6).all()

    embed = mz.datasets.toy.load_embedding()
    del term_index_input['[PAD]']
    embed.build(term_index_input)
    assert embed.embedding_dim == 10
    assert embed.index_state == {4: 1, 2: 1, 3: 1, 1: 2, 0: 0}
    assert (embed.embedding_mat[0] == np.array([0] * 10)).all()
    assert (np.abs(embed.embedding_mat[2] - \
                   (np.array(range(10)) * 0.1 + 0.1)) < 1e-6).all()<commit_msg>Update embedding test.<commit_after>import pytest

import matchzoo as mz


@pytest.fixture
def term_index():
    return {'G': 1, 'C': 2, 'D': 3, 'A': 4, '[PAD]': 0}


def test_embedding(term_index):
    embed = mz.embedding.load_from_file(mz.datasets.embeddings.EMBED_RANK)
    matrix = embed.build_matrix(term_index)
    assert matrix.shape == (len(term_index) + 1, 50)
{'fraction_non_alphanumeric': 0.17678255745433116, 'fraction_numerical': 0.05185621685327048, 'mean_word_length': 3.171990171990172, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7300096', 'n_tokens_mistral': 745, 'n_tokens_neox': 672, 'n_words': 144}