spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

💫 spaCy v2.0.0 alpha – details, feedback & questions (plus stickers!)

Open ines opened this issue 9 years ago • 109 comments

We're very excited to finally publish the first alpha pre-release of spaCy v2.0. It's still an early release and (obviously) not intended for production use. You might come across a NotImplementedError – see the release notes for the implementation details that are still missing.

This thread is intended for general discussion, feedback and all questions related to v2.0. If you come across more complex bugs, feel free to open a separate issue.

Quickstart & overview

The most important new features

  • New neural network models for English (15 MB) and multi-language NER (12 MB), plus GPU support via Chainer's CuPy.
  • Strings mapped to hash values instead of integer IDs. This means they will always match – even across models.
  • Improved saving and loading, consistent serialization API across objects, plus Pickle support.
  • Built-in displaCy visualizers with Jupyter notebook support.
  • Improved language data with support for lazy loading and multi-language models. Alpha tokenization for Norwegian Bokmål, Japanese, Danish and Polish. Lookup-based lemmatization for English, German, French, Spanish, Italian, Hungarian, Portuguese and Swedish.
  • Revised API for Matcher and language processing pipelines.
  • Trainable document vectors and contextual similarity via convolutional neural networks.
  • Various bug fixes and almost completely re-written documentation.

Installation

spaCy v2.0.0-alpha is available on pip as spacy-nightly. If you want to test the new version, we recommend setting up a clean environment first. To install the new model, you'll have to download it with its full name, using the --direct flag.

pip install spacy-nightly
python -m spacy download en_core_web_sm-2.0.0-alpha --direct   # English
python -m spacy download xx_ent_wiki_sm-2.0.0-alpha --direct   # Multi-language NER
import spacy
nlp = spacy.load('en_core_web_sm')
import en_core_web_sm
nlp = en_core_web_sm.load()

Alpha models for German, French and Spanish are coming soon!

Now on to the fun part – stickers!

stickers

We just got our first delivery of spaCy stickers and want to to share them with you! There's only one small favour we'd like to ask. The part we're currently behind on are the tests – this includes our test suite as well as in-depth testing of the new features and usage examples. So here's the idea:

  • Find something that's currently not covered in the test suite and doesn't require the models, and write a test for it - for example, language-specific tokenization tests.
  • Alternatively, find examples from the docs that haven't been added to the tests yet and add them. Plus points if the examples don't actually work – this means you've either discovered a bug in spaCy, or a bug in the docs! 🎉

Submit a PR with your test to the develop branch – if the test covers a bug and currently fails, mark it with @pytest.mark.xfail. For more info, see the test suite docs. Once your pull request is accepted, send us your address via email or private message on Gitter and we'll mail you stickers.

If you can't find anything, don't have time or can't be bothered, that's fine too. Posting your feedback on spaCy v2.0 here counts as well. To be honest, we really just want to mail out stickers 😉

ines avatar Jun 05 '17 19:06 ines

I honestly just wanted it to work :-)

I had spacy 1.5 installed on my other machine, I removed it and installed spacy-nightly v2.0.0a0. It works to import, but then tried to download with both:

python -m spacy download en
python -m spacy download en_core_web_sm

Both give:

Compatibility error
No compatible models found for v2.0.0a0 of spaCy.

It's most likely that I'm missing something?

EDIT: Indeed, on the release page it says: en_core_web_sm-2.0.0-alpha. You also need to give the --direct flag.

python -m spacy download en_core_web_sm-2.0.0-alpha --direct

Perhaps it is possible to temporarily update the docs for it?

Otherwise: it works!

kootenpv avatar Jun 05 '17 22:06 kootenpv

Sorry about that! We originally decided against adding the alpha models to the compatibility table and shortcuts just yet to avoid confusion – but maybe it actually ended up causing more confusion. Just added the models and shortcuts, so in about 5 minutes (which is roughly how long it takes GitHub to clear its cache for raw files), the following commands should work as well:

python -m spacy download en
python -m spacy download xx

ines avatar Jun 05 '17 22:06 ines

Another update: I tried parsing 16k headlines. I can parse all of them* and access some common attributes of each of them, including vectors :)

