def _write_word_scores(vocabulary, words, logprobs, output_file, log_scale):
    """Writes word-level scores to an output file.

    :type vocabulary: Vocabulary
    :param vocabulary: vocabulary for printing information about which word are
                       predicted by the network

    :type words: list
    :param words: either word strings or one list for each word that contains
                  the subwords

    :type logprobs: list of floats
    :param logprobs: logprob of each word starting from the second word

    :type output_file: file object
    :param output_file: a file where to write the output

    :type log_scale: float
    :param log_scale: divide logprobs by this amount to convert to correct base
    """

    def word_info(vocabulary, word):
        """Returns information whether a word is in the vocabulary and in the
        shortlist.
        """
        if not word in vocabulary:
            return word + ':OOV'
        word_id = vocabulary.word_to_id[word]
        if vocabulary.in_shortlist(word_id):
            return word + ':shortlist'
        else:
            return word + ':OOS'

    if len(logprobs) != len(words) - 1:
        raise ValueError("Number of logprobs should be exactly one less than "
                         "the number of words.")

    logprobs = [None if x is None else x / log_scale for x in logprobs]
    for index, logprob in enumerate(logprobs):
        if index - 2 > 0:
            history_list = ['...']
            history_list.extend(words[index - 2:index + 1])
        else:
            history_list = words[:index + 1]
        history_list = [' '.join(word) if isinstance(word, list) else word
                        for word in history_list]
        history = ' '.join(history_list)

        predicted = words[index + 1]
        if isinstance(predicted, list):
            info = ' '.join(word_info(vocabulary, subword)
                            for subword in predicted)
            predicted = ' '.join(predicted)
        else:
            info = word_info(vocabulary, predicted)

        if logprob is None:
            output_file.write("p({0} | {1}) is not predicted  [{2}]\n".format(
                predicted, history, info))
        else:
            output_file.write("log(p({0} | {1})) = {2}  [{3}]\n".format(
                predicted, history, logprob, info))