code: def viterbi_alignment(es, fs, t, a):
      '''
      return
          dictionary
              e in es -> f in fs
      '''
      max_a = collections.defaultdict(float)
      l_e = len(es)
      l_f = len(fs)
      for (j, e) in enumerate(es, 1):
          current_max = (0, -1)
          for (i, f) in enumerate(fs, 1):
              val = t[(e, f)] * a[(i, j, l_e, l_f)]
              # select the first one among the maximum candidates
              if current_max[1] < val:
                  current_max = (i, val)
          max_a[j] = current_max[0]
      return max_f viterbi_alignment(es, fs, t, a):
      '''
      return
          dictionary
              e in es -> f in fs
      '''
      max_a = collections.defaultdict(float)
      l_e = len(es)
      l_f = len(fs)
      for (j, e) in enumerate(es, 1):
          current_max = (0, -1)
          for (i, f) in enumerate(fs, 1):
              val = t[(e, f)] * a[(i, j, l_e, l_f)]
              # select the first one among the maximum candidates
              if current_max[1] < val:
                  current_max = (i, val)
          max_a[j] = current_max[0]
      return max_a
docs: return
          dictionary
              e in es -> f in fs