2011-12-21 16 views
27

Acabo de empezar a utilizar un etiquetador de voz parcial, y estoy enfrentando muchos problemas.¿Qué es el etiquetador NLTK POS pidiéndome que descargue?

empecé POS tagging con lo siguiente:

import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.") 

Cuando quiero imprimir 'text', ocurre lo siguiente:

print nltk.pos_tag(text) 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "F:\Python26\lib\site-packages\nltk\tag\__init__.py", line 63, in pos_tag 
tagger = nltk.data.load(_POS_TAGGER) 
File "F:\Python26\lib\site-packages\nltk\data.py", line 594, in load 
resource_val = pickle.load(_open(resource_url)) 
File "F:\Python26\lib\site-packages\nltk\data.py", line 673, in _open 
return find(path).open() 
File "F:\Python26\lib\site-packages\nltk\data.py", line 455, in find 
    raise LookupError(resource_not_found)` 
LookupError: 
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not 
found. Please use the NLTK Downloader to obtain the resource: 

>>> nltk.download(). 

Searched in: 
    - 'C:\\Documents and Settings\\Administrator/nltk_data' 
    - 'C:\\nltk_data' 
    - 'D:\\nltk_data' 
    - 'E:\\nltk_data' 
    - 'F:\\Python26\\nltk_data' 
    - 'F:\\Python26\\lib\\nltk_data' 
    - 'C:\\Documents and Settings\\Administrator\\Application Data\\nltk_data' 

que utilizan nltk.download() pero no funcionó.

+0

¿Por qué escribe todo su texto en negrita? Esto realmente no es necesario. Además, publique un ejemplo mínimo pero completo que demuestre su error. –

+0

Allí, lo limpié para ti. Por favor, tome esto como un ejemplo sobre cómo formatear las preguntas futuras. –

+0

thankx ... el problema ya está resuelto ... – Pearl

Respuesta

27

Cuando escribe nltk.download() en Python, se visualiza automáticamente una interfaz NLTK Downloader.
Haga clic en Modelos y elija maxent_treebank_pos_. Se instala automáticamente

import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.") 
print nltk.pos_tag(text) 
[('We', 'PRP'), ('are', 'VBP'), ('going', 'VBG'), ('out.Just', 'JJ'), 
('you', 'PRP'), ('and', 'CC'), ('me', 'PRP'), ('.', '.')] 
+16

Aún más, puede descargarlo directamente en el código si especifica el nombre del etiquetador 'nltk.download ('maxent_treebank_pos_tagger');'. Ver esta publicación http: // stackoverflow.com/a/5208563/62921 – ForceMagic

1
import nltk 
text = "Obama delivers his first speech." 

sent = nltk.sent_tokenize(text) 


loftags = [] 
for s in sent: 
    d = nltk.word_tokenize(s) 

    print nltk.pos_tag(d) 

Resultado:

akshayy @ ubuntu: ~/Summ $ pitón nn1.py [('Obama', 'PNN'), ('entrega', 'NNS'), ('su', 'PRP $'), ('primero', 'JJ'), ('discurso', 'NN'), (' ' '.')]

(Acabo de hacer otra pregunta donde usé este código)

+1

Vale la pena señalar que este análisis es ** incorrecto ** - el etiquetador POS ha marcado "entrega" como un sustantivo plural ... – simon

1
nltk.download() 

Haga clic en Modelos y elija maxent_treebank_pos_. Se instala automáticamente

import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.") 
print nltk.pos_tag(text) 
[('We', 'PRP'), ('are', 'VBP'), ('going', 'VBG'), ('out.Just', 'JJ'), 
('you', 'PRP'), ('and', 'CC'), ('me', 'PRP'), ('.', '.')] 
5

Desde el shell/terminal, puede utilizar:

python -m nltk.downloader maxent_treebank_pos_tagger 

(podría ser necesario sudo en Linux)

Se instalará maxent_treebank_pos_tagger (es decir, el etiquetador Treebank POS estándar en NLTK) y arregla tu problema.

21

De NLTK versiones superiores a v3.2, por favor utilice:

>>> import nltk 
>>> nltk.__version__ 
'3.2.1' 
>>> nltk.download('averaged_perceptron_tagger') 
[nltk_data] Downloading package averaged_perceptron_tagger to 
[nltk_data]  /home/alvas/nltk_data... 
[nltk_data] Package averaged_perceptron_tagger is already up-to-date! 
True 

Para NLTK versiones utilizando el antiguo modelo MaxEnt, es decir v3.1 y por debajo, por favor utilice:

>>> import nltk 
>>> nltk.download('maxent_treebank_pos_tagger') 
[nltk_data] Downloading package maxent_treebank_pos_tagger to 
[nltk_data]  /home/alvas/nltk_data... 
[nltk_data] Package maxent_treebank_pos_tagger is already up-to-date! 
True 

Para más detalles sobre el cambio en el valor predeterminado pos_tag, consulte https://github.com/nltk/nltk/pull/1143

Cuestiones relacionadas