# Vector space model

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Vector_space_model
> Markdown URL: https://mediated.wiki/source/Vector_space_model.md
> Source: https://en.wikipedia.org/wiki/Vector_space_model
> Source revision: 1349395790
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Model for representing text documents}}
'''Vector space model''' (VSM) or '''term vector model''' is an algebraic model for representing text documents (or more generally, items) as [vectors](/source/vector_space) such that the distance between vectors represents the relevance between the documents. It is used in [information filtering](/source/information_filtering), [information retrieval](/source/information_retrieval), [index](/source/index_(search_engine))ing and relevance rankings.  Its first use was in the [SMART Information Retrieval System](/source/SMART_Information_Retrieval_System).<ref>{{cite journal
 | last1 = Berry | first1 = Michael W.
 | last2 = Drmac | first2 = Zlatko
 | last3 = Jessup | first3 = Elizabeth R.
 | date = January 1999
 | doi = 10.1137/s0036144598347035
 | issue = 2
 | journal = SIAM Review
 | pages = 335–362
 | title = Matrices, Vector Spaces, and Information Retrieval
 | volume = 41}}</ref>

==Definitions==
In this section we consider a particular vector space model based on the [bag-of-words](/source/Bag-of-words_model) representation. Documents and queries are represented as vectors.

:<math>d_j = ( w_{1,j} ,w_{2,j} , \dotsc ,w_{n,j} )</math>
:<math>q = ( w_{1,q} ,w_{2,q} , \dotsc ,w_{n,q} )</math>

Each [dimension](/source/Dimension_(vector_space)) corresponds to a separate term. If a term occurs in the document, its value in the vector is non-zero. Several different ways of computing these values, also known as (term) weights, have been developed. One of the best known schemes is [tf-idf](/source/tf-idf) weighting (see the example below).

The definition of ''term'' depends on the application. Typically terms are single words, [keyword](/source/keyword_(linguistics))s, or longer phrases. If words are chosen to be the terms, the dimensionality of the vector is the number of words in the vocabulary (the number of distinct words occurring in the [corpus](/source/text_corpus)).

Vector operations can be used to compare documents with queries.<ref name=":0">{{Cite book |last=Büttcher |first=Stefan |title=Information retrieval: implementing and evaluating search engines |last2=Clarke |first2=Charles L. A. |last3=Cormack |first3=Gordon V. |date=2016 |publisher=The MIT Press |isbn=978-0-262-52887-0 |edition=First MIT Press paperback |location=Cambridge, Massachusetts London, England}}</ref>

==Applications==
right|250px

Candidate documents from the corpus can be retrieved and ranked using a variety of methods. [Relevance](/source/Relevance_(information_retrieval)) [ranking](/source/ranking)s of documents in a keyword search can be calculated, using the assumptions of [document similarities](/source/semantic_similarity) theory, by comparing the deviation of angles between each document vector and the original query vector where the query is represented as a vector with same dimension as the vectors that represent the other documents.

In practice, it is easier to calculate the [cosine](/source/cosine) of the angle between the vectors, instead of the angle itself:

:<math>
\cos{\theta} = \frac{\mathbf{d_2} \cdot \mathbf{q}}{\left\| \mathbf{d_2} \right\| \left \| \mathbf{q} \right\|}
</math>

Where <math>\mathbf{d_2} \cdot \mathbf{q}</math> is the intersection (i.e. the [dot product](/source/dot_product)) of the document (d<sub>2</sub> in the figure to the right) and the query (q in the figure) vectors, <math>\left\| \mathbf{d_2} \right\|</math> is the norm of vector d<sub>2</sub>, and <math>\left\| \mathbf{q} \right\|</math> is the norm of vector q. The [norm](/source/Norm_(mathematics)) of a vector is calculated as such:

:<math>
\left\| \mathbf{q} \right\| = \sqrt{\sum_{i=1}^n q_i^2}
</math>

Using the cosine the similarity between document ''d<sub>j</sub>'' and query ''q'' can be calculated as:

:<math>\mathrm{cos}(d_j,q) = \frac{\mathbf{d_j} \cdot \mathbf{q}}{\left\| \mathbf{d_j} \right\| \left \| \mathbf{q} \right\|} = \frac{\sum _{i=1}^N d_{i,j}q_{i}}{\sqrt{\sum _{i=1}^N d_{i,j}^2}\sqrt{\sum _{i=1}^N q_{i}^2}}</math>

As all vectors under consideration by this model are element-wise nonnegative, a cosine value of zero means that the query and document vector are [orthogonal](/source/orthogonal) and have no match (i.e. the query term does not exist in the document being considered). See [cosine similarity](/source/cosine_similarity) for further information.<ref name=":0" />

== Term frequency–inverse document frequency (tf–idf) weights==
In the classic vector space model proposed by [Salton](/source/Gerard_Salton), Wong and Yang,<ref>[http://doi.acm.org/10.1145/361219.361220 G. Salton, A. Wong, C. S. Yang, A vector space model for automatic indexing], Communications of the ACM, v.18 n.11, p.613–620, Nov. 1975</ref> the term-specific weights in the document vectors are products of local and global parameters. The model is known as [term frequency–inverse document frequency](/source/term_frequency%E2%80%93inverse_document_frequency) (tf–idf) model. The weight vector for document ''d'' is <math>\mathbf{v}_d = [w_{1,d}, w_{2,d}, \ldots, w_{N,d}]^T</math>, where

:<math>
w_{t,d} = \mathrm{tf}_{t,d} \cdot \log{\frac{|D|}{|\{d' \in D \, | \, t \in d'\}|}}
</math>

and
* <math>\mathrm{tf}_{t,d}</math> is term frequency of term ''t'' in document ''d'' (a local parameter)
* <math>\log{\frac{|D|}{|\{d' \in D \, | \, t \in d'\}|}}</math> is inverse document frequency (a global parameter). <math>|D|</math> is the total number of documents in the document set; <math>|\{d' \in D \, | \, t \in d'\}|</math> is the number of documents containing the term ''t''.

==Advantages==
The vector space model has the following advantages over the [Standard Boolean model](/source/Standard_Boolean_model):

#Allows ranking documents according to their possible relevance
#Allows retrieving items with a partial term overlap<ref name=":0" />
Most of these advantages are a consequence of the difference in the density of the document collection representation between Boolean and term frequency-inverse document frequency approaches. When using Boolean weights, any document lies in a vertex in a n-dimensional [hypercube](/source/hypercube). Therefore, the possible document representations are <math>2^n</math> and the maximum Euclidean distance between pairs is <math>\sqrt{n}</math>. As documents are added to the document collection, the region defined by the hypercube's vertices become more populated and hence denser. Unlike Boolean, when a document is added using term frequency-inverse document frequency weights, the inverse document frequencies of the terms in the new document decrease while that of the remaining terms increase. In average, as documents are added, the region where documents lie expands regulating the density of the entire collection representation. This behavior models the original motivation of Salton and his colleagues that a document collection represented in a low density region could yield better retrieval results.

==Limitations==
The vector space model has the following limitations:

#Query terms are assumed to be independent, so phrases might not be represented well in the ranking
#Semantic sensitivity; documents with similar context but different term vocabulary won't be associated<ref name=":0" />

Many of these difficulties can, however, be overcome by the integration of various tools, including mathematical techniques such as [singular value decomposition](/source/singular_value_decomposition) and [lexical database](/source/lexical_database)s such as [WordNet](/source/WordNet).

==Models based on and extending the vector space model==
Models based on and extending the vector space model include:
* [Generalized vector space model](/source/Generalized_vector_space_model)
* [Latent semantic analysis](/source/Latent_semantic_analysis)
* [Rocchio Classification](/source/Rocchio_Classification)
* [Random indexing](/source/Random_indexing)

==Software that implements the vector space model==
{{further information|Vector database}}
The following software packages may be of interest to those wishing to experiment with vector models and implement search services based upon them.

===Free open source software===
* [Apache Lucene](/source/Apache_Lucene). Apache Lucene is a high-performance, open source, full-featured text search engine library written entirely in Java.
* [OpenSearch (software)](/source/OpenSearch_(software)), [Elasticsearch](/source/Elasticsearch) and [Solr](/source/Apache_Solr): the three most well-known search engine programs based on Lucene. Others are also available.
* [Gensim](/source/Gensim) is a Python+[NumPy](/source/NumPy) framework for Vector Space modelling. It contains incremental (memory-efficient) algorithms for [term frequency-inverse document frequency](/source/tf%E2%80%93idf), [latent semantic indexing](/source/Latent_Semantic_Indexing), [random projections](/source/Locality_sensitive_hashing) and [latent Dirichlet allocation](/source/Latent_Dirichlet_Allocation).
* [Weka](/source/Weka_(machine_learning)). Weka is a popular data mining package for Java including WordVectors and [Bag Of Words models](/source/Bag-of-words_model).
* [Word2vec](/source/Word2vec). Word2vec uses vector spaces for word embeddings.

==Generalized vector space model==
The '''Generalized vector space model''' is a generalization of the VSM used in [information retrieval](/source/information_retrieval). Wong ''et al.''<ref name="wong">{{citation | chapter=Generalized vector spaces model in information retrieval | first1=S. K. M. | title=Proceedings of the 8th annual international ACM SIGIR conference on Research and development in information retrieval - SIGIR '85 | pages=18–25 | last1=Wong | first2=Wojciech|last2=Ziarko|first3=Patrick C. N.|last3=Wong | publisher=[SIGIR ACM](/source/Association_for_Computing_Machinery) | date=1985-06-05| doi=10.1145/253495.253506 | isbn=0897911598 | doi-access=free }}</ref> presented an analysis of the problems that the pairwise orthogonality assumption of the VSM creates. From here they extended the VSM to the generalized vector space model (GVSM).

Recently Tsatsaronis<ref>{{citation | title=A Generalized Vector Space Model for Text Retrieval Based on Semantic Relatedness | url=http://www.aclweb.org/anthology/E/E09/E09-3009.pdf | last1= Tsatsaronis | first1=George | first2=Vicky | last2=Panagiotopoulou | publisher=[EACL ACM](/source/Association_for_Computing_Machinery) |date=2009-04-02}}</ref> focused on the first approach. They measure semantic relatedness (''SR'') using a thesaurus (''O'') like [WordNet](/source/WordNet). It considers the path length, captured by compactness (''SCM''), and the path depth, captured by semantic path elaboration (''SPE'').

Building also on the first approach, Waitelonis et al.<ref>{{citation | title=Linked Data enabled Generalized Vector Space Model to improve document retrieval | url=http://ceur-ws.org/Vol-1581/paper4.pdf | last1= Waitelonis | first1=Jörg | first2=Claudia | last2=Exeler | last3=Sack| first3=Harald | publisher=ISWC 2015, CEUR-WS 1581 |date=2015-09-11}}</ref> have computed semantic relatedness from [Linked Open Data](/source/Linked_data) resources including [DBpedia](/source/DBpedia) as well as the [YAGO taxonomy](/source/YAGO_(database)). Thereby they exploits taxonomic relationships among semantic entities in documents and queries after [named entity linking](/source/Entity_linking).

==See also==
{{cmn|
*[Bag-of-words model](/source/Bag-of-words_model)
*[Champion list](/source/Champion_list)
*[Compound term processing](/source/Compound_term_processing)
*[Conceptual space](/source/Conceptual_space)
*[Eigenvalues and eigenvectors](/source/Eigenvalues_and_eigenvectors)
*[Inverted index](/source/Inverted_index)
*[Nearest neighbor search](/source/Nearest_neighbor_search)
*[Sparse distributed memory](/source/Sparse_distributed_memory)
*[w-shingling](/source/w-shingling)
}}

==References==
{{reflist}}

==Further reading==
* [G. Salton](/source/Gerard_Salton) (1962), "[https://dl.acm.org/citation.cfm?id=1461544 Some experiments in the generation of word and document associations]" ''Proceeding AFIPS '62 (Fall) Proceedings of the December 4–6, 1962, fall joint computer conference'',  pages 234–250. ''(Early paper of Salton using the term-document matrix formalization)''
* [G. Salton](/source/Gerard_Salton), A. Wong, and C. S. Yang (1975), "[https://dl.acm.org/citation.cfm?id=361220 A Vector Space Model for Automatic Indexing]" ''Communications of the ACM'', vol. 18, nr. 11, pages 613–620. ''(Article in which a vector space model was presented)''
* David Dubin (2004), [https://www.ideals.illinois.edu/items/1790 The Most Influential Paper Gerard Salton Never Wrote] ''(Explains the history of the Vector Space Model and the non-existence of a frequently cited publication)''
* [https://web.archive.org/web/20110814000253/http://cogsys.imm.dtu.dk/thor/projects/multimedia/textmining/node5.html Description of the vector space model]
* [http://www.miislita.com/term-vector/term-vector-3.html Description of the classic vector space model by Dr E. Garcia]
* [http://nlp.stanford.edu/IR-book/html/htmledition/vector-space-classification-1.html Relationship of vector space search to the "k-Nearest Neighbor" search]

Category:Vector space model

---
Adapted from the Wikipedia article [Vector space model](https://en.wikipedia.org/wiki/Vector_space_model) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Vector_space_model?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
