Catalogue of Tools & Metrics for Trustworthy AI

These tools and metrics are designed to help AI actors develop and use trustworthy AI systems and applications that respect human rights and are fair, transparent, explainable, robust, secure and safe.

17347 citations of this metric

The Levenshtein distance is a metric for quantifying the difference between two strings by counting the minimum number of single-character edits—insertions, deletions, or substitutions—required to transform one string into the other. For example, converting "kitten" to "sitting" involves three edits: substituting 'k' with 's', substituting 'e' with 'i', and inserting 'g' at the end.

Applicable Models: The Levenshtein distance is applicable to various models and systems, particularly in natural language processing (NLP) tasks, including spell checkers, text similarity assessments, and DNA sequence analyses.
 

Background: Introduced by Soviet mathematician Vladimir Levenshtein in 1965, this metric has become fundamental in computer science, linguistics, and bioinformatics for measuring textual similarity.

Formulae: The Levenshtein distance between two strings a and b is defined as lev(a, b), where:

  • If either string is empty, the distance is the length of the other string.
  • If the first characters of both strings are the same, they can be ignored, and the distance is lev(tail(a), tail(b)).
  • Otherwise, the distance is 1 plus the minimum of:
    • lev(tail(a), b) // Deletion
    • lev(a, tail(b)) // Insertion
    • lev(tail(a), tail(b)) // Substitution

Here, 'tail(x)' denotes the string x without its first character.

 

Applications:
 

  • Spell Checking: Suggesting corrections for misspelled words by finding the closest matches in a dictionary.
     
  • Data Cleaning: Identifying and merging similar records in datasets to reduce redundancy.
     
  • DNA Sequence Analysis: Comparing genetic sequences to identify mutations or evolutionary relationships.
     
  • Natural Language Processing: Assessing text similarity for tasks like plagiarism detection and machine translation.

     

Impact: Utilizing the Levenshtein distance enhances the accuracy of systems that rely on string comparison by providing a quantifiable measure of similarity. This leads to improved performance in applications such as spell checkers, search algorithms, and bioinformatics analyses, thereby contributing to more reliable and efficient technological solutions.

Trustworthy AI Relevance

This metric addresses Robustness and Explainability by quantifying relevant system properties. Robustness: Levenshtein Distance provides a quantitative, repeatable measure of how much a model's output changes under perturbations (noisy inputs, distribution shift, adversarial edits) or across generations, so it can detect and help quantify reliability and consistency issues. For example, measuring normalized edit distance between outputs on perturbed/clean inputs captures noise- or attack-induced degradation and helps compare model resilience.

References

  • Levenshtein, V. I. (1966). Binary codes capable of correcting deletions, insertions, and reversals. Soviet Physics Doklady.
  • Navarro, G. (2001). A guided tour to approximate string matching. ACM Computing Surveys.

About the metric


Metric type(s):








Risk management stage(s):


Github stars:

  • 400

Github forks:

  • 26

Modify this metric

Partnership on AI

Disclaimer: The tools and metrics featured herein are solely those of the originating authors and are not vetted or endorsed by the OECD or its member countries. The Organisation cannot be held responsible for possible issues resulting from the posting of links to third parties' tools and metrics on this catalogue. More on the methodology can be found at https://oecd.ai/catalogue/faq.