user1172502
user1172502

Reputation: 51

Using pre-trained MaltParser model with NLTK

Can anyone tell me how to use a pre-trained MaltParser model (http://maltparser.org/mco/english_parser/engmalt.html) in nltk.parse.malt? The only option seems to be to train from a file (If anyone could point me in the direction of a good, publicly available training file, that would be great, too).

Upvotes: 5

Views: 1880

Answers (2)

pflaquerre
pflaquerre

Reputation: 538

The MaltParser interface in older versions of NLTK used to hardcode the path to the model. This was fixed in commit e9e443. You can now do the following:

maltparser = MaltParser(mco="/path/to/your/model.mco")

As of this writing, easy_install and pip still install a version of NLTK that doesn't include this fix (2.0.1rc4). If you cannot afford switching to a bleeding edge version, you could use the following hack:

maltparser = MaltParser()
maltparser.mco = "/path/to/your/model.mco"

Pre-trained models can be found on MaltParser's official website.

Upvotes: 3

Gabis
Gabis

Reputation: 193


Regarding using pretrained model - It seems this has been (and it seems still to be) an open subject in the nltk dev forum: https://github.com/nltk/nltk/issues/145

From what I understand you can do it via setting some internal variable:

"And while you can manually set the mco field on the object, that's not exposed in the API, and a user who hasn't dug into the code wouldn't know that."

Yet I was unable to find the specific place to do this.

Regarding getting a pretrained model - I am referring you to this topic on SO:

Does NLTK have a tool for dependency parsing?

Upvotes: 1

Related Questions