sentence_transformers_support (#1)
Browse files- Add support for Sentence Transformer (6da74ca1f33306288d1c05b67d283393d6867906)
- Adapt to the new naming of IDF (b4f72ca312ca0573d19ca5305f9776ceac8f0c69)
- README.md +47 -0
- config_sentence_transformers.json +14 -0
- document_1_SpladePooling/config.json +5 -0
- modules.json +8 -0
- query_0_SparseStaticEmbedding/config.json +3 -0
- query_0_SparseStaticEmbedding/model.safetensors +3 -0
- query_0_SparseStaticEmbedding/special_tokens_map.json +37 -0
- query_0_SparseStaticEmbedding/tokenizer.json +0 -0
- query_0_SparseStaticEmbedding/tokenizer_config.json +63 -0
- query_0_SparseStaticEmbedding/vocab.txt +0 -0
- router_config.json +20 -0
- sentence_bert_config.json +4 -0
    	
        README.md
    CHANGED
    
    | @@ -9,6 +9,13 @@ tags: | |
| 9 | 
             
            - passage-retrieval
         | 
| 10 | 
             
            - document-expansion
         | 
| 11 | 
             
            - bag-of-words
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 12 | 
             
            ---
         | 
| 13 |  | 
| 14 | 
             
            # opensearch-neural-sparse-encoding-doc-v3-gte
         | 
| @@ -40,6 +47,46 @@ The training datasets includes MS MARCO, eli5_question_answer, squad_pairs, Wiki | |
| 40 |  | 
| 41 | 
             
            OpenSearch neural sparse feature supports learned sparse retrieval with lucene inverted index. Link: https://opensearch.org/docs/latest/query-dsl/specialized/neural-sparse/. The indexing and search can be performed with OpenSearch high-level API.
         | 
| 42 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 43 |  | 
| 44 | 
             
            ## Usage (HuggingFace)
         | 
| 45 | 
             
            This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API. 
         | 
|  | |
| 9 | 
             
            - passage-retrieval
         | 
| 10 | 
             
            - document-expansion
         | 
| 11 | 
             
            - bag-of-words
         | 
| 12 | 
            +
            - sentence-transformers
         | 
| 13 | 
            +
            - sparse-encoder
         | 
| 14 | 
            +
            - sparse
         | 
| 15 | 
            +
            - asymmetric
         | 
| 16 | 
            +
            - inference-free
         | 
| 17 | 
            +
            pipeline_tag: feature-extraction
         | 
| 18 | 
            +
            library_name: sentence-transformers
         | 
| 19 | 
             
            ---
         | 
| 20 |  | 
| 21 | 
             
            # opensearch-neural-sparse-encoding-doc-v3-gte
         | 
|  | |
| 47 |  | 
| 48 | 
             
            OpenSearch neural sparse feature supports learned sparse retrieval with lucene inverted index. Link: https://opensearch.org/docs/latest/query-dsl/specialized/neural-sparse/. The indexing and search can be performed with OpenSearch high-level API.
         | 
| 49 |  | 
| 50 | 
            +
            ## Usage (Sentence Transformers)
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            First install the Sentence Transformers library:
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            ```bash
         | 
| 55 | 
            +
            pip install -U sentence-transformers
         | 
| 56 | 
            +
            ```
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            Then you can load this model and run inference.
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            ```python
         | 
| 61 | 
            +
            from sentence_transformers.sparse_encoder import SparseEncoder
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            # Download from the 🤗 Hub
         | 
| 64 | 
            +
            model = SparseEncoder("opensearch-project/opensearch-neural-sparse-encoding-doc-v3-distill")
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            query = "What's the weather in ny now?"
         | 
| 67 | 
            +
            document = "Currently New York is rainy."
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            query_embed = model.encode_query(query)
         | 
| 70 | 
            +
            document_embed = model.encode_document(document)
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            sim = model.similarity(query_embed, document_embed)
         | 
| 73 | 
            +
            print(f"Similarity: {sim}")
         | 
| 74 | 
            +
            # Similarity: tensor([[12.5747]])
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            decoded_query = model.decode(query_embed)
         | 
| 77 | 
            +
            decoded_document = model.decode(document_embed)
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            for i in range(len(decoded_query)):
         | 
| 80 | 
            +
                query_token, query_score = decoded_query[i]
         | 
| 81 | 
            +
                doc_score = next((score for token, score in decoded_document if token == query_token), 0)
         | 
| 82 | 
            +
                if doc_score != 0:
         | 
| 83 | 
            +
                    print(f"Token: {query_token}, Query score: {query_score:.4f}, Document score: {doc_score:.4f}")
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            # Token: ny, Query score: 5.7729, Document score: 0.9703
         | 
| 86 | 
            +
            # Token: weather, Query score: 4.5684, Document score: 1.0387
         | 
| 87 | 
            +
            # Token: now, Query score: 3.5895, Document score: 0.5861
         | 
| 88 | 
            +
            # Token: in, Query score: 0.4989, Document score: 0.2494
         | 
| 89 | 
            +
            ```
         | 
| 90 |  | 
| 91 | 
             
            ## Usage (HuggingFace)
         | 
| 92 | 
             
            This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API. 
         | 
    	
        config_sentence_transformers.json
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "model_type": "SparseEncoder",
         | 
| 3 | 
            +
              "__version__": {
         | 
| 4 | 
            +
                "sentence_transformers": "5.0.0",
         | 
| 5 | 
            +
                "transformers": "4.50.3",
         | 
| 6 | 
            +
                "pytorch": "2.6.0+cu124"
         | 
| 7 | 
            +
              },
         | 
| 8 | 
            +
              "prompts": {
         | 
| 9 | 
            +
                "query": "",
         | 
| 10 | 
            +
                "document": ""
         | 
| 11 | 
            +
              },
         | 
| 12 | 
            +
              "default_prompt_name": null,
         | 
| 13 | 
            +
              "similarity_fn_name": "dot"
         | 
| 14 | 
            +
            }
         | 
    	
        document_1_SpladePooling/config.json
    ADDED
    
    | @@ -0,0 +1,5 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "pooling_strategy": "max",
         | 
