Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +32 -0
README.md CHANGED
@@ -4,6 +4,8 @@ language:
4
  - en
5
  tags:
6
  - ColBERT
 
 
7
  - sentence-similarity
8
  - feature-extraction
9
  - generated_from_trainer
@@ -20,3 +22,33 @@ pipeline_tag: sentence-similarity
20
  This is a [ColBERT](https://github.com/stanford-futuredata/ColBERT) model finetuned from [google/bert_uncased_L-2_H-128_A-2](https://huggingface.co/google/bert_uncased_L-2_H-128_A-2) on the [msmarco-bm25](https://huggingface.co/datasets/sentence-transformers/msmarco-bm25) dataset. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
21
 
22
  This model is primarily designed for unit tests in limited compute environments such as GitHub Actions. But it does work to an extent for basic use cases.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  - en
5
  tags:
6
  - ColBERT
7
+ - multi-vector
8
+ - sentence-transformers
9
  - sentence-similarity
10
  - feature-extraction
11
  - generated_from_trainer
 
22
  This is a [ColBERT](https://github.com/stanford-futuredata/ColBERT) model finetuned from [google/bert_uncased_L-2_H-128_A-2](https://huggingface.co/google/bert_uncased_L-2_H-128_A-2) on the [msmarco-bm25](https://huggingface.co/datasets/sentence-transformers/msmarco-bm25) dataset. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
23
 
24
  This model is primarily designed for unit tests in limited compute environments such as GitHub Actions. But it does work to an extent for basic use cases.
25
+
26
+ ## Usage with Sentence Transformers
27
+
28
+ As of [Sentence Transformers](https://www.sbert.net/) v6.0.0, this model loads directly as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
29
+
30
+ ```bash
31
+ pip install "sentence-transformers>=6.0.0"
32
+ ```
33
+
34
+ ```python
35
+ from sentence_transformers import MultiVectorEncoder
36
+
37
+ model = MultiVectorEncoder("NeuML/colbert-bert-tiny")
38
+
39
+ query = "What is the capital of France?"
40
+ documents = [
41
+ "Paris is the capital and largest city of France.",
42
+ "Berlin is the capital of Germany.",
43
+ ]
44
+
45
+ query_embeddings = model.encode_query(query)
46
+ document_embeddings = model.encode_document(documents)
47
+ print(query_embeddings.shape, document_embeddings[0].shape)
48
+ # torch.Size([32, 128]) torch.Size([12, 128])
49
+
50
+ # MaxSim late-interaction scoring (higher is more relevant)
51
+ scores = model.similarity(query_embeddings, document_embeddings)
52
+ print(scores)
53
+ # tensor([[25.9327, 23.9168]], device='cuda:0')
54
+ ```