jaclearn.embedding.embedding_utils#

Functions

init_random(elements_to_embed, embedding_size)

Initialize a random embedding matrix for a collection of elements.

make_element2idx(elements_to_embed[, ...])

Functions

init_random(elements_to_embed, embedding_size, add_all_zeros=False, add_unknown=False)[source]#

Initialize a random embedding matrix for a collection of elements. Elements are sorted in order to ensure the same mapping from indices to elements each time.

Parameters:
  • elements_to_embed – collection of elements to construct the embedding matrix for

  • embedding_size – size of the embedding

  • add_all_zeros – add a all_zero embedding at index 0

  • add_unknown – add unknown embedding at the last index

Returns:

an embedding matrix and a dictionary mapping elements to rows in the matrix

make_element2idx(elements_to_embed, add_all_zeros=False, add_unknown=False)[source]#