| 3 | 
            +
                "activation_function": "log1p_relu",
         | 
| 4 | 
            +
                "word_embedding_dimension": null
         | 
| 5 | 
            +
            }
         | 
    	
        modules.json
    ADDED
    
    | @@ -0,0 +1,8 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            [
         | 
| 2 | 
            +
              {
         | 
| 3 | 
            +
                "idx": 0,
         | 
| 4 | 
            +
                "name": "0",
         | 
| 5 | 
            +
                "path": "",
         | 
| 6 | 
            +
                "type": "sentence_transformers.models.Router"
         | 
| 7 | 
            +
              }
         | 
| 8 | 
            +
            ]
         | 
    	
        query_0_SparseStaticEmbedding/config.json
    ADDED
    
    | @@ -0,0 +1,3 @@ | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "frozen": false
         | 
| 3 | 
            +
            }
         | 
    	
        query_0_SparseStaticEmbedding/model.safetensors
    ADDED
    
    | @@ -0,0 +1,3 @@ | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            version https://git-lfs.github.com/spec/v1
         | 
| 2 | 
            +
            oid sha256:711ec64837a7962d2ae106996079782b7ee87860089a0b2348bf7cb840f252d3
         | 
| 3 | 
            +
            size 122168
         | 
    	
        query_0_SparseStaticEmbedding/special_tokens_map.json
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "cls_token": {
         | 
| 3 | 
            +
                "content": "[CLS]",
         | 
| 4 | 
            +
                "lstrip": false,
         | 
| 5 | 
            +
                "normalized": false,
         | 
| 6 | 
            +
                "rstrip": false,
         | 
| 7 | 
            +
                "single_word": false
         | 
| 8 | 
            +
              },
         | 
| 9 | 
            +
              "mask_token": {
         | 
| 10 | 
            +
                "content": "[MASK]",
         | 
| 11 | 
            +
                "lstrip": false,
         | 
| 12 | 
            +
                "normalized": false,
         | 
| 13 | 
            +
                "rstrip": false,
         | 
| 14 | 
            +
                "single_word": false
         | 
| 15 | 
            +
              },
         | 
| 16 | 
            +
              "pad_token": {
         | 
| 17 | 
            +
                "content": "[PAD]",
         | 
| 18 | 
            +
                "lstrip": false,
         | 
| 19 | 
            +
                "normalized": false,
         | 
| 20 | 
            +
                "rstrip": false,
         | 
| 21 | 
            +
                "single_word": false
         | 
| 22 | 
            +
              },
         | 
| 23 | 
            +
              "sep_token": {
         | 
| 24 | 
            +
                "content": "[SEP]",
         | 
| 25 | 
            +
                "lstrip": false,
         | 
| 26 | 
            +
                "normalized": false,
         | 
| 27 | 
            +
                "rstrip": false,
         | 
| 28 | 
            +
                "single_word": false
         | 
| 29 | 
            +
              },
         | 
| 30 | 
            +
              "unk_token": {
         | 
| 31 | 
            +
                "content": "[UNK]",
         | 
| 32 | 
            +
                "lstrip": false,
         | 
| 33 | 
            +
                "normalized": false,
         | 
| 34 | 
            +
                "rstrip": false,
         | 
| 35 | 
            +
                "single_word": false
         | 
| 36 | 
            +
              }
         | 
