yjoonjang commited on
Commit
7e0cd05
Β·
verified Β·
1 Parent(s): 1028d5e

Add API usage

Browse files
Files changed (1) hide show
  1. README.md +37 -0
README.md CHANGED
@@ -23,6 +23,7 @@ license: apache-2.0
23
  # πŸ”Ž KURE-Sparse-nano
24
 
25
  **KURE-Sparse-nano** is a compact (0.1B) Korean-English learned sparse retrieval model. It shows state-of-the-art performance among < 0.5B sparse models supporting Korean, averaging **0.7716** nDCG@10 on MTEB(kor, v2) Retrieval. It also outperforms much larger dense models, such as pplx-embed-v1-4b and harrier-oss-v1-27b.
 
26
 
27
  <p align="center">
28
  <img src="assets/kure_ndcg.png" width="100%" alt="Average nDCG@10 on MTEB(kor, v2) Retrieval of the KURE models and baseline retrievers">
@@ -38,6 +39,8 @@ license: apache-2.0
38
 
39
  ## Usage
40
 
 
 
41
  ```bash
42
  pip install -U sentence-transformers
43
  ```
@@ -67,6 +70,40 @@ print(scores)
67
  # tensor([[119.3931, 11.5758, 6.4037]])
68
  ```
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  ## Evaluation
71
 
72
  KURE-Sparse-nano is evaluated on the nine **MTEB(kor, v2) Retrieval** tasks. We report nDCG@10.
 
23
  # πŸ”Ž KURE-Sparse-nano
24
 
25
  **KURE-Sparse-nano** is a compact (0.1B) Korean-English learned sparse retrieval model. It shows state-of-the-art performance among < 0.5B sparse models supporting Korean, averaging **0.7716** nDCG@10 on MTEB(kor, v2) Retrieval. It also outperforms much larger dense models, such as pplx-embed-v1-4b and harrier-oss-v1-27b.
26
+ It is also served through the [KURE API](https://kure.kullm.ai/).
27
 
28
  <p align="center">
29
  <img src="assets/kure_ndcg.png" width="100%" alt="Average nDCG@10 on MTEB(kor, v2) Retrieval of the KURE models and baseline retrievers">
 
39
 
40
  ## Usage
41
 
42
+ ### Sentence Transformers
43
+
44
  ```bash
45
  pip install -U sentence-transformers
46
  ```
 
70
  # tensor([[119.3931, 11.5758, 6.4037]])
71
  ```
72
 
73
+ ### API
74
+
75
+ KURE-Sparse-nano is served at [kure.kullm.ai](https://kure.kullm.ai/). Sign in with GitHub there to get an API key.
76
+
77
+ ```python
78
+ import os
79
+
80
+ import requests
81
+
82
+ URL = "https://kure.kullm.ai/api/v1/sparse-embeddings"
83
+ HEADERS = {"Authorization": f"Bearer {os.environ['KURE_API_KEY']}"}
84
+
85
+ query = "ν›ˆλ―Όμ •μŒμ€ μ–Έμ œ λ§Œλ“€μ–΄μ‘Œλ‚˜μš”?"
86
+ documents = [
87
+ "μ„Έμ’…λŒ€μ™•μ€ 1443년에 ν›ˆλ―Όμ •μŒμ„ μ°½μ œν•˜κ³  1446년에 이λ₯Ό λ°˜ν¬ν•˜μ˜€λ‹€.",
88
+ "κΉ€μΉ˜λŠ” λ°°μΆ”λ‚˜ 무λ₯Ό μ†ŒκΈˆμ— 절인 λ’€ 고좧가루와 μ “κ°ˆμ„ λ„£μ–΄ λ°œνš¨μ‹œν‚¨ μŒμ‹μ΄λ‹€.",
89
+ "ν•œλΌμ‚°μ€ ν•΄λ°œ 1,947m둜 λ‚¨ν•œμ—μ„œ κ°€μž₯ 높은 산이며 μ œμ£Όλ„ 쀑앙에 μžλ¦¬ν•œλ‹€.",
90
+ ]
91
+
92
+ # input_type adds the query or document markers. return_tokens=True also returns the term of each index
93
+ def encode(texts, input_type):
94
+ response = requests.post(URL, headers=HEADERS, json={"model": "kure-sparse-nano", "input": texts, "input_type": input_type})
95
+ response.raise_for_status()
96
+ return [dict(zip(e["indices"], e["values"])) for e in response.json()["data"]]
97
+
98
+ query_embedding = encode(query, "query")[0]
99
+ document_embeddings = encode(documents, "document")
100
+
101
+ # Dot-product scores (higher is more relevant)
102
+ scores = [sum(w * doc.get(i, 0.0) for i, w in query_embedding.items()) for doc in document_embeddings]
103
+ print([round(s, 4) for s in scores])
104
+ # [117.3682, 11.7437, 6.2175]
105
+ ```
106
+
107
  ## Evaluation
108
 
109
  KURE-Sparse-nano is evaluated on the nine **MTEB(kor, v2) Retrieval** tasks. We report nDCG@10.