Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python NLTK align import error

I am getting a strange import error for NLTK's align module:

$ python2 --version
Python 2.7.10
$ pip2 freeze | grep nltk
nltk==3.2
$ python2
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> from nltk.align import AlignedSent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named align

As you can see, I have nltk 3.2 installed for python 2.7. I can import nltk directly. However, I cannot access the align module.

I know the import statement I used is correct, since I took it directly from the official documentation. Additionally, I looked at the interface changes from NLTK 2 to NLTK 3 and there is no mention there of the align module.


Why is this happening and what can I do to fix this?

like image 928
RandomGuyqwert Avatar asked Dec 24 '22 07:12

RandomGuyqwert


1 Answers

As of NLTK version 3.2, the align module has been renamed to translate. Therefore use:

from nltk.translate import AlignedSent
like image 178
unutbu Avatar answered Jan 06 '23 06:01

unutbu