Closed debraj135 closed 3 years ago
Hi @debraj135, Thank you for opening the issue. It is not the expected behaviour. There was a little bug. It should now work as expected. Please install the updated v0.4.1
Best, Martino
Thank you, this works now. I believe I have encountered another issue outlined in this snippet
>>> import spacy
>>> nlp = spacy.load('en_core_web_lg')
>>> nlp.add_pipe('universal_sentence_encoder')
<spacy_universal_sentence_encoder.language.UniversalSentenceEncoder object at 0x1f65fc080>
>>> doc = nlp('Hi there, how are you?')
>>> doc.vector.shape
(512,)
>>> doc[:5].vector.shape
(512,)
>>> doc[:1].vector.shape
(300,)
>>> doc[0].similarity(doc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "spacy/tokens/token.pyx", line 212, in spacy.tokens.token.Token.similarity
File "<__array_function__ internals>", line 6, in dot
ValueError: shapes (300,) and (512,) not aligned: 300 (dim 0) != 512 (dim 0)
Shouldn't the vectors for the tokens have the same dimensionality as span and doc?
Thanks for spotting this issue. It's a consequence of the change done for https://github.com/MartinoMensio/spacy-universal-sentence-encoder/issues/13
The underlying model has the Tokens in the vocabulary and therefore the array of shape (300,) comes from en_core_web_lg
. This is not the expected behaviour.
I will provide a fix, but if you switch back to v0.4.1 it should work as expected.
Thank you for your patience. Best, Martino
Thank you, appreciate your prompt response!
While the first and second option in the readme for using this works the third option
throws a keyerror of the form
Is this behavior expected?
Thank you for any help.