Dongjin-kr
commited on
Commit
โข
2e58d77
1
Parent(s):
6f11226
update
Browse files
README.md
CHANGED
@@ -14,12 +14,37 @@ ko-reranker๋ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
14 |
|
15 |
- - -
|
16 |
|
17 |
-
## 0.
|
18 |
- #### <span style="#FF69B4;"> Reranker๋ ์๋ฒ ๋ฉ ๋ชจ๋ธ๊ณผ ๋ฌ๋ฆฌ ์ง๋ฌธ๊ณผ ๋ฌธ์๋ฅผ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ๋ฉฐ ์๋ฒ ๋ฉ ๋์ ์ ์ฌ๋๋ฅผ ์ง์ ์ถ๋ ฅํฉ๋๋ค.</span>
|
19 |
- #### <span style="#FF69B4;"> Reranker์ ์ง๋ฌธ๊ณผ ๊ตฌ์ ์ ์
๋ ฅํ๋ฉด ์ฐ๊ด์ฑ ์ ์๋ฅผ ์ป์ ์ ์์ต๋๋ค.</span>
|
20 |
- #### <span style="#FF69B4;"> Reranker๋ CrossEntropy loss๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ต์ ํ๋๋ฏ๋ก ๊ด๋ จ์ฑ ์ ์๊ฐ ํน์ ๋ฒ์์ ๊ตญํ๋์ง ์์ต๋๋ค.</span>
|
21 |
|
22 |
-
## 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
- #### <span style="#FF69B4;"> **์ปจํ์คํธ ์์๊ฐ ์ ํ๋์ ์ํฅ ์ค๋ค**([Lost in Middel, *Liu et al., 2023*](https://arxiv.org/pdf/2307.03172.pdf)) </span>
|
24 |
|
25 |
- #### <span style="#FF69B4;"> [Reranker ์ฌ์ฉํด์ผ ํ๋ ์ด์ ](https://www.pinecone.io/learn/series/rag/rerankers/)</span>
|
@@ -31,7 +56,7 @@ ko-reranker๋ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
31 |
|
32 |
- - -
|
33 |
|
34 |
-
##
|
35 |
|
36 |
- #### <span style="#FF69B4;"> [Cohere] [Reranker](https://txt.cohere.com/rerank/)</span>
|
37 |
- #### <span style="#FF69B4;"> [BAAI] [bge-reranker-large](https://huggingface.co/BAAI/bge-reranker-large)</span>
|
@@ -39,7 +64,7 @@ ko-reranker๋ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
39 |
|
40 |
- - -
|
41 |
|
42 |
-
##
|
43 |
|
44 |
- #### <span style="#FF69B4;"> [msmarco-triplets](https://github.com/microsoft/MSMARCO-Passage-Ranking) </span>
|
45 |
- (Question, Answer, Negative)-Triplets from MS MARCO Passages dataset, 499,184 samples
|
@@ -48,7 +73,7 @@ ko-reranker๋ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
48 |
|
49 |
- - -
|
50 |
|
51 |
-
##
|
52 |
| Model | has-right-in-contexts | mrr (mean reciprocal rank) |
|
53 |
|:---------------------------|:-----------------:|:--------------------------:|
|
54 |
| without-reranker (default)| 0.93 | 0.80 |
|
@@ -76,22 +101,22 @@ ko-reranker๋ [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
|
|
76 |
|
77 |
- - -
|
78 |
|
79 |
-
##
|
80 |
- <span style="#FF69B4;"> Part of the code is developed based on [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/tree/master?tab=readme-ov-file) and [KoSimCSE-SageMaker](https://github.com/daekeun-ml/KoSimCSE-SageMaker/tree/7de6eefef8f1a646c664d0888319d17480a3ebe5).</span>
|
81 |
|
82 |
- - -
|
83 |
|
84 |
-
##
|
85 |
- <span style="#FF69B4;"> If you find this repository useful, please consider giving a like โญ and citation</span>
|
86 |
|
87 |
- - -
|
88 |
|
89 |
-
##
|
90 |
- <span style="#FF69B4;"> **Dongjin Jang, Ph.D.** (AWS AI/ML Specislist Solutions Architect) | [Mail](mailto:dongjinj@amazon.com) | [Linkedin](https://www.linkedin.com/in/dongjin-jang-kr/) | [Git](https://github.com/dongjin-ml) | </span>
|
91 |
|
92 |
- - -
|
93 |
|
94 |
-
##
|
95 |
- <span style="#FF69B4;"> FlagEmbedding is licensed under the [MIT License](https://github.com/aws-samples/aws-ai-ml-workshop-kr/blob/master/LICENSE). </span>
|
96 |
|
97 |
|
|
|
14 |
|
15 |
- - -
|
16 |
|
17 |
+
## 0. Features
|
18 |
- #### <span style="#FF69B4;"> Reranker๋ ์๋ฒ ๋ฉ ๋ชจ๋ธ๊ณผ ๋ฌ๋ฆฌ ์ง๋ฌธ๊ณผ ๋ฌธ์๋ฅผ ์
๋ ฅ์ผ๋ก ์ฌ์ฉํ๋ฉฐ ์๋ฒ ๋ฉ ๋์ ์ ์ฌ๋๋ฅผ ์ง์ ์ถ๋ ฅํฉ๋๋ค.</span>
|
19 |
- #### <span style="#FF69B4;"> Reranker์ ์ง๋ฌธ๊ณผ ๊ตฌ์ ์ ์
๋ ฅํ๋ฉด ์ฐ๊ด์ฑ ์ ์๋ฅผ ์ป์ ์ ์์ต๋๋ค.</span>
|
20 |
- #### <span style="#FF69B4;"> Reranker๋ CrossEntropy loss๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ต์ ํ๋๋ฏ๋ก ๊ด๋ จ์ฑ ์ ์๊ฐ ํน์ ๋ฒ์์ ๊ตญํ๋์ง ์์ต๋๋ค.</span>
|
21 |
|
22 |
+
## 1.Usage
|
23 |
+
|
24 |
+
- Local
|
25 |
+
'''
|
26 |
+
def exp_normalize(x):
|
27 |
+
b = x.max()
|
28 |
+
y = np.exp(x - b)
|
29 |
+
return y / y.sum()
|
30 |
+
|
31 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
32 |
+
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
34 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
35 |
+
model.eval()
|
36 |
+
|
37 |
+
pairs = [["๋๋ ๋๋ฅผ ์ซ์ดํด", "๋๋ ๋๋ฅผ ์ฌ๋ํด"], \
|
38 |
+
["๋๋ ๋๋ฅผ ์ข์ํด", "๋์ ๋ํ ๋์ ๊ฐ์ ์ ์ฌ๋ ์ผ ์๋ ์์ด"]]
|
39 |
+
|
40 |
+
with torch.no_grad():
|
41 |
+
inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
|
42 |
+
scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
|
43 |
+
scores = exp_normalize(scores.numpy())
|
44 |
+
print (f'first: {scores[0]}, second: {scores[1]}')
|
45 |
+
'''
|
46 |
+
|
47 |
+
## 2. Backgound
|
48 |
- #### <span style="#FF69B4;"> **์ปจํ์คํธ ์์๊ฐ ์ ํ๋์ ์ํฅ ์ค๋ค**([Lost in Middel, *Liu et al., 2023*](https://arxiv.org/pdf/2307.03172.pdf)) </span>
|
49 |
|
50 |
- #### <span style="#FF69B4;"> [Reranker ์ฌ์ฉํด์ผ ํ๋ ์ด์ ](https://www.pinecone.io/learn/series/rag/rerankers/)</span>
|
|
|
56 |
|
57 |
- - -
|
58 |
|
59 |
+
## 3. Reranker models
|
60 |
|
61 |
- #### <span style="#FF69B4;"> [Cohere] [Reranker](https://txt.cohere.com/rerank/)</span>
|
62 |
- #### <span style="#FF69B4;"> [BAAI] [bge-reranker-large](https://huggingface.co/BAAI/bge-reranker-large)</span>
|
|
|
64 |
|
65 |
- - -
|
66 |
|
67 |
+
## 4. Dataset
|
68 |
|
69 |
- #### <span style="#FF69B4;"> [msmarco-triplets](https://github.com/microsoft/MSMARCO-Passage-Ranking) </span>
|
70 |
- (Question, Answer, Negative)-Triplets from MS MARCO Passages dataset, 499,184 samples
|
|
|
73 |
|
74 |
- - -
|
75 |
|
76 |
+
## 5. Performance
|
77 |
| Model | has-right-in-contexts | mrr (mean reciprocal rank) |
|
78 |
|:---------------------------|:-----------------:|:--------------------------:|
|
79 |
| without-reranker (default)| 0.93 | 0.80 |
|
|
|
101 |
|
102 |
- - -
|
103 |
|
104 |
+
## 6. Acknowledgement
|
105 |
- <span style="#FF69B4;"> Part of the code is developed based on [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/tree/master?tab=readme-ov-file) and [KoSimCSE-SageMaker](https://github.com/daekeun-ml/KoSimCSE-SageMaker/tree/7de6eefef8f1a646c664d0888319d17480a3ebe5).</span>
|
106 |
|
107 |
- - -
|
108 |
|
109 |
+
## 7. Citation
|
110 |
- <span style="#FF69B4;"> If you find this repository useful, please consider giving a like โญ and citation</span>
|
111 |
|
112 |
- - -
|
113 |
|
114 |
+
## 8. Contributors:
|
115 |
- <span style="#FF69B4;"> **Dongjin Jang, Ph.D.** (AWS AI/ML Specislist Solutions Architect) | [Mail](mailto:dongjinj@amazon.com) | [Linkedin](https://www.linkedin.com/in/dongjin-jang-kr/) | [Git](https://github.com/dongjin-ml) | </span>
|
116 |
|
117 |
- - -
|
118 |
|
119 |
+
## 9. License
|
120 |
- <span style="#FF69B4;"> FlagEmbedding is licensed under the [MIT License](https://github.com/aws-samples/aws-ai-ml-workshop-kr/blob/master/LICENSE). </span>
|
121 |
|
122 |
|