-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Missing modules from nltk.metrics in Python 3.5 ?? #1516
Comments
Please use this idiom instead of from nltk.metrics import edit_distance The explanation can be found on http://stackoverflow.com/questions/33398282/attributeerror-module-object-has-no-attribute-scores >>> import inspect
>>> from nltk.metrics import edit_distance
>>> print inspect.getdoc(edit_distance)
Calculate the Levenshtein edit-distance between two strings.
The edit distance is the number of characters that need to be
substituted, inserted, or deleted, to transform s1 into s2. For
example, transforming "rain" to "shine" requires three steps,
consisting of two substitutions and one insertion:
"rain" -> "sain" -> "shin" -> "shine". These operations could have
been done in other orders, but at least three steps are needed.
This also optionally allows transposition edits (e.g., "ab" -> "ba"),
though this is disabled by default.
:param s1, s2: The strings to be analysed
:param transpositions: Whether to allow transposition edits
:type s1: str
:type s2: str
:type transpositions: bool
:rtype int |
wonderful, thanks :) |
Thanks, this works fine for me for chrf_score. But, unfortunately, it does not work for meteor_score gives:
Anyone with a hint on how to import meteor_score from nltk? |
@VincentCCL Hello! As can be seen here: nltk/nltk/translate/__init__.py Line 23 in 220920c
This function is likely meant to be imported as from nltk.translate import meteor The same goes for chrf: from nltk.translate import chrf
However, I can't promise this'll work for you, as I cannot reproduce your issue to begin with.
If this fails, you might try updating your nltk version and retrying these steps. Good luck! |
I tried in on Google Colab: I first do:
Same for This should give me the most recent version of nltk, no? |
@VincentCCL Ah, yes. That link is useful. It tells me that the the version of nltk that's installed is 3.2.5. (This can be seen in the first line after Version 3.2.5 dates to 24 Sep 2017. Lines 52 to 55 in ca357e5
The meteor score was only added in version 3.4.1, dating to 2019-04-17. So, you cannot import this file because this file does not exist in the nltk version that you have installed.
Good luck! |
That solves it -- thanks a lot! |
Hey, I'm trying to compute
nltk.metrics.distance.edit_distance
in v3.5, but I'm seeing "module 'nltk.translate.metrics' has no attribute 'distance'"
Can you help?
Thx!
The text was updated successfully, but these errors were encountered: