Python NLTK pos_tag throws a URLError

I tried to use the pos_tag function in NLTK 3 (on Windows), but this error appeared:

 >>> import nltk >>> tokens = nltk.word_tokenize("This is a sentence!") >>> tokens ['This', 'is', 'a', 'sentence', '!'] >>> tags = nltk.pos_tag(tokens) Traceback (most recent call last): File "<pyshell#24>", line 1, in <module> tags = nltk.pos_tag(tokens) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\tag\__init__.py", line 110, in pos_tag tagger = PerceptronTagger() File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\tag\perceptron.py", line 141, in __init__ self.load(AP_MODEL_LOC) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\tag\perceptron.py", line 209, in load self.model.weights, self.tagdict, self.classes = load(loc) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\data.py", line 801, in load opened_resource = _open(resource_url) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nltk\data.py", line 924, in _open return urlopen(resource_url) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 162, in urlopen return opener.open(url, data, timeout) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 465, in open response = self._open(req, data) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 488, in _open 'unknown_open', req) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 443, in _call_chain result = func(*args) File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 1310, in unknown_open raise URLError('unknown url type: %s' % type) urllib.error.URLError: <urlopen error unknown url type: c> 

All packages were installed successfully (including maxent_treebank_pos_tagger), and I also installed Numpy.

Am I doing something wrong?

+7
source share
1 answer

EDITED

This issue has been resolved with NLTK v3.2.1. Upgrading your NLTK will solve the problem, for example. pip install -U nltk .


Perhaps you are using nltk verion 3.2. Reduce it to version 3.1 and it will work fine. I myself used the method below and the URL error went away. There seems to be a problem with nltk_version-3.2

Go to this directory on your computer

 C:\Users\USERNAME\AppData\Local\Continuum\Anaconda2\Lib\site-packages OR C:\python2.7\site-packages\ 

Basically, the goal is to go to the directory of package sites where the installed packages are stored.

Search and delete these files and directories:

 nltk-3.1.dist-info nltk 

After removing the force, install an older version as: -

 pip install nltk==3.1 
+11
source share

All Articles