I did notice that on an empty string (1 of headlines*), it now throws an exception, this was not the case in v.18.2. Probably better to fix that :)

I wanted to do a benchmark against v.1.8.2, but the machines are not comparable :( It did feel a lot slower though...

kootenpv avatar Jun 05 '17 23:06 kootenpv

Thanks!

Try the doc.similarity() if you have a use-case for it? I'm not sure how well this works yet. It's using the tensors learned for the parser, NER and tagger (but no external data). It seems to have some interesting context sensitivity, and in theory it might give useful results --- but it hasn't been optimised for that. So, I'm curious to hear how it does.

http://alpha.spacy.io/docs/usage/word-vectors-similarities

honnibal avatar Jun 05 '17 23:06 honnibal

Hi, very excited about the new, better, smaller and potentially faster(?) spaCy 2.0. I hope to give it a try in the next days. Just one question. According to the (new) docs the embeddings seem to work just as they did before, i.e. external word vectors and their averages for spans and docs. But you also mention the use of tensors for similarity calculations. Is it correct that the vectors are essentially the same, but are not used as such in the similarity calculations anymore? Or are they somehow combined with the internal tensor representations of the documents? In any case thanks for the great work, and I hope to be able to give some useful feedback soon about the Spanish model etc.

buhrmann avatar Jun 06 '17 08:06 buhrmann

@buhrmann This is inherently a bit confusing, because there are two types of vector representations:

  1. You can import word vectors, as before. The assumption is you'll want to leave these static, with perhaps a trainable projection layer to reduce dimension

  2. The parser, NER, tagger etc learns a small embedding table and a depth-4 convolutional layer, to assign the document a tensor with a row for each token in context.

We're calling type 1 vector, and type 2 tensor. I've designed the neural network models to use a very small embedding table, shared between the parser, tagger and NER. I've also avoided using pre-trained vectors as features. I didn't want the models to depend on, say, the GloVe vectors, because I want to make sure you can load in any arbitrary word vectors without messing up the pipeline.

honnibal avatar Jun 06 '17 11:06 honnibal

Thanks, that's clear now. I still had doubts about how the (type 1) vectors and (type 2) tensors are used in similarity calculations, since you mention above the tensors could have interesting properties in this context (something I'm keen to try). I've cleared this up looking at the code and it seems that the tensors for now are only used in similarity calculations when there are no word vectors available (which of course could easily be changed with user hooks).

buhrmann avatar Jun 06 '17 11:06 buhrmann

Hi,

I wanted to do a quick benchmark between spaCy v1.8.2 and the v2.0.0. First of all, the memory usage is amazingly less in the new version! The old version's model took approximately 1GB memory, while the new one about 200MB.

However, I noticed that the latest release is using all 8 cores of my machine (100 % usage), but it is remarkably very, very slow!

I made two separate virtualenv to make sure the installation was clean. This is a small code I wrote to test it's speed -

import time
import spacy
nlp = spacy.load('en')

def do_lemma(text):
	doc = nlp(text.decode('utf-8'))
	lemma = []
	for token in doc:
		lemma.append(token.lemma_)
	return ' '.join(lemma)

def time_lemma():
	text = 'mangoes bought were nice this time'  # just a stupid sentence
	start = time.time()
	for i in range(1000):
		do_lemma(text)
	end = time.time()
	print end - start

time_lemma()

And for the latest release, same code only the model imports changed -


import time
import spacy
nlp = spacy.load('en_core_web_sm')

def do_lemma(text):
	doc = nlp(text.decode('utf-8'))
	lemma = []
	for token in doc:
		lemma.append(token.lemma_)
	return ' '.join(lemma)

def time_lemma():
	text = 'mangoes bought were nice this time'  # just a stupid sentence
	start = time.time()
	for i in range(1000):
		do_lemma(text)
	end = time.time()
	print end - start

time_lemma()

The first (v1.8.2) runs in 0.15 seconds while the latest (v2.0.0) took 11.77 seconds to run! Is there something I'm doing wrong in the way I'm using the new model?

unography avatar Jun 06 '17 13:06 unography

Hm! That's a lot worse than my tests, but in my tests I used the .pipe() method, which lets the model minibatch. This helps to mask the Python overhead a bit. I still think the result you're seeing is much slower than I expect though.

