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 src_sentence: Sentence to be translated
  :type src_sentence: list(str)
  
  :return: Translated sentence
  :rtype: list(str)
docstr_tok: [":","param","src_sentence",":","Sentence","to","be","translated",":","type","src_sentence",":","list","(","str",")",":","return",":","Translated","sentence",":","rtype",":","list","(","str",")"]
code: def translate(self, src_sentence):
      """
      :param src_sentence: Sentence to be translated
      :type src_sentence: list(str)
  
      :return: Translated sentence
      :rtype: list(str)
      """
      sentence = tuple(src_sentence)  # prevent accidental modification
      sentence_length = len(sentence)
      stacks = [
          _Stack(self.stack_size, self.beam_threshold)
          for _ in range(0, sentence_length + 1)
      ]
      empty_hypothesis = _Hypothesis()
      stacks[0].push(empty_hypothesis)
  
      all_phrases = self.find_all_src_phrases(sentence)
      future_score_table = self.compute_future_scores(sentence)
      for stack in stacks:
          for hypothesis in stack:
              possible_expansions = StackDecoder.valid_phrases(
                  all_phrases, hypothesis
              )
              for src_phrase_span in possible_expansions:
                  src_phrase = sentence[
                      src_phrase_span[0] : src_phrase_span[1]
                  ]
                  for (
                      translation_option
                  ) in self.phrase_table.translations_for(src_phrase):
                      raw_score = self.expansion_score(
                          hypothesis,
                          translation_option,
                          src_phrase_span,
                      )
                      new_hypothesis = _Hypothesis(
                          raw_score=raw_score,
                          src_phrase_span=src_phrase_span,
                          trg_phrase=translation_option.trg_phrase,
                          previous=hypothesis,
                      )
                      new_hypothesis.future_score = self.future_score(
                          new_hypothesis,
                          future_score_table,
                          sentence_length,
                      )
                      total_words = (
                          new_hypothesis.total_translated_words()
                      )
                      stacks[total_words].push(new_hypothesis)
  
      if not stacks[sentence_length]:
          warnings.warn(
              "Unable to translate all words. "
              "The source sentence contains words not in "
              "the phrase table"
          )
          # Instead of returning empty output, perhaps a partial
          # translation could be returned
          return []
  
      best_hypothesis = stacks[sentence_length].best()
      return best_hypothesis.translation_so_far()
  
imports: import warnings
  from collections import defaultdict
  from math import log
label_desc: Use image node_id 5 for calling the StackDecoder obj's underlying member method code with example usage: obj.translate(src_sentence) and returns: best_hypothesis, list