class_docstr: Phrase-based stack decoder for machine translation
  
  >>> from nltk.translate import PhraseTable
  >>> phrase_table = PhraseTable()
  >>> phrase_table.add(('niemand',), ('nobody',), log(0.8))
  >>> phrase_table.add(('niemand',), ('no', 'one'), log(0.2))
  >>> phrase_table.add(('erwartet',), ('expects',), log(0.8))
  >>> phrase_table.add(('erwartet',), ('expecting',), log(0.2))
  >>> phrase_table.add(('niemand', 'erwartet'), ('one', 'does', 'not', 'expect'), log(0.1))
  >>> phrase_table.add(('die', 'spanische', 'inquisition'), ('the', 'spanish', 'inquisition'), log(0.8))
  >>> phrase_table.add(('!',), ('!',), log(0.8))
  
  >>> #  nltk.model should be used here once it is implemented
  >>> from collections import defaultdict
  >>> language_prob = defaultdict(lambda: -999.0)
  >>> language_prob[('nobody',)] = log(0.5)
  >>> language_prob[('expects',)] = log(0.4)
  >>> language_prob[('the', 'spanish', 'inquisition')] = log(0.2)
  >>> language_prob[('!',)] = log(0.1)
  >>> language_model = type('',(object,),{'probability_change': lambda self, context, phrase: language_prob[phrase], 'probability': lambda self, phrase: language_prob[phrase]})()
  
  >>> stack_decoder = StackDecoder(phrase_table, language_model)
  
  >>> stack_decoder.translate(['niemand', 'erwartet', 'die', 'spanische', 'inquisition', '!'])
  ['nobody', 'expects', 'the', 'spanish', 'inquisition', '!']
class_docstr_tok: ["Phrase-based","stack","decoder","for","machine","translation",">",">",">","from","nltk.translate","import","PhraseTable",">",">",">","phrase_table","=","PhraseTable","(",")",">",">",">","phrase_table.add","(","(","'niemand","'",",",")",",","(","'nobody","'",",",")",",","log","(","0.8",")",")",">",">",">","phrase_table.add","(","(","'niemand","'",",",")",",","(","'no","'",",","'one","'",")",",","log","(","0.2",")",")",">",">",">","phrase_table.add","(","(","'erwartet","'",",",")",",","(","'expects","'",",",")",",","log","(","0.8",")",")",">",">",">","phrase_table.add","(","(","'erwartet","'",",",")",",","(","'expecting","'",",",")",",","log","(","0.2",")",")",">",">",">","phrase_table.add","(","(","'niemand","'",",","'erwartet","'",")",",","(","'one","'",",","'does","'",",","'not","'",",","'expect","'",")",",","log","(","0.1",")",")",">",">",">","phrase_table.add","(","(","'die","'",",","'spanische","'",",","'inquisition","'",")",",","(","'the","'",",","'spanish","'",",","'inquisition","'",")",",","log","(","0.8",")",")",">",">",">","phrase_table.add","(","(","'","!","'",",",")",",","(","'","!","'",",",")",",","log","(","0.8",")",")",">",">",">","#","nltk.model","should","be","used","here","once","it","is","implemented",">",">",">","from","collections","import","defaultdict",">",">",">","language_prob","=","defaultdict","(","lambda",":","-999.0",")",">",">",">","language_prob","[","(","'nobody","'",",",")","]","=","log","(","0.5",")",">",">",">","language_prob","[","(","'expects","'",",",")","]","=","log","(","0.4",")",">",">",">","language_prob","[","(","'the","'",",","'spanish","'",",","'inquisition","'",")","]","=","log","(","0.2",")",">",">",">","language_prob","[","(","'","!","'",",",")","]","=","log","(","0.1",")",">",">",">","language_model","=","type","(","``",",","(","object",",",")",",","{","'probability_change","'",":","lambda","self",",","context",",","phrase",":","language_prob","[","phrase","]",",","'probability","'",":","lambda","self",",","phrase",":","language_prob","[","phrase","]","}",")","(",")",">",">",">","stack_decoder","=","StackDecoder","(","phrase_table",",","language_model",")",">",">",">","stack_decoder.translate","(","[","'niemand","'",",","'erwartet","'",",","'die","'",",","'spanische","'",",","'inquisition","'",",","'","!","'","]",")","[","'nobody","'",",","'expects","'",",","'the","'",",","'spanish","'",",","'inquisition","'",",","'","!","'","]"]
docstr: :param phrase_table: Table of translations for source language
      phrases and the log probabilities for those translations.
  :type phrase_table: PhraseTable
  
  :param language_model: Target language model. Must define a
      ``probability_change`` method that calculates the change in
      log probability of a sentence, if a given string is appended
      to it.
      This interface is experimental and will likely be replaced
      with nltk.model once it is implemented.
  :type language_model: object
docstr_tok: [":","param","phrase_table",":","Table","of","translations","for","source","language","phrases","and","the","log","probabilities","for","those","translations",".",":","type","phrase_table",":","PhraseTable",":","param","language_model",":","Target","language","model",".","Must","define","a","``","probability_change","``","method","that","calculates","the","change","in","log","probability","of","a","sentence",",","if","a","given","string","is","appended","to","it",".","This","interface","is","experimental","and","will","likely","be","replaced","with","nltk.model","once","it","is","implemented",".",":","type","language_model",":","object"]
code: def __init__(self, phrase_table, language_model):
      """
      :param phrase_table: Table of translations for source language
          phrases and the log probabilities for those translations.
      :type phrase_table: PhraseTable
  
      :param language_model: Target language model. Must define a
          ``probability_change`` method that calculates the change in
          log probability of a sentence, if a given string is appended
          to it.
          This interface is experimental and will likely be replaced
          with nltk.model once it is implemented.
      :type language_model: object
      """
      self.phrase_table = phrase_table
      self.language_model = language_model
  
      self.word_penalty = 0.0
      """
          float: Influences the translation length exponentially.
              If positive, shorter translations are preferred.
              If negative, longer translations are preferred.
              If zero, no penalty is applied.
          """
  
      self.beam_threshold = 0.0
      """
          float: Hypotheses that score below this factor of the best
              hypothesis in a stack are dropped from consideration.
              Value between 0.0 and 1.0.
          """
  
      self.stack_size = 100
      """
          int: Maximum number of hypotheses to consider in a stack.
              Higher values increase the likelihood of a good translation,
              but increases processing time.
          """
  
      self.__distortion_factor = 0.5
      self.__compute_log_distortion()
  
imports: import warnings
  from collections import defaultdict
  from math import log
label_desc: Use image node_id 1 to create a new StackDecoder object  with example: obj = StackDecoder(phrase_table, language_model)