def __init__(self,
               embeddings_path,
               max_vocab_size,
               num_oov_buckets=1,
               lowercase=False,
               vocab_path=None,
               skip_header=False):
    """Read and store embeddings for a text file up to a maximum number.

    Args:
      embeddings_path: String for path to where the pretrained embeddings are
          stored. The file should be in the typical GloVe format, e.g. lines
          each containing "word 0.1 -0.2 1.5" for pretrained embeddings of
          length 3.
      max_vocab_size: Integer indicating the maximum vocabulary size. This is
          most effective when the embeddings are sorted by frequency, making
          later embeddings more reasonable to truncate.
      num_oov_buckets: Integer indicating the number of OOV buckets. If this is
          one, then the OOV bucket will be set to a zero vector. If this is
          greater than one, then each OOV bucket is randomly sampled from a
          normal distribution.
      lowercase: Boolean indicating whether embeddings shouled be lowercased. In
          the case of duplicates due to lower casing, we use the first one.
      vocab_path: String for path to an optional vocabulary file. If provided,
          loads embeddings only from the vocabulary. Otherwise, loads
          `max_vocab_size` embeddings from the embeddings file in order.
      skip_header: Boolean indicating whether the first line is a header that
          should be skipped.

    Raises:
      ValueError: If embeddings_path does not contain any embeddings or
        max_vocab_size is 0.
    """
    self._idx2str = []
    self._idx2emb = []
    self._dims = None

    provided_vocab = set()
    if vocab_path is not None:
      tf.logging.info("Vocabulary was provided. Loading from %s...", vocab_path)
      with tf.gfile.Open(vocab_path) as vocab_file:
        for line in vocab_file:
          splits = line.strip().split(" ")
          word = splits[0]
          if lowercase:
            word = word.lower()
          provided_vocab.add(word)

    tf.logging.info("Loading embeddings from %s...", embeddings_path)

    vocab = set()
    with tf.gfile.Open(embeddings_path) as embeddings_file:
      for i, line in enumerate(embeddings_file):
        if max_vocab_size is not None and len(vocab) >= max_vocab_size:
          break
        if i == 0 and skip_header:
          continue
        word_end_ix = line.find(" ")
        word = line[:word_end_ix]

        if lowercase:
          word = word.lower()
        if (word in vocab) or (provided_vocab and word not in provided_vocab):
          continue
        else:
          vocab.add(word)

        self._idx2str.append(word)

        word_emb = np.fromstring(line[word_end_ix+1:], np.float32, sep=" ")
        word_emb = l2_normalize(word_emb)
        if self._dims is not None:
          assert self._dims == len(word_emb)
        else:
          self._dims = len(word_emb)
        self._idx2emb.append(word_emb)

    tf.logging.info("Loaded %d embeddings.", len(self._idx2emb))
    if self._dims is None:
      raise ValueError("No embeddings found.")

    self._num_oov_buckets = num_oov_buckets

    if num_oov_buckets == 1:
      self._idx2emb.append(np.zeros([self._dims], dtype=np.float32))
    else:
      for _ in range(self._num_oov_buckets):
        self._idx2emb.append(l2_normalize(np.random.normal(size=(self._dims))))

    self._idx2str = np.array(self._idx2str)
    self._idx2emb = np.array(self._idx2emb, dtype=np.float32)
Read and store embeddings for a text file up to a maximum number.

    Args:
      embeddings_path: String for path to where the pretrained embeddings are
          stored. The file should be in the typical GloVe format, e.g. lines
          each containing "word 0.1 -0.2 1.5" for pretrained embeddings of
          length 3.
      max_vocab_size: Integer indicating the maximum vocabulary size. This is
          most effective when the embeddings are sorted by frequency, making
          later embeddings more reasonable to truncate.
      num_oov_buckets: Integer indicating the number of OOV buckets. If this is
          one, then the OOV bucket will be set to a zero vector. If this is
          greater than one, then each OOV bucket is randomly sampled from a
          normal distribution.
      lowercase: Boolean indicating whether embeddings shouled be lowercased. In
          the case of duplicates due to lower casing, we use the first one.
      vocab_path: String for path to an optional vocabulary file. If provided,
          loads embeddings only from the vocabulary. Otherwise, loads
          `max_vocab_size` embeddings from the embeddings file in order.
      skip_header: Boolean indicating whether the first line is a header that
          should be skipped.

    Raises:
      ValueError: If embeddings_path does not contain any embeddings or
        max_vocab_size is 0.
    
language/common/inputs/embedding_utils.py