Mayfull commited on
Commit
7f99ab1
1 Parent(s): f7b548b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +122 -0
README.md ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - transformers
4
+ language:
5
+ - en
6
+ license: cc-by-nc-4.0
7
+ ---
8
+ <h1 align="center">Linq-AI-Research/Linq-Embed-Mistral</h1>
9
+
10
+ **Linq-Embed-Mistral**
11
+
12
+ Linq-Embed-Mistral has been developed by building upon the foundations of the E5-mistral-7b-instruct and Mistral-7B-v0.1 models. We focus on improving text retrieval using advanced data refinement methods, including sophisticated data crafting, data filtering, and negative mining techniques. These methods are applied to both existing benchmark datasets and highly tailored synthetic datasets generated via LLMs. To enhance the quality of the synthetic data, we employ extensive prompt engineering and guidance from teacher models, ensuring these methods are specifically tailored to each task. Our efforts primarily aim to create high-quality triplet datasets (query, positive example, negative example), significantly improving text retrieval performance.
13
+
14
+ Linq-Embed-Mistral performs exceptionally well in the MTEB benchmarks, achieving an average score of 68.1 across 56 datasets. This performance ranks it 1st among publicly accessible models on the MTEB leaderboard and 3rd overall among all evaluated models. The model excels in retrieval tasks, ranking 1st among all models listed on the MTEB leaderboard with a performance score of 60.0.
15
+
16
+ This project is for research purposes only. Third-party datasets may be subject to additional terms and conditions under their associated licenses. Please refer to specific papers for more details:
17
+
18
+ - [MTEB benchmark](https://arxiv.org/abs/2210.07316)
19
+ - [Mistral](https://arxiv.org/abs/2310.06825)
20
+ - [E5-mistral-7b-instruct](https://arxiv.org/pdf/2401.00368.pdf)
21
+
22
+ For more details, refer to [this blog post](https://getlinq.com/blog/linq-embed-mistral/).
23
+
24
+ ## How to use
25
+
26
+ ### Transformers
27
+
28
+ Here is an example of how to encode queries and passages from the Mr.TyDi training dataset.
29
+
30
+ ```python
31
+ import torch
32
+ import torch.nn.functional as F
33
+ from torch import Tensor
34
+ from transformers import AutoTokenizer, AutoModel
35
+
36
+ def last_token_pool(last_hidden_states: Tensor,
37
+ attention_mask: Tensor) -> Tensor:
38
+ left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
39
+ if left_padding:
40
+ return last_hidden_states[:, -1]
41
+ else:
42
+ sequence_lengths = attention_mask.sum(dim=1) - 1
43
+ batch_size = last_hidden_states.shape[0]
44
+ return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]
45
+
46
+ def get_detailed_instruct(task_description: str, query: str) -> str:
47
+ return f'Instruct: {task_description}\nQuery: {query}'
48
+
49
+ # Each query must come with a one-sentence instruction that describes the task
50
+ task = 'Given a question, retrieve Wikipedia passages that answer the question'
51
+ queries = [
52
+ get_detailed_instruct(task, '최초의 원자력 발전소는 무엇인가?'),
53
+ get_detailed_instruct(task, 'Who invented Hangul?')
54
+ ]
55
+ # No need to add instruction for retrieval documents
56
+ passages = [
57
+ "현재 사용되는 핵분열 방식을 이용한 전력생산은 1948년 9월 미국 테네시주 오크리지에 설치된 X-10 흑연원자로에서 전구의 불을 밝히는 데 사용되면서 시작되었다. 그리고 1954년 6월에 구소련의 오브닌스크에 건설된 흑연감속 비등경수 압력관형 원자로를 사용한 오브닌스크 원자력 발전소가 시험적으로 전력생산을 시작하였고, 최초의 상업용 원자력 엉더이로를 사용한 영국 셀라필드 원자력 단지에 위치한 콜더 홀(Calder Hall) 원자력 발전소로, 1956년 10월 17일 상업 운전을 시작하였다.",
58
+ "Hangul was personally created and promulgated by the fourth king of the Joseon dynasty, Sejong the Great.[1][2] Sejong's scholarly institute, the Hall of Worthies, is often credited with the work, and at least one of its scholars was heavily involved in its creation, but it appears to have also been a personal project of Sejong."
59
+ ]
60
+
61
+ # Load model and tokenizer
62
+ tokenizer = AutoTokenizer.from_pretrained('Linq-AI-Research/Linq-Embed-Mistral')
63
+ model = AutoModel.from_pretrained('Linq-AI-Research/Linq-Embed-Mistral')
64
+
65
+ max_length = 4096
66
+ input_texts = [*queries, *passages]
67
+ # Tokenize the input texts
68
+ batch_dict = tokenizer(input_texts, max_length=max_length, padding=True, truncation=True, return_tensors="pt")
69
+ outputs = model(**batch_dict)
70
+ embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
71
+
72
+ # Normalize embeddings
73
+ embeddings = F.normalize(embeddings, p=2, dim=1)
74
+ scores = (embeddings[:2] @ embeddings[2:].T) * 100
75
+ print(scores.tolist())
76
+ # [[86.7153549194336, 36.64569091796875], [35.00493621826172, 82.0738525390625]]
77
+ ```
78
+
79
+ ### MTEB Benchmark Evaluation
80
+
81
+ Check out [unilm/e5](https://github.com/microsoft/unilm/tree/master/e5) to reproduce evaluation results on the [BEIR](https://arxiv.org/abs/2104.08663) and [MTEB](https://arxiv.org/abs/2210.07316) benchmark.
82
+
83
+ ## Evaluation Result
84
+
85
+ ### MTEB
86
+
87
+ | Model Name | Retrieval (15) | Average (56) |
88
+ | :------------------------------------------------------------------------------: | :------------: | :----------: |
89
+ | [Linq-Embed-Mistral](https://huggingface.co/Linq-AI-Research/Linq-Embed-Mistral) | 60.0 | 68.1 |
90
+ | [NV-Embed-v1](https://huggingface.co/nvidia/NV-Embed-v1) | 59.4 | 69.3 |
91
+ | [SFR-Embedding-Mistral](https://huggingface.co/Salesforce/SFR-Embedding-Mistral) | 59.0 | 67.6 |
92
+ | [voyage-large-2-instruct](https://docs.voyageai.com/docs/embeddings) | 58.3 | 68.3 |
93
+ | [GritLM-7B](https://huggingface.co/GritLM/GritLM-7B) | 57.4 | 66.8 |
94
+ | voyage-lite-02-instruct](https://docs.voyageai.com/docs/embeddings) | 56.6 | 67.1 |
95
+ |[gte-Qwen1.5-7B-instruct](https://huggingface.co/Alibaba-NLP/gte-Qwen1.5-7B-instruct)| 56.2 | 67.3 |
96
+ | [e5-mistral-7b-instruct](https://huggingface.co/intfloat/e5-mistral-7b-instruct) | 56.9 | 66.6 |
97
+ |[google-gecko.text-embedding-preview-0409](https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings?hl=ko#latest_models)| 55.7 | 66.3 |
98
+ |[text-embedding-3-large](https://openai.com/index/new-embedding-models-and-api-updates/)| 55.4 | 64.6 |
99
+ |[Cohere-embed-english-v3.0](https://huggingface.co/Cohere/Cohere-embed-english-v3.0)| 55.0 | 64.5 |
100
+
101
+ Linq Research Team.
102
+
103
+ - Junseong Kim
104
+ - Seolhwa Lee
105
+ - Jihoon Kwon
106
+ - Sangmo Gu
107
+ - Yejin Kim
108
+ - Minkyung Cho
109
+ - Jy-yong Sohn
110
+ - Chanyeol Choi
111
+
112
+ ### Citation
113
+
114
+ ```bibtex
115
+ @misc{LinqAIResearch2024,
116
+ title={Linq-Embed-Mistral:Elevating Text Retrieval with Improved GPT Data Through Task-Specific Control and Quality Refinement},
117
+ author={Junseong Kim, Seolhwa Lee, Jihoon Kwon, Sangmo Gu, Yejin Kim, Minkyung Cho, Jy-yong Sohn, Chanyeol Choi},
118
+ howpublished={Linq AI Research Blog},
119
+ year={2024},
120
+ url={https://getlinq.com/blog/linq-embed-mistral/}
121
+ }
122
+ ```