def words_to_word_ids(data=None, word_to_id=None, unk_key='<STR_LIT>'):
if data is None:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if word_to_id is None:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>word_ids = []<EOL>for word in data:<EOL><INDENT>if word_to_id.get(word) is not None:<EOL><INDENT>word_ids.append(word_to_id[word])<EOL><DEDENT>else:<EOL><INDENT>word_ids.append(word_to_id[unk_key])<EOL><DEDENT><DEDENT>return word_ids<EOL>
Convert a list of string (words) to IDs.

    Parameters
    ----------
    data : list of string or byte
        The context in list format
    word_to_id : a dictionary
        that maps word to ID.
    unk_key : str
        Represent the unknown words.

    Returns
    --------
    list of int
        A list of IDs to represent the context.

    Examples
    --------
    >>> words = tl.files.load_matt_mahoney_text8_dataset()
    >>> vocabulary_size = 50000
    >>> data, count, dictionary, reverse_dictionary = tl.nlp.build_words_dataset(words, vocabulary_size, True)
    >>> context = [b'hello', b'how', b'are', b'you']
    >>> ids = tl.nlp.words_to_word_ids(words, dictionary)
    >>> context = tl.nlp.word_ids_to_words(ids, reverse_dictionary)
    >>> print(ids)
    [6434, 311, 26, 207]
    >>> print(context)
    [b'hello', b'how', b'are', b'you']

    References
    ---------------
    - `tensorflow.models.rnn.ptb.reader <https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/rnn/ptb>`__