A thought: Could you try setting export OPENBLAS_NUM_THREADS=1 and trying again? If your machine has lots of cores, it could be that the stupid thing tries to load up like 40 threads to do this tiny amount of work per document, and that kills the performance.

honnibal avatar Jun 06 '17 13:06 honnibal

@honnibal Hi, setting export OPENBLAS_NUM_THREADS=1 surely helped! It avoided that 100% usage but it is still slower than the old guy. Now it takes about 4 seconds to run, way faster than before but still slow.

unography avatar Jun 06 '17 13:06 unography

I just finished reading documentation for v2.0 and it's way better than for v1.*.

But this export OPENBLAS_NUM_THREADS=1 looks new for me. I thought blas used by numpy only to train vectors. Could this be documented?

slavaGanzin avatar Jun 06 '17 14:06 slavaGanzin

@slavaGanzin The neural network model makes lots of calls to numpy.tensordot, which uses blas -- both for training and runtime. I'd like to have set this within the code --- even for my own usage I don't want to micromanage this stupid environment variable! The behaviour of "Spin up 40 threads to compute this tiny matrix multiplication" is one that nobody could want. So, we should figure out how to stop it from happening.

@eldor4do What happens if you use .pipe() as well?

honnibal avatar Jun 06 '17 15:06 honnibal

@honnibal I'll try with .pipe() once, but in my actual use case I won't be able to use pipe(), it would be more like repeated calls.

unography avatar Jun 06 '17 15:06 unography

Hopefully the ability to hold more workers in memory compensates a bit.

Btw, the changes to the StringStore are also very useful for multi-processing. The annotations from each worker are now easy to reconcile, because they're stored as hash IDs -- so the annotation encoding no longer depends on the worker's state.

honnibal avatar Jun 06 '17 15:06 honnibal

@honnibal Yes, that is a plus. Also, I tested the OPENBLAS value on 2 machines, on one it was able to reduce the threads, on the other, a 4 core machine, it failed to do so. Still all at 100% usage. Any idea what could be the problem?

unography avatar Jun 06 '17 16:06 unography

@eldor4do That's annoying. I think it depends on what BLAS numpy is linked to. Is the second machine a mac? If so the relevant library will be Accelerate, not openblas. Maybe there's a numpy API for limiting the thread count?

Appreciate the feedback -- this is good alpha testing :)

honnibal avatar Jun 06 '17 16:06 honnibal

@honnibal What are the expected differences for your test cases?

kootenpv avatar Jun 06 '17 16:06 kootenpv

#1021 is still an issue with this alpha release -- all of the sentences I gave as examples fail to be parsed correctly.

lake-hope avatar Jun 06 '17 17:06 lake-hope

I get some errors when I run this example from the documentation (https://alpha.spacy.io/docs/usage/lightning-tour#examples-tokens-sentences):

doc = nlp(u"Peach emoji is where it has always been. Peach is the superior "
          u"emoji. It's outranking eggplant 🍑 ")

assert doc[0].text == u'Peach'
assert doc[1].text == u'emoji'
assert doc[-1].text == u'🍑'
assert doc[17:19].text == u'outranking eggplant'
assert doc.noun_chunks[0].text == u'Peach emoji'

sentences = list(doc.sents)
assert len(sentences) == 3
assert sentences[0].text == u'Peach is the superior emoji.'

There are two problems

  1. This expresion doc.noun_chunks[0].text has error TypeError: 'generator' object is not subscriptable

  2. This expresion sentences[0].text returns 'Peach emoji is where it has always been.' and therefore the last assertion fails

I'm using python 3.6 (and spacy 2.0 alpha)

alfonsomhc avatar Jun 08 '17 11:06 alfonsomhc

I have also a problem with the example: https://alpha.spacy.io/docs/usage/lightning-tour#examples-pos-tags This statement fails: assert [apple.pos_, apple.pos] == [u'PROPN', 17049293600679659579] because [apple.pos_, apple.pos] returns ['PROPN', 95] The rest of the assertions are fine.

alfonsomhc avatar Jun 08 '17 13:06 alfonsomhc