Feature Extraction
sentence-transformers
PyTorch
Safetensors
English
roberta
language
granite
embeddings
sparse-encoder
sparse
splade
text-embeddings-inference
Instructions to use ibm-granite/granite-embedding-30m-sparse with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use ibm-granite/granite-embedding-30m-sparse with sentence-transformers:
from sentence_transformers import SparseEncoder model = SparseEncoder("ibm-granite/granite-embedding-30m-sparse") 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
Update README.md
Browse filesFixed the model name and sparse vector format
README.md
CHANGED
|
@@ -68,7 +68,7 @@ client.create_collection(
|
|
| 68 |
)
|
| 69 |
|
| 70 |
embeddings_model = model.sparse.SpladeEmbeddingFunction(
|
| 71 |
-
model_name="ibm-granite/granite-embedding-30m-sparse
|
| 72 |
device="cpu",
|
| 73 |
batch_size=2,
|
| 74 |
k_tokens_query=50,
|
|
@@ -81,7 +81,11 @@ docs = [
|
|
| 81 |
"Alan Turing was the first person to conduct substantial research in AI.",
|
| 82 |
"Born in Maida Vale, London, Turing was raised in southern England.",
|
| 83 |
]
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
client.insert(
|
| 87 |
collection_name="my_sparse_collection",
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
embeddings_model = model.sparse.SpladeEmbeddingFunction(
|
| 71 |
+
model_name="ibm-granite/granite-embedding-30m-sparse",
|
| 72 |
device="cpu",
|
| 73 |
batch_size=2,
|
| 74 |
k_tokens_query=50,
|
|
|
|
| 81 |
"Alan Turing was the first person to conduct substantial research in AI.",
|
| 82 |
"Born in Maida Vale, London, Turing was raised in southern England.",
|
| 83 |
]
|
| 84 |
+
|
| 85 |
+
# SpladeEmbeddingFunction.encode_documents returns sparse matrix or sparse array depending
|
| 86 |
+
# on the milvus-model version. reshape(1,-1) ensures the format is correct for ingestion.
|
| 87 |
+
doc_vector = [{"embeddings": doc_emb.reshape(1,-1), "id": f"item_{i}"} for i, doc_emb in enumerate(embeddings_model.encode_documents(docs))]
|
| 88 |
+
|
| 89 |
|
| 90 |
client.insert(
|
| 91 |
collection_name="my_sparse_collection",
|