Dongjin-kr commited on
Commit
2e58d77
โ€ข
1 Parent(s): 6f11226
Files changed (1) hide show
  1. README.md +34 -9
README.md CHANGED
@@ -14,12 +14,37 @@ ko-reranker๋Š” [BAAI/bge-reranker-larger](https://huggingface.co/BAAI/bge-rerank
14
 
15
  - - -
16
 
17
- ## 0. Usage
18
  - #### <span style="#FF69B4;"> Reranker๋Š” ์ž„๋ฒ ๋”ฉ ๋ชจ๋ธ๊ณผ ๋‹ฌ๋ฆฌ ์งˆ๋ฌธ๊ณผ ๋ฌธ์„œ๋ฅผ ์ž…๋ ฅ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ ์ž„๋ฒ ๋”ฉ ๋Œ€์‹  ์œ ์‚ฌ๋„๋ฅผ ์ง์ ‘ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.</span>
19
  - #### <span style="#FF69B4;"> Reranker์— ์งˆ๋ฌธ๊ณผ ๊ตฌ์ ˆ์„ ์ž…๋ ฅํ•˜๋ฉด ์—ฐ๊ด€์„ฑ ์ ์ˆ˜๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</span>
20
  - #### <span style="#FF69B4;"> Reranker๋Š” CrossEntropy loss๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ตœ์ ํ™”๋˜๋ฏ€๋กœ ๊ด€๋ จ์„ฑ ์ ์ˆ˜๊ฐ€ ํŠน์ • ๋ฒ”์œ„์— ๊ตญํ•œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</span>
21
 
22
- ## 1. Backgound
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- ## 2. Reranker models
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
- ## 3. Dataset
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
- ## 4. Performance
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
- ## 5. Acknowledgement
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
- ## 6. Citation
85
  - <span style="#FF69B4;"> If you find this repository useful, please consider giving a like โญ and citation</span>
86
 
87
  - - -
88
 
89
- ## 7. Contributors:
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
- ## 8. License
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