def p_word_given_topic(topic_word_counts,
                       topic_counts,
                       word,
                       topic,
                       W,
                       beta=0.1):
    """the fraction of words assigned to topic
    that equal word (plus some smoothing)"""
    return ((topic_word_counts[topic][word] + beta) /
            (topic_counts[topic] + W * beta))