LLM2Vec
이라는 decoder-only LLM을 text encoder로 변환하는 unsupervised approach를 제안함.
- unsupervised approach는 아래와 같음
- decoder-only LLM은 causal attention 때문에 좋은 contextualized representation을 얻는 데 한계가 있음.
- 하지만 아래와 이유로 bidirectional attention을 사용하는 encoder model로 embedding을 얻는 거보다 매력적인 선택지임.
- encoder model보다 pre-training 과정에서 일반적으로 sample efficient함.
- decoder-only LLM에 관련된 연구 혹은 생태계가 상대적으로 잘 구축되어있고, 좋은 pre-training recipes (e.g. staged pre-training)이 많이 연구됨.
- decoder-only LLM의 instruction following 연구들에 힘입어, instruction을 사용해서 universal text embedding model을 만들려는 시도들이 있음.
- 어떠한 pre-trained decoder-only LLMs를 universal text encoder로 만드는 방법으로서
LLM2Vec
을 제안함.
- word-level tasks (e.g. chunking, named-entity recognition, part-of speech tagging) 뿐만아니라 sequence-level tasks (e.g. retrieval, classification 등)에서도 매우 좋은 성능을 보임. 또한 공개된 데이터셋만을 이용하여 supervised contrastive learning을 수행하면,
MTEB
benchmark에서 SOTA 급 성능을 보임.
- decoder-only LLMs은 causal attention으로 학습되었으므로, bidirectional attention으로 inference를 하면 representation의 성능이 저하될 수 있음.
- 따라서
masked next token prediction
(MNTP
)로 학습하여, bidirectional attention에 decoder-only LLM이 적응할 수 있게해야함.
masked next token prediction
까지 끝나면, word-level tasks에 잘 대응하는 embedding model을 얻게된 것과 같음. → SimCSE
를 사용하여 unsupervised contrastive learning을 해서 sequence-level tasks (e.g. retrieval, classification, clustering 등)에도 잘 대응할 수 있게함.
- sequence-level embedding을 얻고 싶은 경우,
mean pooling
을 사용함.
Transforming decoder-only LLMs with LLM2Vec
- 아래의 세 개의 decoder-only LLMs를 사용함.
MNTP
와 unsupervised SimCSE에서 English Wikipedia만을 학습 데이터로 사용함.- decoder-only LLMs의 pre-training 과정에 포함되는 데이터이므로, adaptation하는 것외에 새로운 knowledge를 가르치지 않게 할 수 있음.
MNTP
과정에서 masking을 위한 special token이 없기 때문에, underscore (_
)를 masking token으로 사용, LoRA
를 사용하여 학습함.
SimCSE
방법을 LoRA
를 사용하여 학습함.
LLM2Vec-transformed models are strong unsupervised text embedders
Evaluation on word-level tasks
- linear probing setup으로 아래의 tasks에 대하여 평가함.
- causal attention 사용한
Uni
의 경우도 encoder baseline인 DeBERTa-v3-large
보다 좋은 성능을 보임.
MNTP
로 adaptation을 하지않은 경우, bidirectional attention의 성능이 떨어지는 것을 볼 수 있음.
- word-level tasks의 경우,
SimCSE
를 적용하지 않은 경우가 훨씬 좋은 모습을 보임.
Evaluation on sequence-level tasks
- Massive Text Embedding Benchmark (
MTEB
)을 활용해서, sequence-leval tasks에 대한 성능을 측정함.
- sequence-level embedding을 얻기위해서, last EOS token의 embedding을 사용하는 것이 좋은 전략이 아님을 알 수 있음.
- bidirectional attention을 adapt하지않고 적용하는 것은
Mistral-7B
를 제외하고 문제였음.
MNTP
와 SimCSE
를 적용하는 것이 성능을 증대시킴.
- 공정한 비교를 위해서,
LLM2Vec
방법에서 MNTP
까지만 적용한 뒤, Echo embedding
과 비교해보면 거의 비슷한 성능을보임. 그러나 Echo embedding
대비 아래의 이득이 있음.
How does LLM2Vec affect a model?
LLM2Vec helps models to capture information from future tokens
Echo embedding
연구에서 사용했던 방법과 데이터를 동일하게 사용하여, future tokens로부터 information을 얼마나 capture하는 지 평가
Echo embedding
연구에서 데이터는 아래와 같이 구성됨.
- 위와 같은 데이터 구성에서 shared prefix에 해당하는 가 future tokens의 정보를 얼마나 잘 반영하는 지 분석함.
S-LLaMA-1.3B
의 경우는 MNTP
까지 적용해야, positive와 negative를 잘 구분하는 반면에, Mistral-7B
의 경우는 MNTP
로 bidirectional attention에 adapt하지 않아도 잘 구분하는 모습을 보임.
Why does bidirectional attention without training work for Mistral models?
Mistral-7B
가 MNTP
로 bidirectional attention에 adaptation을 시키지 않아도 잘 동작하는 이유를 분석하기위한 시도를 함.
- wikipedia의 paragraph를
Mistral-7B
로 추론을 해서, 의 similarity를 계산함. → bidirectional attention을 adaptation 없이 사용 하는 경우, similarity 값이 작을 것이라고 생각함.- : the hidden representations of every token at ever layer with causal attention
- : the hidden representations of every token at ever layer with bidirectional attention
S-LLaMA-1.3B
, LLaMA-2-7B
는 예상과 같았으나 Mistral-7B
는 그러지 않았음.
Combining LLM2Vec with supervised contrastive learning
LLM2Vec leads to strong performance on the MTEB leaderboard
- supervised contrastive learning을 위해서
E5 dataset
에서 공개가 되어 사용할 수 있는 부분만 사용함.
- 일반적인 contrastive learning 방식을 따름.
- supervised contrastive learning에서
SimCSE
는 덜 중요해지는 것 처럼 보이지만, sample-efficient training을 할 수 있게 해주는 trick으로써 작용함.