class_docstr: Embedding class.
  
  Examples::
      >>> import matchzoo as mz
      >>> train_raw = mz.datasets.toy.load_data()
      >>> pp = mz.preprocessors.NaivePreprocessor()
      >>> train = pp.fit_transform(train_raw, verbose=0)
      >>> vocab_unit = mz.build_vocab_unit(train, verbose=0)
      >>> term_index = vocab_unit.state['term_index']
      >>> embed_path = mz.datasets.embeddings.EMBED_RANK
  
  To load from a file:
      >>> embedding = mz.embedding.load_from_file(embed_path)
      >>> matrix = embedding.build_matrix(term_index)
      >>> matrix.shape[0] == len(term_index)
      True
  
  To build your own:
      >>> data = pd.DataFrame(data=[[0, 1], [2, 3]], index=['A', 'B'])
      >>> embedding = mz.Embedding(data)
      >>> matrix = embedding.build_matrix({'A': 2, 'B': 1, '_PAD': 0})
      >>> matrix.shape == (3, 2)
      True
docstr: Build a matrix using `term_index`.
  
  :param term_index: A `dict` or `TermIndex` to build with.
  :param initializer: A callable that returns a default value for missing
      terms in data. (default: a random uniform distribution in range)
      `(-0.2, 0.2)`).
  :return: A matrix.
code: def build_matrix(
      self,
      term_index: typing.Union[
          dict, mz.preprocessors.units.Vocabulary.TermIndex
      ],
      initializer=lambda: np.random.uniform(-0.2, 0.2),
  ) -> np.ndarray:
      """
      Build a matrix using `term_index`.
  
      :param term_index: A `dict` or `TermIndex` to build with.
      :param initializer: A callable that returns a default value for missing
          terms in data. (default: a random uniform distribution in range)
          `(-0.2, 0.2)`).
      :return: A matrix.
      """
      input_dim = len(term_index)
  
      matrix = np.empty((input_dim, self.output_dim))
      for index in np.ndindex(*matrix.shape):
          matrix[index] = initializer()
  
      valid_keys = set(self._data.index)
      for term, index in term_index.items():
          if term in valid_keys:
              matrix[index] = self._data.loc[term]
  
      return matrix
  
file_path: MatchZoo/matchzoo/embedding/embedding.py
imports: import csv
  import typing
  import numpy
  import pandas
  import matchzoo
label_desc: Use image node_id 4 for calling the Embedding obj's underlying member method code with example usage: obj.build_matrix(term_index, initializer) and returns: matrix