problem in the book

116 views
Skip to first unread message

WANG Wei

unread,
Apr 8, 2009, 6:21:36 AM4/8/09
to nltk...@googlegroups.com
Hello everyone,

I follow the command,
sent = nltk.corpus.treebank.tagged_sents()[22]
>>> print nltk.ne_chunk(sent, binary=True) [1]

but there is a error

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: ne_chunk() got an unexpected keyword argument 'binary'

CHeers,

--
Wei WANG
wei....@ensta.fr
ENSTA, ParisTech

anand j

unread,
Apr 8, 2009, 11:25:06 AM4/8/09
to nltk...@googlegroups.com
Hi wei,
         which version are you using?? what was your import??
I am using 0.9.8(if my memory is right.how do i check the version installed on my comp?)
 and for me the print nltk.ne_chunk throws the object ne_chunk not found error.......

==============================================
Anand J
Center for Behaviour and Cognitive Sciences
University of Allahabad
Allahabad-211002
http://cbcs.ac.in
==============================================
The man who is really serious,
with the urge to find out what truth is,
has no style at all. He lives only in what is.
                 ~Bruce Lee

WANG Wei

unread,
Apr 8, 2009, 11:52:35 AM4/8/09
to nltk...@googlegroups.com
Hi Anand,

I am using the same version, 0.9.8
import nltk
and then from nltk.book import *

Perhaps you didn't do the second import.

Cheers,

Wei

2009/4/8 anand j <anand....@gmail.com>:

anand j

unread,
Apr 8, 2009, 12:48:18 PM4/8/09
to nltk...@googlegroups.com
i hadn't done it true.......but this time did that too..
It might turn to be a different python version.........
I am using version 2.5.2..
attaching the screenshot..


==============================================
Anand J
Center for Behaviour and Cognitive Sciences
University of Allahabad
Allahabad-211002
http://cbcs.ac.in
==============================================
The man who is really serious,
with the urge to find out what truth is,
has no style at all. He lives only in what is.
                 ~Bruce Lee




nltk-error.JPG

Andrew Lee

unread,
Apr 8, 2009, 10:06:36 PM4/8/09
to nltk-dev
On Apr 8, 12:48 pm, anand j <anand.ibm...@gmail.com> wrote:
..
> > Hi Anand,
>
> > I am using the same version, 0.9.8
> > import nltk
> > and then from nltk.book import *
>
> > Perhaps you didn't do the second import.
>

don't use "binary"

from chunk/__init__.py:

line 171: def ne_chunk(tagged_tokens):

It does not take a named argument in 0.9.9b1, nor in 0.9.8

Also -- please use nltk-users for questions.

Cheers,

Andrew

WANG Wei

unread,
Apr 9, 2009, 3:02:52 AM4/9/09
to nltk...@googlegroups.com
Hi Andrew,

Sorry for the disturb to dev list again.

There is always a problem when I was trying to do this:

>>> sent = nltk.corpus.treebank.tagged_sents()[22]
>>> print nltk.ne_chunk(sent)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/nltk/chunk/__init__.py", line
177, in ne_chunk
return tagger.tag(tokens)
AttributeError: 'NEChunkParser' object has no attribute 'tag'

Cheers,

Wei

2009/4/9 Andrew Lee <fiacre....@gmail.com>:

Andrew Lee

unread,
Apr 9, 2009, 10:51:48 AM4/9/09
to nltk-dev
On Apr 9, 3:02 am, WANG Wei <wangwei...@gmail.com> wrote:
> Hi Andrew,
>
> Sorry for the disturb to dev list again.
>
> There is always a problem when I was trying to do this:
>
> >>> sent = nltk.corpus.treebank.tagged_sents()[22]
> >>> print nltk.ne_chunk(sent)
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/lib/python2.4/site-packages/nltk/chunk/__init__.py", line
> 177, in ne_chunk
>     return tagger.tag(tokens)
> AttributeError: 'NEChunkParser' object has no attribute 'tag'
>

It works for me with python 2.6.1 and nltk 0.9.9b1

Try it with the latest release of nltk. It seems like the book and
code are little out of synch, but that example works for me.

-- Andrew

Steven Bird

unread,
Apr 11, 2009, 2:38:00 AM4/11/09
to nltk-dev
2009/4/10 Andrew Lee <fiacre....@gmail.com>:

> It works for me with python 2.6.1 and nltk 0.9.9b1
>
> Try it with the latest release of nltk.  It seems like the book and
> code are little out of synch, but that example works for me.

Yes, they're slightly out of sync, sorry. I hoped to have 0.9.9 final
released before traveling to New Guinea for a field trip. It won't
happen until I get back at the end of the month, unless Edward has
time.

If anyone can hang out on nltk-users and answer questions there, it
would be much appreciated.

Thanks,
-Steven

Petro Verkhogliad

unread,
Apr 11, 2009, 3:01:39 AM4/11/09
to nltk...@googlegroups.com
Actually, I was wondering..

_NE_CHUNKER = 'chunkers/maxent_ne_chunker/english_ace.pickle'

How was this file generated? Is there a way to update the file with
the available NLTK code?

Petro

Andrew Lee

unread,
Apr 11, 2009, 4:55:38 PM4/11/09
to nltk-dev
On Apr 11, 3:01 am, Petro Verkhogliad <vpe...@gmail.com> wrote:
> Actually, I was wondering..
>
>  _NE_CHUNKER = 'chunkers/maxent_ne_chunker/english_ace.pickle'
>
> How was this file generated? Is there a way to update the file with
> the available NLTK code?
>
> Petro
>

I believe the data was from one of the sets here:

http://projects.ldc.upenn.edu/ace/data/

If you look at ne_chunker.py ??? (it was pasted as a example in the
users group) you can see that an sgml file is parsed -- several of the
ACE structured data files are used for training named entity
extractors.

english_ace.pickle is a trained entity extractor class that has been
pickled. The data isn't free, unfortunately.

:-(

-- Andrew

Petro Verkhogliad

unread,
Apr 11, 2009, 5:22:22 PM4/11/09
to nltk...@googlegroups.com

Hi,

I did take a look at the nltk/chunk/named_entity.py. That is what gave
rise to the question. I thought I might have been missing the data.
But since, as you pointed out, the data is not free, everything makes
sense.

Thanks,
Petro

Joel Nothman

unread,
Apr 11, 2009, 9:45:39 PM4/11/09
to nltk...@googlegroups.com

It may be worth having a machine somewhere with all the scripts and data
required to reproduce pickles so that we don't run into these versioning
problems...

- Joel



On Sun, 12 Apr 2009 07:22:22 +1000, Petro Verkhogliad <vpe...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages