Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +39 -3
README.md CHANGED
@@ -1,6 +1,7 @@
1
  ---
2
  tags:
3
  - ColBERT
 
4
  - PyLate
5
  - sentence-transformers
6
  - sentence-similarity
@@ -485,14 +486,14 @@ colgrep set-model lightonai/LateOn-Code # default: lightonai/LateOn-Code-edge
485
  For more information about ColGrep, please refer to the [official documentation](https://github.com/lightonai/next-plaid/tree/main/colgrep)
486
 
487
 
488
- # PyLate
489
 
490
- This is a [PyLate](https://github.com/lightonai/pylate) model finetuned from [lightonai/LateOn-Code-pretrain](https://huggingface.co/lightonai/LateOn-Code-pretrain) on the [apps](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [synthetictext2sql](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [cosqa](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codefeedbackst](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codefeedbackmt](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [stackoverflowqa](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codetranscontest](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codetransdl](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_go](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_java](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_javascript](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_php](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_python](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ruby](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_go](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_java](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_javascript](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_php](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_python](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code) and [CodeSearchNet_ccr_ruby](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code) datasets. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
491
 
492
  ## Model Details
493
 
494
  ### Model Description
495
- - **Model Type:** PyLate model
496
  <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
497
  - **Document Length:** 2048 tokens
498
  - **Query Length:** 256 tokens
@@ -538,6 +539,41 @@ ColBERT(
538
  ```
539
 
540
  ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  First install the PyLate library:
542
 
543
  ```bash
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
486
  For more information about ColGrep, please refer to the [official documentation](https://github.com/lightonai/next-plaid/tree/main/colgrep)
487
 
488
 
489
+ # Model
490
 
491
+ This is a multi-vector (ColBERT-style late interaction) embedding model finetuned from [lightonai/LateOn-Code-pretrain](https://huggingface.co/lightonai/LateOn-Code-pretrain) on the [apps](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [synthetictext2sql](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [cosqa](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codefeedbackst](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codefeedbackmt](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [stackoverflowqa](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codetranscontest](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [codetransdl](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_go](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_java](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_javascript](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_php](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_python](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ruby](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_go](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_java](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_javascript](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_php](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code), [CodeSearchNet_ccr_python](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code) and [CodeSearchNet_ccr_ruby](https://huggingface.co/datasets/lightonai/nv-embed-supervised-distill-dedup-code) datasets. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
492
 
493
  ## Model Details
494
 
495
  ### Model Description
496
+ - **Model Type:** Multi-vector embedding model
497
  <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
498
  - **Document Length:** 2048 tokens
499
  - **Query Length:** 256 tokens
 
539
  ```
540
 
541
  ## Usage
542
+
543
+ ### Sentence Transformers
544
+
545
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
546
+
547
+ ```bash
548
+ pip install "sentence-transformers>=6.0.0"
549
+ ```
550
+
551
+ ```python
552
+ from sentence_transformers import MultiVectorEncoder
553
+
554
+ model = MultiVectorEncoder("lightonai/LateOn-Code")
555
+
556
+ query = "Which planet is known as the Red Planet?"
557
+ documents = [
558
+ "Venus is often called Earth's twin because of its similar size and proximity.",
559
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
560
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
561
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
562
+ ]
563
+
564
+ query_embeddings = model.encode_query(query)
565
+ document_embeddings = model.encode_document(documents)
566
+ print(query_embeddings.shape, document_embeddings[0].shape)
567
+ # (12, 128) (18, 128)
568
+
569
+ # MaxSim late-interaction scoring (higher is more relevant)
570
+ scores = model.similarity(query_embeddings, document_embeddings)
571
+ print(scores)
572
+ # tensor([[4.7803, 8.2878, 6.5700, 7.0952]])
573
+ ```
574
+
575
+ ### PyLate
576
+
577
  First install the PyLate library:
578
 
579
  ```bash