How to use edist - 2 common examples

To help you get started, we’ve selected a few edist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / language-resources / utils / eval_lex.py View on Github external
assert prons
    stats.prons += len(prons)

    assert len(golden_lex[word]) >= 1

    # Compute stats for phone error rate and word error rate:
    argvals = []
    for predicted in prons[:predicted_cutoff]:
      predicted_pron = predicted[0]
      # Inner oracle: Find the best among the golden pronunciations.
      inner_argmin = None
      inner_valmin = _INF
      for golden in golden_lex[word][:golden_cutoff]:
        golden_pron = golden[0]
        ed = edist.EditDistance(golden_pron, predicted_pron,
                                edist.LevenshteinCost)
        val = fdiv(ed.Valmin(), len(golden_pron))  # Per-word phone error.
        if val < inner_valmin:
          inner_argmin = (golden, predicted, ed)
          inner_valmin = val
      assert inner_argmin is not None
      if FLAGS.output_word_stats:
        # Output phone error per predicted pronunciation.
        writer.write('#PRON_PhE\t%s\t%s\t%s\t%f\t%s\n' %
                     (word,
                      ' '.join(inner_argmin[0][0]),
                      ' '.join(predicted_pron),
                      inner_valmin,
                      '\t'.join(predicted[2])))
      argvals.append((inner_argmin, inner_valmin))
    assert argvals
github google / language-resources / utils / eval_lex.py View on Github external
assert prons
    stats.prons += len(prons)

    assert len(golden_lex[word]) >= 1

    # Compute stats for phone error rate and word error rate:
    argvals = []
    for predicted in prons[:predicted_cutoff]:
      predicted_pron = predicted[0]
      # Inner oracle: Find the best among the golden pronunciations.
      inner_argmin = None
      inner_valmin = _INF
      for golden in golden_lex[word][:golden_cutoff]:
        golden_pron = golden[0]
        ed = edist.EditDistance(golden_pron, predicted_pron,
                                edist.LevenshteinCost)
        val = fdiv(ed.Valmin(), len(golden_pron))  # Per-word phone error.
        if val < inner_valmin:
          inner_argmin = (golden, predicted, ed)
          inner_valmin = val
      assert inner_argmin is not None
      if FLAGS.output_word_stats:
        # Output phone error per predicted pronunciation.
        writer.write('#PRON_PhE\t%s\t%s\t%s\t%f\t%s\n' %
                     (word,
                      ' '.join(inner_argmin[0][0]),
                      ' '.join(predicted_pron),
                      inner_valmin,
                      '\t'.join(predicted[2])))
      argvals.append((inner_argmin, inner_valmin))
    assert argvals
    argvals.sort(key=lambda x: x[1])  # Sort by increasing values.

edist

Edit distance implementations in cython

GPL-3.0
Latest version published 9 months ago

Package Health Score

44 / 100
Full package analysis

Similar packages