Views
No views yet
bge-reranker-v2-m3 which you can run on HuggingFace Inference Endpoints.Settings -> Advanced settings -> Task: Sentence Similarity1curl "https://xxxxxxx.us-east-1.aws.endpoints.huggingface.cloud" \
2-X POST \
3-H "Accept: application/json" \
4-H "Authorization: Bearer hf_yyyyyyy" \
5-H "Content-Type: application/json" \
6-d '{
7 "inputs": {
8 "source_sentence": "Hello, world!",
9 "sentences": [
10 "Hello! How are you?",
11 "Cats and dogs",
12 "The sky is blue"
13 ]
14 },
15 "normalize": true
16}'1from FlagEmbedding import FlagReranker
2
3class RerankRequest(BaseModel):
4 query: str
5 documents: list[str]
6
7# Prepare array
8arr = []
9for element in request.documents:
10 arr.append([request.query, element])
11print(arr)
12
13# Inference
14reranker = FlagReranker('netandreus/bge-reranker-v2-m3', use_fp16=True)
15scores = reranker.compute_score(arr, normalize=True)
16if not isinstance(scores, list):
17 scores = [scores]
18print(scores) # [-8.1875, 5.26171875]