File size: 2,564 Bytes
aba9483
d3e2300
aba9483
 
d3e2300
29827d7
aba9483
c075982
aba9483
d3e2300
 
ff16f81
 
3d2138b
b3787bf
4b7f4a7
 
 
b3787bf
 
 
aba9483
 
a97a4b5
aba9483
a97a4b5
 
 
ea829c4
 
 
aba9483
 
 
a97a4b5
aba9483
a97a4b5
 
 
aba9483
 
a97a4b5
aba9483
a97a4b5
aba9483
a97a4b5
 
 
 
 
 
aba9483
ea829c4
 
ff16f81
3d2138b
 
 
ea829c4
ff16f81
ea829c4
 
 
 
 
ff16f81
c075982
 
ff16f81
 
 
 
 
 
ea829c4
 
 
 
aba9483
 
 
4b7f4a7
 
 
 
 
 
 
 
 
 
 
 
a97a4b5
 
 
 
 
aba9483
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
license: mit
base_model: BAAI/bge-reranker-v2-m3
tags:
  - generated_from_trainer
  - transformers
library_name: sentence-transformers
pipeline_tag: text-ranking
model-index:
  - name: bge_reranker
    results: []
inference:
  parameters:
    normalize: true
widget:
  - inputs:
      source_sentence: "Hello, world!"
      sentences:
        - "Hello! How are you?"
        - "Cats and dogs"
        - "The sky is blue"
---

# Reranker model

- [Reranker model](#reranker-model)
  - [Brief information](#brief-information)
  - [Supporting architectures](#supporting-architectures)
  - [Example usage](#example-usage)
    - [HuggingFace Inference Endpoints](#huggingface-inference-endpoints)
    - [Local inference](#local-inference)



## Brief information

This repository contains reranker model ```bge-reranker-v2-m3``` which you can run on HuggingFace Inference Endpoints.
- Base model:  [BAAI/bge-reranker-v2-m3](https://huggingface.co/BAAI/bge-reranker-v2-m3) with no any fine tune.
- Commit: [953dc6f6f85a1b2dbfca4c34a2796e7dde08d41e](https://huggingface.co/BAAI/bge-reranker-v2-m3/commit/953dc6f6f85a1b2dbfca4c34a2796e7dde08d41e)


**More details please refer to the [repo of bse model](https://huggingface.co/BAAI/bge-reranker-v2-m3).**

## Supporting architectures

- Apple Silicon MPS
- Nvidia GPU
- HuggingFace Inference Endpoints (AWS)
  - CPU (Intel Sapphire Rapids, 4 vCPU, 8 Gb)
  - GPU (Nvidia T4)
  - Infernia 2 (2 cores, 32 Gb RAM)

## Example usage

### HuggingFace Inference Endpoints

⚠️ When you will deploy this model in HuggingFace Inference endpoints plese select ```Settings``` -> ```Advanced settings``` -> ```Task```: ```Sentence Similarity```

```bash
curl "https://xxxxxxx.us-east-1.aws.endpoints.huggingface.cloud" \
-X POST \
-H "Accept: application/json" \
-H "Authorization: Bearer hf_yyyyyyy" \
-H "Content-Type: application/json" \
-d '{
  "inputs": {
    "source_sentence": "Hello, world!",
    "sentences": [
      "Hello! How are you?",
      "Cats and dogs",
      "The sky is blue"
      ]
  },
  "normalize": true
}'
```

### Local inference

```python
from FlagEmbedding import FlagReranker

class RerankRequest(BaseModel):
    query: str
    documents: list[str]

# Prepare array
arr = []
for element in request.documents:
    arr.append([request.query, element])
print(arr)

# Inference
reranker = FlagReranker('netandreus/bge-reranker-v2-m3', use_fp16=True)
scores = reranker.compute_score(arr, normalize=True)
if not isinstance(scores, list):
    scores = [scores]
print(scores)  # [-8.1875, 5.26171875]
```