| 37 | 
            +
            }
         | 
    	
        query_0_SparseStaticEmbedding/tokenizer.json
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        query_0_SparseStaticEmbedding/tokenizer_config.json
    ADDED
    
    | @@ -0,0 +1,63 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "added_tokens_decoder": {
         | 
| 3 | 
            +
                "0": {
         | 
| 4 | 
            +
                  "content": "[PAD]",
         | 
| 5 | 
            +
                  "lstrip": false,
         | 
| 6 | 
            +
                  "normalized": false,
         | 
| 7 | 
            +
                  "rstrip": false,
         | 
| 8 | 
            +
                  "single_word": false,
         | 
| 9 | 
            +
                  "special": true
         | 
| 10 | 
            +
                },
         | 
| 11 | 
            +
                "100": {
         | 
| 12 | 
            +
                  "content": "[UNK]",
         | 
| 13 | 
            +
                  "lstrip": false,
         | 
| 14 | 
            +
                  "normalized": false,
         | 
| 15 | 
            +
                  "rstrip": false,
         | 
| 16 | 
            +
                  "single_word": false,
         | 
| 17 | 
            +
                  "special": true
         | 
| 18 | 
            +
                },
         | 
| 19 | 
            +
                "101": {
         | 
| 20 | 
            +
                  "content": "[CLS]",
         | 
| 21 | 
            +
                  "lstrip": false,
         | 
| 22 | 
            +
                  "normalized": false,
         | 
| 23 | 
            +
                  "rstrip": false,
         | 
| 24 | 
            +
                  "single_word": false,
         | 
| 25 | 
            +
                  "special": true
         | 
| 26 | 
            +
                },
         | 
| 27 | 
            +
                "102": {
         | 
| 28 | 
            +
                  "content": "[SEP]",
         | 
| 29 | 
            +
                  "lstrip": false,
         | 
| 30 | 
            +
                  "normalized": false,
         | 
| 31 | 
            +
                  "rstrip": false,
         | 
| 32 | 
            +
                  "single_word": false,
         | 
| 33 | 
            +
                  "special": true
         | 
| 34 | 
            +
                },
         | 
| 35 | 
            +
                "103": {
         | 
| 36 | 
            +
                  "content": "[MASK]",
         | 
| 37 | 
            +
                  "lstrip": false,
         | 
| 38 | 
            +
                  "normalized": false,
         | 
| 39 | 
            +
                  "rstrip": false,
         | 
| 40 | 
            +
                  "single_word": false,
         | 
| 41 | 
            +
                  "special": true
         | 
| 42 | 
            +
                }
         | 
| 43 | 
            +
              },
         | 
| 44 | 
            +
              "clean_up_tokenization_spaces": true,
         | 
| 45 | 
            +
              "cls_token": "[CLS]",
         | 
| 46 | 
            +
              "do_lower_case": true,
         | 
| 47 | 
            +
              "extra_special_tokens": {},
         | 
| 48 | 
            +
              "mask_token": "[MASK]",
         | 
| 49 | 
            +
              "max_length": 512,
         | 
| 50 | 
            +
              "model_max_length": 512,
         | 
| 51 | 
            +
              "pad_to_multiple_of": null,
         | 
| 52 | 
            +
              "pad_token": "[PAD]",
         | 
| 53 | 
            +
              "pad_token_type_id": 0,
         | 
| 54 | 
            +
              "padding_side": "right",
         | 
| 55 | 
            +
              "sep_token": "[SEP]",
         | 
| 56 | 
            +
              "stride": 0,
         | 
| 57 | 
            +
              "strip_accents": null,
         | 
| 58 | 
            +
              "tokenize_chinese_chars": true,
         | 
| 59 | 
            +
              "tokenizer_class": "DistilBertTokenizer",
         | 
| 60 | 
            +
              "truncation_side": "right",
         | 
| 61 | 
            +
              "truncation_strategy": "longest_first",
         | 
| 62 | 
            +
              "unk_token": "[UNK]"
         | 
| 63 | 
            +
            }
         | 
    	
        query_0_SparseStaticEmbedding/vocab.txt
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        router_config.json
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "types": {
         | 
| 3 | 
            +
                    "query_0_SparseStaticEmbedding": "sentence_transformers.sparse_encoder.models.SparseStaticEmbedding.SparseStaticEmbedding",
         | 
| 4 | 
            +
                    "": "sentence_transformers.sparse_encoder.models.MLMTransformer.MLMTransformer",
         | 
| 5 | 
            +
                    "document_1_SpladePooling": "sentence_transformers.sparse_encoder.models.SpladePooling.SpladePooling"
         | 
| 6 | 
            +
                },
         | 
| 7 | 
            +
                "structure": {
         | 
| 8 | 
            +
                    "query": [
         | 
| 9 | 
            +
                        "query_0_SparseStaticEmbedding"
         | 
| 10 | 
            +
                    ],
         | 
| 11 | 
            +
                    "document": [
         | 
| 12 | 
            +
                        "",
         | 
| 13 | 
            +
                        "document_1_SpladePooling"
         | 
| 14 | 
            +
                    ]
         | 
| 15 | 
            +
                },
         | 
| 16 | 
            +
                "parameters": {
         | 
| 17 | 
            +
                    "default_route": "document",
         | 
| 18 | 
            +
                    "allow_empty_key": true
         | 
| 19 | 
            +
                }
         | 
| 20 | 
            +
            }
         | 
    	
        sentence_bert_config.json
    ADDED
    
    | @@ -0,0 +1,4 @@ | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
                "max_seq_length": 512,
         | 
| 3 | 
            +
                "do_lower_case": false
         | 
| 4 | 
            +
            }
         | 

