def create_vocabulary(<EOL>vocabulary_path, data_path, max_vocabulary_size, tokenizer=None, normalize_digits=True,<EOL>_DIGIT_RE=re.compile(br"<STR_LIT>"), _START_VOCAB=None<EOL>):
if _START_VOCAB is None:<EOL><INDENT>_START_VOCAB = [b"<STR_LIT>", b"<STR_LIT>", b"<STR_LIT>", b"<STR_LIT>"]<EOL><DEDENT>if not gfile.Exists(vocabulary_path):<EOL><INDENT>tl.logging.info("<STR_LIT>" % (vocabulary_path, data_path))<EOL>vocab = {}<EOL>with gfile.GFile(data_path, mode="<STR_LIT:rb>") as f:<EOL><INDENT>counter = <NUM_LIT:0><EOL>for line in f:<EOL><INDENT>counter += <NUM_LIT:1><EOL>if counter % <NUM_LIT> == <NUM_LIT:0>:<EOL><INDENT>tl.logging.info("<STR_LIT>" % counter)<EOL><DEDENT>tokens = tokenizer(line) if tokenizer else basic_tokenizer(line)<EOL>for w in tokens:<EOL><INDENT>word = re.sub(_DIGIT_RE, b"<STR_LIT:0>", w) if normalize_digits else w<EOL>if word in vocab:<EOL><INDENT>vocab[word] += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>vocab[word] = <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>vocab_list = _START_VOCAB + sorted(vocab, key=vocab.get, reverse=True)<EOL>if len(vocab_list) > max_vocabulary_size:<EOL><INDENT>vocab_list = vocab_list[:max_vocabulary_size]<EOL><DEDENT>with gfile.GFile(vocabulary_path, mode="<STR_LIT:wb>") as vocab_file:<EOL><INDENT>for w in vocab_list:<EOL><INDENT>vocab_file.write(w + b"<STR_LIT:\n>")<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>tl.logging.info("<STR_LIT>" % (vocabulary_path, data_path))<EOL><DEDENT>
r"""Create vocabulary file (if it does not exist yet) from data file.

    Data file is assumed to contain one sentence per line. Each sentence is
    tokenized and digits are normalized (if normalize_digits is set).
    Vocabulary contains the most-frequent tokens up to max_vocabulary_size.
    We write it to vocabulary_path in a one-token-per-line format, so that later
    token in the first line gets id=0, second line gets id=1, and so on.

    Parameters
    -----------
    vocabulary_path : str
        Path where the vocabulary will be created.
    data_path : str
        Data file that will be used to create vocabulary.
    max_vocabulary_size : int
        Limit on the size of the created vocabulary.
    tokenizer : function
        A function to use to tokenize each data sentence. If None, basic_tokenizer will be used.
    normalize_digits : boolean
        If true, all digits are replaced by `0`.
    _DIGIT_RE : regular expression function
        Default is ``re.compile(br"\d")``.
    _START_VOCAB : list of str
        The pad, go, eos and unk token, default is ``[b"_PAD", b"_GO", b"_EOS", b"_UNK"]``.

    References
    ----------
    - Code from ``/tensorflow/models/rnn/translation/data_utils.py``