Пространство: почему векторы не доступны при использовании трубы? - PullRequest
0 голосов
/ 11 января 2019

Это очень специфический вопрос для очень специфического случая в просторах. Я надеюсь, что Stackoverflow - все еще правильное место, чтобы спросить это.

Кажется, что есть разница в результатах при использовании nlp.pipe(docs) против nlp(doc). Когда я использую первое вместо второго, я не получаю векторы при определенных обстоятельствах. Вот что я заметил:

  • При использовании модели по умолчанию (en_core_web_sm) с отключенными тэгером и анализатором, я получаю векторы слов с nlp(doc), но не с nlp.pipe(docs)
  • Большие модели, т.е. en_core_web_lg, генерируют векторы в обоих случаях
  • Повторное включение тегера также «исправляет» это для моделей по умолчанию
  • Помимо векторов, отключение тэгера и парсера, кажется, работает как и ожидалось в обоих случаях

Может кто-нибудь объяснить это мне? Особенно, почему теггер, кажется, влияет на это?

Код:

import spacy


documents = [
    "spaCy is a free, open-source library for advanced Natural Language Processing (NLP) in Python.",
    "If you're working with a lot of text, you'll eventually want to know more about it. For example, what's it about? What do the words mean in context? Who is doing what to whom? What companies and products are mentioned? Which texts are similar to each other?",
    "spaCy is designed specifically for production use and helps you build applications that process and \"understand\" large volumes of text. It can be used to build information extraction or natural language understanding systems, or to pre-process text for deep learning."
]

nlp = spacy.load('en', disable=['tagger', 'parser'])
print('classic model, disabled tagger and parser, without pipe')
for i, doc in enumerate(documents):
    spacy_doc = nlp(doc)
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')

print('classic model, disabled tagger and parser, with pipe')
for i, spacy_doc in enumerate(nlp.pipe(documents)):
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')

nlp = spacy.load('en', disable=['parser'])
print('classic model, disabled only parser, without pipe')
for i, doc in enumerate(documents):
    spacy_doc = nlp(doc)
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')

print('classic model, disabled only parser, with pipe')
for i, spacy_doc in enumerate(nlp.pipe(documents)):
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')

nlp = spacy.load('en', disable=['tagger'])
print('classic model, disabled only tagger, without pipe')
for i, doc in enumerate(documents):
    spacy_doc = nlp(doc)
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')

print('classic model, disabled only tagger, with pipe')
for i, spacy_doc in enumerate(nlp.pipe(documents)):
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')


nlp = spacy.load('en_core_web_lg', disable=['tagger', 'parser'])
print('model en_core_web_lg, disabled tagger and parser, with pipe')
for i, spacy_doc in enumerate(nlp.pipe(documents)):
    print(f'document {i} has_vector: {spacy_doc.has_vector}, is_parsed: {spacy_doc.is_parsed}, token_0_pos: {spacy_doc[0].pos_}')

Выход:

classic model, disabled tagger and parser, without pipe
document 0 has_vector: True, is_parsed: False, token_0_pos: 
document 1 has_vector: True, is_parsed: False, token_0_pos: 
document 2 has_vector: True, is_parsed: False, token_0_pos: 
classic model, disabled tagger and parser, with pipe
document 0 has_vector: False, is_parsed: False, token_0_pos: 
document 1 has_vector: False, is_parsed: False, token_0_pos: 
document 2 has_vector: False, is_parsed: False, token_0_pos: 
classic model, disabled only parser, without pipe
document 0 has_vector: True, is_parsed: False, token_0_pos: ADJ
document 1 has_vector: True, is_parsed: False, token_0_pos: ADP
document 2 has_vector: True, is_parsed: False, token_0_pos: ADJ
classic model, disabled only parser, with pipe
document 0 has_vector: True, is_parsed: False, token_0_pos: ADJ
document 1 has_vector: True, is_parsed: False, token_0_pos: ADP
document 2 has_vector: True, is_parsed: False, token_0_pos: ADJ
classic model, disabled only tagger, without pipe
document 0 has_vector: True, is_parsed: True, token_0_pos: 
document 1 has_vector: True, is_parsed: True, token_0_pos: 
document 2 has_vector: True, is_parsed: True, token_0_pos: 
classic model, disabled only tagger, with pipe
document 0 has_vector: False, is_parsed: True, token_0_pos: 
document 1 has_vector: False, is_parsed: True, token_0_pos: 
document 2 has_vector: False, is_parsed: True, token_0_pos: 
model en_core_web_lg, disabled tagger and parser, with pipe
document 0 has_vector: True, is_parsed: False, token_0_pos: 
document 1 has_vector: True, is_parsed: False, token_0_pos: 
document 2 has_vector: True, is_parsed: False, token_0_pos:
...