3 ms·
Something I've never understood about text embeddings is how they work with multi-topic documents. I mean, I can imagine text embeddings in a 2D plane. Documen
by michaelt 3y ago
Something I've never understood about text embeddings is how they work with multi-topic documents.
I mean, I can imagine text embeddings in a 2D plane. Documents about lions and documents about tigers are close together, as they're both big cats. Documents about bears are relatively further away, forming a triangle with two long sides and one short side.
But wouldn't a single document about lions, tiger and bears end up at the middle of the triangle? And wouldn't that mean that when a user searches for lions, the document about tigers is closer than the document about lions, tigers and bears?
- MogwaiAllOnYou 3y agoYou're thinking in human dimensions. With so many dimensions available, it might be the case that one dimension represents the "animal" dimension, and the others represent other features. Oversimplification obviously!
- mhuffman 3y agoI do not think embeddings would have too much trouble with a mult-topic document. It might have more trouble where words are phrases are used closed together in the same document but have different meanings.
- PaulHoule 3y agoIt's a big strength of embeddings like BERT and later on that they embed not just the "word" but the word plus its context so if the same word is used in two different places with two different meanings the embedding for that token ought to be different.
- hobofan 3y agoAs far as my understanding goes, there are multiple parts to what you are bringing up. In your simplified example of a 2D plane, yeah, you are right, I think. However that's why we have more than two dimensions. E.g. If we just have a few more dimensions, we could have one dimension per attribute "lion-ness", "bear-ness", "tiger-ness" of the document, so going higher on the "lion-ness" dimension doesn't have any impact on the other two dimensions, and the conflict is resolved. Of course in practice, we can't spare one dimension per animal, and that's where embedding models come in, which take care of mapping a string of text into a high-dimensional vector space, and in the process compresses topics, context, etc.. If that model were to be constructed badly, it is possible that we may actually end up with such a bug as you described, where mention of multiple topics produces a not-so-optimal embedding. Another part that's also relevant in practice is that embedding vectors can be very sensitive (depending on model used) to how you "chunk" (= divide the input string). E.g. if you create chunks where each sentence that is about a bear, a tiger and a lion are separated you will of course get clearer embeddings regarding the individual animals. If you chunk all of them together you will probably receive an "apex-predator"-like embedding, that performs better if you are doing vector search on a more generalized level. That can indeed cause a challenge if you'd like to implementa generalized search that can handle both individual word retrieval as well as concept based retrieval.
- michaelt 3y agoBut if I only have 3 feature vectors, aren't they always in a 2D plane, regardless of their dimensionality?
- barrell 3y agoEven in this example, I don’t think that the middle of lions, tigers, and bears would be further away from lions than tigers. But it might also help to understand that most often your embedding smaller chunks of data, specifically for the reason of specificity. A lot of embedding models have a hard limit of 512 tokens or so. Embedding text that is incredibly short, or much longer than that, tends to decrease the quality precisely because of what you’re talking about. Although I don’t think to the extent you’re imagining
- DougBTX 3y agoThis might interest you: https://transformer-circuits.pub/2023/monosemantic-features https://transformer-circuits.pub/2023/monosemantic-features An embedding is essentially a set of neuron activations, the number of combinations of activations is much bigger than the number of neurons themselves. An embedding could store "A+B" as well as being able to store "A" and "B", but it is a little complex to understand what particular activations mean.
- didgeoridoo 3y agoThis is where chunking comes into play. If you embed the entire document, then yes it’s likely to only be close in vector space to other documents containing lions, tigers, AND bears. But if you set up your chunking such that you’re dividing the document by sentence, paragraph, etc. you will get a finer-grained set of separate embeddings that can point to the document (or even different areas within it) whether you’re looking for lions, tigers, OR bears.
- taneq 3y agoSounds like a ‘mipmap’ sort of approach could be useful. Add the whole document, then the chapters, then paragraphs. How does the system know how much context is required, though? If I ask “Steve wears turtlenecks, what company does Steve work at?” then a paragraph about a Steve who likes turtlenecks and a paragraph about a Steve who works at MS would both be highly relevant but when combined they would result in the wrong answer.
- didgeoridoo 3y agoThe boring answer is to bash domain expertise and evals together until your data pipeline seems to be spitting out embeddings that give you acceptable results for whatever you’re trying to do. I do wonder if there is some additional cleverness that’s possible with fast, long-context LLMs, maybe a summarizing/preprocessing step that can slice up the document into a sensible hierarchy of topics that can be used as the embeddings source. Never seen this in practice though.
- joshka 3y agoThe RAG from scratch video series on the Langchain youtube channel has some pretty good coverage of this and many other ideas. https://www.youtube.com/@LangChain/videos https://www.youtube.com/@LangChain/videos (the LlamaIndex channel is similarly good https://www.youtube.com/@LlamaIndex/ https://www.youtube.com/@LlamaIndex/