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
@@ -486,14 +487,14 @@ colgrep set-model lightonai/LateOn-Code # default: lightonai/LateOn-Code-edge
486
  For more information about ColGrep, please refer to the [official documentation](https://github.com/lightonai/next-plaid/tree/main/colgrep)
487
 
488
 
489
- # PyLate
490
 
491
- This is a [PyLate](https://github.com/lightonai/pylate) model finetuned from [lightonai/LateOn-Code-edge-pretrain](https://huggingface.co/lightonai/LateOn-Code-edge-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 48-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:** PyLate model
497
  <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
498
  - **Document Length:** 2048 tokens
499
  - **Query Length:** 256 tokens
@@ -540,6 +541,41 @@ ColBERT(
540
  ```
541
 
542
  ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  First install the PyLate library:
544
 
545
  ```bash
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
487
  For more information about ColGrep, please refer to the [official documentation](https://github.com/lightonai/next-plaid/tree/main/colgrep)
488
 
489
 
490
+ # Model
491
 
492
+ This is a multi-vector (ColBERT-style late interaction) embedding model finetuned from [lightonai/LateOn-Code-edge-pretrain](https://huggingface.co/lightonai/LateOn-Code-edge-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 48-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
493
 
494
  ## Model Details
495
 
496
  ### Model Description
497
+ - **Model Type:** Multi-vector embedding model
498
  <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
499
  - **Document Length:** 2048 tokens
500
  - **Query Length:** 256 tokens
 
541
  ```
542
 
543
  ## Usage
544
+
545
+ ### Sentence Transformers
546
+
547
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
548
+
549
+ ```bash
550
+ pip install "sentence-transformers>=6.0.0"
551
+ ```
552
+
553
+ ```python
554
+ from sentence_transformers import MultiVectorEncoder
555
+
556
+ model = MultiVectorEncoder("lightonai/LateOn-Code-edge")
557
+
558
+ query = "Which planet is known as the Red Planet?"
559
+ documents = [
560
+ "Venus is often called Earth's twin because of its similar size and proximity.",
561
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
562
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
563
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
564
+ ]
565
+
566
+ query_embeddings = model.encode_query(query)
567
+ document_embeddings = model.encode_document(documents)
568
+ print(query_embeddings.shape, document_embeddings[0].shape)
569
+ # (12, 48) (18, 48)
570
+
571
+ # MaxSim late-interaction scoring (higher is more relevant)
572
+ scores = model.similarity(query_embeddings, document_embeddings)
573
+ print(scores)
574
+ # tensor([[4.7185, 7.8521, 7.0537, 7.3523]])
575
+ ```
576
+
577
+ ### PyLate
578
+
579
  First install the PyLate library:
580
 
581
  ```bash