Error in nltk.tag.accuracy

553 views
Skip to first unread message

Richard Parker

unread,
Feb 14, 2016, 12:10:30 PM2/14/16
to nltk-users
Hi,

I was trying to implement the accuracy measure of NLTK tag,
print nltk.tag.accuracy(unigram_chunker, chunk_data)
it is giving me following error message,
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    print nltk.tag.accuracy(unigram_chunker, chunk_data)
AttributeError: 'module' object has no attribute 'accuracy'

I am using NLTK3.1
[>>> print('The nltk version is {}.'.format(nltk.__version__))
The nltk version is 3.1]
My Python version is Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32,
I am using Windows 10.

If any one may kindly suggest how may I fix this error.

Regards,
RP


Steven Bird

unread,
Feb 14, 2016, 6:20:46 PM2/14/16
to nltk-users
Please try:

from nltk.metrics import accuracy

And then just call:

print accuracy(unigram_chunker, chunk_data)



--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Parker

unread,
Feb 16, 2016, 9:21:23 PM2/16/16
to nltk-users
Dear Sir,

The unigram chunker module is generating some error, so I could not test it. 
But if you wrote it must be correct. I will check and get back to you in few days.

Regards,
RP.

Alexis

unread,
Feb 20, 2016, 8:40:25 AM2/20/16
to nltk-...@googlegroups.com
I think Steven must have confused the APIs for nltk.chunk.accuracy( ) and nltk.metrics.accuracy( ). The former is called with a chunker as its first argument, the second is called with two sets of tagged data. 

>>> help(nltk.metrics.accuracy)
accuracy(reference, test)
    Given a list of reference values and a corresponding list of test values, ...

Use `help()` to figure out which one is suited to your needs, and how to call it.

Alexis


Dr. Alexis Dimitriadis | Assistant Professor and Senior Research Fellow | Utrecht Institute of Linguistics OTS | Utrecht University | Trans 10, 3512 JK Utrecht, room 2.33 | +31 30 253 65 68 | a.dimi...@uu.nl | www.hum.uu.nl/medewerkers/a.dimitriadis

Jeff Silverman

unread,
Nov 19, 2016, 2:21:42 AM11/19/16
to nltk-users
Hello,

I am still having problems.  I am a bit of a newbie.

(Pdb) from nltk.metrics import accuracy
(Pdb) print (nltk.tag.accuracy.__doc__)
*** AttributeError: 'module' object has no attribute 'accuracy'
(Pdb) dir(accuracy)
['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
(Pdb) 
(Pdb)  print('The nltk version is {}.'.format(nltk.__version__))
The nltk version is 3.2.1.
(Pdb) import sys
(Pdb) print sys.version
2.7.12 (default, Sep 29 2016, 13:30:34) 
[GCC 6.2.1 20160916 (Red Hat 6.2.1-2)]
(Pdb) 


I am getting my instructions from how to train a nltk-chunker


Thank you

Jeff
Reply all
Reply to author
Forward
0 new messages