Comments (6)
This was a bug in the docs code. In the cosine function,
(norm(v1), norm(v2))
Should be:
(norm(v1) * norm(v2))
With the comma, the function returns a vector instead of a float.
I've updated the docs.
from spacy.
hm, it still doesn't like my code....
----> 3 cosine = lambda v1, v2: dot(v1, v2) / (norm(v1) * norm(v2))
4 words = [w for w in nlp.vocab if w.lower]
5 words.sort(key=lambda w: cosine(w, pleaded))
TypeError: unsupported operand type(s) for *: 'spacy.lexeme.Lexeme' and 'spacy.tokens.Token'
and perhaps on a separate error, would be good to figure out why I have an empty vector array farther up:
In [4]:
pleaded = tokens[8]
In [5]:
pleaded.repvec.shape
Out[5]:
(300,)
In [6]:
pleaded.repvec[:5]
Out[6]:
array([ 0., 0., 0., 0., 0.], dtype=float32)
from spacy.
Try changing
4 words = [w for w in nlp.vocab if w.lower]
To
4 words = [w for w in nlp.vocab if w.has_repvec]
from spacy.
Changed and re-ran, but the error is thrown before that point:
<ipython-input-13-61632dc9dcea> in <lambda>(v1, v2)
1 from numpy import dot
2 from numpy.linalg import norm
----> 3 cosine = lambda v1, v2: dot(v1, v2) / (norm(v1) * norm(v2))
4 words = [w for w in nlp.vocab if w.has_repvec]
5 words.sort(key=lambda w: cosine(w, pleaded))
TypeError: unsupported operand type(s) for *: 'spacy.lexeme.Lexeme' and 'spacy.tokens.Token'
Env Details if it helps:
Mac OsX 10.9.5
Python 2.7.6 :: Anaconda 2.0.0 (x86_64)
from spacy.
Well, the error is thrown when cosine is invoked --- i.e., during the sort function (cosine is used as the comparison function).
words.sort(key=lambda w: cosine(w.repvec, pleaded.repvec))
(Btw: the larger point is, why have I had so many bugs in the documentation code --- why can't I just use doctest, so that the code is run automatically, during the build?
The problem is that I can't make doctest work with unicode in the strings, and I want to keep the smart-quotes in the example, to illustrate that spaCy works with unicode source text. So, it's hard to ensure that the documentation examples have no errors.)
from spacy.
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.
from spacy.
Related Issues (20)
- Error Loading Spacy pickle model to gpu HOT 1
- Spacy french NER transformer based model fr_dep_news_trf not working HOT 1
- ROCm 5.7 + Spacy HOT 4
- Doc won't serialize with custom attribute HOT 1
- Install via `requirements.txt` documentation doesn't work HOT 17
- catalogue.RegistryError: [E892] Unknown function registry: 'vectors'. HOT 1
- invalid whitespace entity spans msg but no whitespace is there HOT 2
- Upgrade to spacy 3.7.2 throws Attribute error HOT 9
- Training spacy model stucking in 99% HOT 1
- displaCy: Separating Punctuations in Dependency Visualization HOT 1
- spaCy training stopping automatically in Google Colab
- Spacy-transformers - update transformers compatibility HOT 4
- NER component in en_core_web_trf doesn't depend on transformer HOT 1
- en_core_web_sm/md/lg stopped loading today (02/04/2024) HOT 1
- Custom component to split coordinations
- Fail to train openai-community / gpt2 model for custom NER on SpaCy framework HOT 1
- Summary HOT 1
- Sharding Warning HOT 1
- nlp.pipe() with multiple processes on Windows VSCode HOT 2
- `Spacy` has inconsistency when dividing sentences HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spacy.