1

I am using NLTK 3.2 and I was wondering how you save NLTK alignments. I have found this link: How to save Python NLTK alignment models for later use?, but it seems that there is no align() method. Also, I figured out that nltk.align has been renamed to nltk.translate, but I still cannot access the align() method. Thanks!

Community
  • 1
  • 1
andyph666
  • 23
  • 4
  • You have to use the IBM models now, see example on https://github.com/nltk/nltk/blob/develop/nltk/translate/ibm1.py#L70 – alvas Apr 18 '16 at 22:37

1 Answers1

0

Yeah, you are right. The method align became private in the current version. So, if you want to use that method, you have to modify the source code.

To modify the source code, you have to get to the directory of the file. You can find that directory by:

  1. Open your terminal
  2. Type these commands:

    >>> python

    >>> import nltk

    >>> nltk.translate.ibm1.__file__

Here is a screen-shot of what it should look like:

Now, you have to go to that directory and find the file 'ibm1.py'. Open the file and modify the method __align to align.

It's the last method in the file. enter image description here

CAUTION:

The align method returns Alignment class instead of AlignedSent in earlier versions.

Anwarvic
  • 12,156
  • 4
  • 49
  • 69