Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Levenshtein C module instead of custom cpp code #6

Open
BramVanroy opened this issue Aug 17, 2022 · 0 comments
Open

Using Levenshtein C module instead of custom cpp code #6

BramVanroy opened this issue Aug 17, 2022 · 0 comments

Comments

@BramVanroy
Copy link

BramVanroy commented Aug 17, 2022

The following line

result = self.ed_wrapper.wrapper(hyp_c, ref_c, len(hyp_c), len(ref_c), norm)

can be replaced by

Levenshtein.distance(hyp_c, ref_c) / norm

If the C extension module is installed (Levenshtein) this computation will be blazing fast and compatible with different platforms. Currently, how CharacTER is written with a precompiled SO, this is not the case.

Making the change suggested above will lead to better compatibility with close to zero performance loss due to the C implementation in Levenshtein. In fact, the whole EditDistance class seems unnecessary as pre_score can be replaced by a single line:

pre_score = Levenshtein.distance(hyp_words, ref_words) / len(ref_words)

I tested this with a large corpus and results were always the same as the current implementation.

@BramVanroy BramVanroy changed the title Why not just use Levenshtein instead of custom cpp code? Using Levenshtein C module instead of custom cpp code Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant