A vector space is a space for representing vectors: ordered coordinates that encode position, direction, magnitude, distance, or features. A two-coordinate vector such as [latitude, longitude] belongs to a 2D vector space, while a document’s term-frequency vector occupies one dimension per chosen term. section 3.2.3
Coordinate order is part of the meaning. Swapping latitude and longitude, or rearranging entries in a term-frequency vector, changes the represented point and can invalidate later calculations. Rectilinear spaces use perpendicular dimensions, allowing Euclidean distance to measure the straight-line separation between vectors. section 3.2.3
Vector spaces make language representations computable:
- Term-frequency and TF–IDF vectors place documents in spaces where dot products and distances support similarity calculations. section 3.2.2 section 3.2.3
- Word2Vec maps token-count representations into a lower-dimensional continuous space, where nearby vectors often correspond to related words. section 6.3.1
- Vector arithmetic can express analogies: Portland Timbers + Seattle − Portland produces a vector near Seattle Sounders, even when the result is not exactly in the vocabulary. section 6.3.1
Listing 3.8 2D term frequency vector examples
>>> from matplotlib import pyplot as plt
>>> import seaborn as sns
>>> palette = sns.color_palette("muted") #1
>>> sns.set_theme() #2
>>> vecs = pd.DataFrame([[1, 0], [2, 1]], columns=['x', 'y'])
>>> vecs['color'] = palette[:2]
>>> vecs['label'] = [f'vec{i}' for i in range(1, len(vecs)+1)]
>>> fig, ax = plt.subplots()
>>> for i, row in vecs.iterrows():
... ax.quiver(0, 0, row['x'], row['y'], color=row['color'],
... angles='xy', scale_units='xy', scale=1)
... ax.annotate(row['label'], (row['x'], row['y']),
... color=row['color'], verticalalignment='top'
... )
>>> plt.xlim(-1, 3)
>>> plt.ylim(-1, 2)
>>> plt.xlabel('X (e.g. frequency of word "vector")')
>>> plt.ylabel('Y (e.g. frequency of word "space")')
>>> plt.show()
Plotting [1, 0] and [2, 1] as arrows makes dimensions, direction, magnitude, and coordinate order visible before scaling to high-dimensional NLP vectors. section 3.2.3



