class_docstr: Hidden Markov model class, a generative model for labelling sequence data.
  These models define the joint probability of a sequence of symbols and
  their labels (state transitions) as the product of the starting state
  probability, the probability of each state transition, and the probability
  of each observation being generated from each state. This is described in
  more detail in the module documentation.
  
  This implementation is based on the HMM description in Chapter 8, Huang,
  Acero and Hon, Spoken Language Processing and includes an extension for
  training shallow HMM parsers or specialized HMMs as in Molina et.
  al, 2002.  A specialized HMM modifies training data by applying a
  specialization function to create a new training set that is more
  appropriate for sequential tagging with an HMM.  A typical use case is
  chunking.
  
  :param symbols: the set of output symbols (alphabet)
  :type symbols: seq of any
  :param states: a set of states representing state space
  :type states: seq of any
  :param transitions: transition probabilities; Pr(s_i | s_j) is the
      probability of transition from state i given the model is in
      state_j
  :type transitions: ConditionalProbDistI
  :param outputs: output probabilities; Pr(o_k | s_i) is the probability
      of emitting symbol k when entering state i
  :type outputs: ConditionalProbDistI
  :param priors: initial state distribution; Pr(s_i) is the probability
      of starting in state i
  :type priors: ProbDistI
  :param transform: an optional function for transforming training
      instances, defaults to the identity function.
  :type transform: callable
docstr: Returns the log-probability of the given symbol sequence. If the
  sequence is labelled, then returns the joint log-probability of the
  symbol, state sequence. Otherwise, uses the forward algorithm to find
  the log-probability over all label sequences.
  
  :return: the log-probability of the sequence
  :rtype: float
  :param sequence: the sequence of symbols which must contain the TEXT
      property, and optionally the TAG property
  :type sequence:  Token
docstr_tok: ["Returns","the","log-probability","of","the","given","symbol","sequence",".","If","the","sequence","is","labelled",",","then","returns","the","joint","log-probability","of","the","symbol",",","state","sequence",".","Otherwise",",","uses","the","forward","algorithm","to","find","the","log-probability","over","all","label","sequences",".",":","return",":","the","log-probability","of","the","sequence",":","rtype",":","float",":","param","sequence",":","the","sequence","of","symbols","which","must","contain","the","TEXT","property",",","and","optionally","the","TAG","property",":","type","sequence",":","Token"]
code: def log_probability(self, sequence):
      """
      Returns the log-probability of the given symbol sequence. If the
      sequence is labelled, then returns the joint log-probability of the
      symbol, state sequence. Otherwise, uses the forward algorithm to find
      the log-probability over all label sequences.
  
      :return: the log-probability of the sequence
      :rtype: float
      :param sequence: the sequence of symbols which must contain the TEXT
          property, and optionally the TAG property
      :type sequence:  Token
      """
      sequence = self._transform(sequence)
  
      T = len(sequence)
  
      if T > 0 and sequence[0][_TAG]:
          last_state = sequence[0][_TAG]
          p = self._priors.logprob(last_state) + self._output_logprob(
              last_state, sequence[0][_TEXT]
          )
          for t in range(1, T):
              state = sequence[t][_TAG]
              p += self._transitions[last_state].logprob(
                  state
              ) + self._output_logprob(state, sequence[t][_TEXT])
              last_state = state
          return p
      else:
          alpha = self._forward_probability(sequence)
          p = logsumexp2(alpha[T - 1])
          return p
  
imports: import itertools
  import re
  from nltk.metrics import accuracy
  from nltk.probability import ConditionalFreqDist, ConditionalProbDist, DictionaryConditionalProbDist, DictionaryProbDist, FreqDist, LidstoneProbDist, MLEProbDist, MutableProbDist, RandomProbDist
  from nltk.tag.api import TaggerI
  from nltk.util import LazyMap, unique_list
label_desc: Use image node_id 5 for calling the HiddenMarkovModelTagger obj's underlying member method code with example usage: obj.log_probability(sequence) and returns: p, p