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: Extract phrases from ``all_phrases_from`` that contains words
  that have not been translated by ``hypothesis``
  
  :param all_phrases_from: Phrases represented by their spans, in
      the same format as the return value of
      ``find_all_src_phrases``
  :type all_phrases_from: list(list(int))
  
  :type hypothesis: _Hypothesis
  
  :return: A list of phrases, represented by their spans, that
      cover untranslated positions.
  :rtype: list(tuple(int, int))
docstr_tok: ["Extract","phrases","from","``","all_phrases_from","``","that","contains","words","that","have","not","been","translated","by","``","hypothesis","``",":","param","all_phrases_from",":","Phrases","represented","by","their","spans",",","in","the","same","format","as","the","return","value","of","``","find_all_src_phrases","``",":","type","all_phrases_from",":","list","(","list","(","int",")",")",":","type","hypothesis",":","_Hypothesis",":","return",":","A","list","of","phrases",",","represented","by","their","spans",",","that","cover","untranslated","positions",".",":","rtype",":","list","(","tuple","(","int",",","int",")",")"]
code: def valid_phrases(all_phrases_from, hypothesis):
      """
      Extract phrases from ``all_phrases_from`` that contains words
      that have not been translated by ``hypothesis``
  
      :param all_phrases_from: Phrases represented by their spans, in
          the same format as the return value of
          ``find_all_src_phrases``
      :type all_phrases_from: list(list(int))
  
      :type hypothesis: _Hypothesis
  
      :return: A list of phrases, represented by their spans, that
          cover untranslated positions.
      :rtype: list(tuple(int, int))
      """
      untranslated_spans = hypothesis.untranslated_spans(
          len(all_phrases_from)
      )
      valid_phrases = []
      for available_span in untranslated_spans:
          start = available_span[0]
          available_end = available_span[1]
          while start < available_end:
              for phrase_end in all_phrases_from[start]:
                  if phrase_end > available_end:
                      # Subsequent elements in all_phrases_from[start]
                      # will also be > available_end, since the
                      # elements are in ascending order
                      break
                  valid_phrases.append((start, phrase_end))
              start += 1
      return valid_phrases
  
imports: import warnings
  from collections import defaultdict
  from math import log
label_desc: Use image node_id 11 for calling the StackDecoder obj's underlying member method code with example usage: obj.valid_phrases(all_phrases_from, hypothesis) and returns: valid_phrases