Feature Extraction
sentence-transformers
Safetensors
Korean
English
modernbert
sparse-encoder
sparse
splade
learned-sparse-retrieval
text-embeddings-inference
Instructions to use nlpai-lab/KURE-Sparse-nano with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use nlpai-lab/KURE-Sparse-nano with sentence-transformers:
from sentence_transformers import SparseEncoder model = SparseEncoder("nlpai-lab/KURE-Sparse-nano") queries = ["Which planet is known as the Red Planet?"] documents = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", ] query_embeddings = model.encode_query(queries) document_embeddings = model.encode_document(documents) similarities = model.similarity(query_embeddings, document_embeddings) print(similarities) - Notebooks
- Google Colab
- Kaggle
Add API usage
Browse files
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.
|