def log_perplexity(sentences, hmm):
    """
    For a dataset of sentences (each sentence is a list of words)
        and an instance of the HMMLM class
        return the log perplexity as defined in Equation (12)
    """
    
    t = sum([len(s) + 2 for s in sentences])
    return -1.0 / t * sum([hmm.log_marginal(s) for s in sentences])