def words_to_indices(sentence, worddict):
    """
    Transform the words in a sentence to integer indices.

    Args:
        sentence: A list of words that must be transformed to indices.
        worddict: A dictionary associating words to indices.

    Returns:
        A list of indices.
    """
    # Include the beggining of sentence token at the start of the sentence.
    indices = [worddict["_BOS_"]]
    for word in sentence:
        if word in worddict:
            index = worddict[word]
        else:
            # Words absent from 'worddict' are treated as a special
            # out-of-vocabulary word (OOV).
            index = worddict['_OOV_']
        indices.append(index)
    # Add the end of sentence token at the end of the sentence.
    indices.append(worddict["_EOS_"])

    return indices