en_core_web_lg). While:
- NumPy is the core numerical library used to manipulate vectors (arrays)
- matplotlib is for visualization
- scikit-learn offers ML utilities and some vectorizers (e.g., TF-IDF)
.vector embeddings that are convenient for semantic search workflows.
Use a spaCy model that includes vectors (for example,
en_core_web_lg) when you need ready-made dense embeddings. For higher-quality sentence or paragraph embeddings, consider transformer-based libraries such as sentence-transformers (SBERT) or Hugging Face models, and combine those embeddings with spaCy or your retrieval pipeline as needed.Quick comparison
Install and load a spaCy model with vectors
Shell:- spaCy’s
.vectoron aDocorTokenreturns a densenumpy.ndarraythat you can use directly for similarity computations (cosine similarity), indexing into vector stores, or as input to downstream models. - For improved semantic-search accuracy at sentence/paragraph level, consider transformer-based encoders such as
sentence-transformersor Hugging Face embedding models; these typically yield higher-quality embeddings than classic spaCy vectors for sentence semantics. - Use
sklearn.metrics.pairwise.cosine_similarityorscipy.spatial.distance.cosine(or faiss/annoy for large-scale search) to compute nearest neighbors efficiently.
References and further reading
- spaCy models: https://spacy.io/models/en_core_web_lg
- sentence-transformers: https://www.sbert.net/
- Hugging Face: https://huggingface.co/