How are vectors constructed
What this lesson covers
This lesson explains how objects such as documents are turned into vectors. Each document is plotted with its length on the x axis and how real its content is on the y axis, so a long fictional book like Harry Potter sits at the bottom right, Sherlock Holmes a little higher, and the short, fact based paper Attention Is All You Need at the top left. As more documents are plotted, clusters appear, and a document's position comes to carry its meaning. Two dimensions are not enough, and adding a dimension for every property would give an unbounded number, so the count is fixed at some value D. Llama uses 4,096 and larger models use more. A neural network does the mapping: it takes a document as input and outputs a one dimensional array of that length, the vector. During training the network is rewarded when similar objects produce vectors that are close in Euclidean distance and penalised when dissimilar ones land close together, with back propagation minimising the loss. Pre-trained libraries are recommended for most cases, but the video describes fine tuning for a t-shirt site's image search, where the model is shown examples that vary pose and expression so it learns to ignore everything but the t-shirt. Fine tuning needs manual examples and GPU time. Finally, queries become vectors, nearby document vectors are fetched, and those documents go to the LLM.
- Plotting documents by properties such as length and how real they are moves their meaning into a spatial domain
- The number of dimensions is fixed, 4,096 in the case of Llama, and a neural network maps each document to a vector of that length
- Training rewards the network when similar objects produce nearby vectors and penalises it when dissimilar ones do
- Off the shelf vectorisers work for most cases, but a t-shirt image search needs fine tuning so pose and expression are ignored
- Fine tuning needs hand made examples and GPU time, through a cloud provider or with TensorFlow or PyTorch