Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2.1] TextCategorizer fails at inference time because of 'drop' being None #2684

Closed
thomasopsomer opened this issue Aug 19, 2018 · 3 comments
Labels
bug Bugs and behaviour differing from documentation feat / textcat Feature: Text Classifier 🌙 nightly Discussion and contributions related to nightly builds

Comments

@thomasopsomer
Copy link
Contributor

How to reproduce the behaviour

Hi,

I just tried the new pre release of spacy 2.1, and there is an issue with the TextCategorizer at inference time. The problem is that the drop parameter being None in the forward pass break the concatenate_lists function. To reproduce:

import spacy
from spacy.pipeline import TextCategorizer
from spacy.gold import GoldParse

nlp = spacy.load("en_core_web_md")
textcat = TextCategorizer(nlp.vocab, pretrained_dims=300)

for label in ["cat_1", "cat_2", "cat_3"]:
    textcat.add_label(label)

nlp.add_pipe(textcat)

doc = nlp.tokenizer("Apple builds Iphones.")
cats = {"cat_1": True, "cat_2": False, "cat_3": True}
gold = GoldParse(doc, cats=cats)
with nlp.disable_pipes(*["ner", "tagger", "parser"]):
    optimizer = nlp.begin_training()
    losses = {}
    nlp.update([doc], [gold], sgd=optimizer, drop=0.2, losses=losses)

# inference
nlp("Apple builds Iphones.").cats

it results in:

  File "/Users/thomasopsomer/Envs/spacy-nightly/lib/python3.6/site-packages/thinc/api.py", line 61, in begin_update
    X, inc_layer_grad = layer.begin_update(X, drop=drop)
  File "<stdin>", line 15, in concatenate_lists_fwd
TypeError: unsupported operand type(s) for *=: 'NoneType' and 'float'

And just a comment on the textcat, it's a bit strange that the pretrained vectors are not used by default when available.

btw speed improvement in v2.1 are awesome :) about 30% !

Your Environment

  • spaCy version: 2.1.0a1
  • Platform: Darwin-16.7.0-x86_64-i386-64bit
  • Python version: 3.6.2
  • Models: en, en_core_web_md
@thomasopsomer thomasopsomer changed the title [v2.1] TextCategorizer fail at inference time because of 'drop' being None [v2.1] TextCategorizer fails at inference time because of 'drop' being None Aug 19, 2018
@honnibal honnibal added the bug Bugs and behaviour differing from documentation label Aug 22, 2018
@honnibal
Copy link
Member

Thanks. That's two bugs, really --- we should be using the vectors if they're available by default.

@honnibal honnibal added 🌙 nightly Discussion and contributions related to nightly builds feat / textcat Feature: Text Classifier labels Aug 22, 2018
@honnibal
Copy link
Member

Both should be fixed now.

@lock
Copy link

lock bot commented Jan 9, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs and behaviour differing from documentation feat / textcat Feature: Text Classifier 🌙 nightly Discussion and contributions related to nightly builds
Projects
None yet
Development

No branches or pull requests

2 participants