def load_embed(file_name, vocab_size):
    'Loads a pre-trained embedding matrix.\n\n  Args:\n    file_name: the file name of the embedding file.\n    vocab_size: if > 0, only load embedding weights for vocab_size words.\n\n  Returns:\n    vocab: a list of tokens.\n    embeds: a numpy array of embeddings for each token plus an OOV embedding.\n    depth: the depth of the embedding.\n  Raises:\n    ValueError: embeddings have different depths.\n  '
    with tf.io.gfile.GFile(file_name, 'r') as embed_file:
        vocab = []
        embeds = []
        depth = (- 1)
        for (index, line) in enumerate(embed_file):
            if ((vocab_size > 0) and (index >= vocab_size)):
                break
            line = line.strip()
            tokens = line.strip().split(' ')
            word = tokens[0]
            vocab.append(word)
            if (depth == (- 1)):
                embed = [float(token) for token in tokens[1:]]
            else:
                embed = [float(token) for token in tokens[(- depth):]]
            d = len(embed)
            if (depth == (- 1)):
                depth = d
            if (d != depth):
                raise ValueError('Inconsistent embedding sizes')
            embeds.append(embed)
        embeds = np.stack(embeds)
    return (vocab, embeds, depth)
Loads a pre-trained embedding matrix.

Args:
  file_name: the file name of the embedding file.
  vocab_size: if > 0, only load embedding weights for vocab_size words.

Returns:
  vocab: a list of tokens.
  embeds: a numpy array of embeddings for each token plus an OOV embedding.
  depth: the depth of the embedding.
Raises:
  ValueError: embeddings have different depths.
def load_embed(file_name, vocab_size):
    'Loads a pre-trained embedding matrix.\n\n  Args:\n    file_name: the file name of the embedding file.\n    vocab_size: if > 0, only load embedding weights for vocab_size words.\n\n  Returns:\n    vocab: a list of tokens.\n    embeds: a numpy array of embeddings for each token plus an OOV embedding.\n    depth: the depth of the embedding.\n  Raises:\n    ValueError: embeddings have different depths.\n  '
    with tf.io.gfile.GFile(file_name, 'r') as embed_file:
        vocab = []
        embeds = []
        depth = (- 1)
        for (index, line) in enumerate(embed_file):
            if ((vocab_size > 0) and (index >= vocab_size)):
                break
            line = line.strip()
            tokens = line.strip().split(' ')
            word = tokens[0]
            vocab.append(word)
            if (depth == (- 1)):
                embed = [float(token) for token in tokens[1:]]
            else:
                embed = [float(token) for token in tokens[(- depth):]]
            d = len(embed)
            if (depth == (- 1)):
                depth = d
            if (d != depth):
                raise ValueError('Inconsistent embedding sizes')
            embeds.append(embed)
        embeds = np.stack(embeds)
    return (vocab, embeds, depth)