initial model add and README.
Browse files- 1_Pooling/config.json +7 -0
- README.md +94 -0
- config.json +26 -0
- config_sentence_transformers.json +7 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
- vocab.txt +0 -0
    	
        1_Pooling/config.json
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "word_embedding_dimension": 768,
         | 
| 3 | 
            +
              "pooling_mode_cls_token": true,
         | 
| 4 | 
            +
              "pooling_mode_mean_tokens": false,
         | 
| 5 | 
            +
              "pooling_mode_max_tokens": false,
         | 
| 6 | 
            +
              "pooling_mode_mean_sqrt_len_tokens": false
         | 
| 7 | 
            +
            }
         | 
    	
        README.md
    ADDED
    
    | @@ -0,0 +1,94 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            pipeline_tag: sentence-similarity
         | 
| 3 | 
            +
            tags:
         | 
| 4 | 
            +
            - sentence-transformers
         | 
| 5 | 
            +
            - feature-extraction
         | 
| 6 | 
            +
            - sentence-similarity
         | 
| 7 | 
            +
            - transformers
         | 
| 8 | 
            +
            datasets:
         | 
| 9 | 
            +
            - wikipedia
         | 
| 10 | 
            +
            - bookcorpus
         | 
| 11 | 
            +
            - ms_marco
         | 
| 12 | 
            +
            ---
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            # nthakur/dragon-plus-context-encoder
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            This is a port of the [facebook/dragon-plus-context-encoder](https://huggingface.co/facebook/dragon-plus-context-encoder) model to [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            <!--- Describe your model here -->
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ## Usage (Sentence-Transformers)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ```
         | 
| 25 | 
            +
            pip install -U sentence-transformers
         | 
| 26 | 
            +
            ```
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            Then you can use the model like this:
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ```python
         | 
| 31 | 
            +
            from sentence_transformers import SentenceTransformer
         | 
| 32 | 
            +
            sentences = ["This is an example sentence", "Each sentence is converted"]
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            model = SentenceTransformer('nthakur/dragon-plus-context-encoder')
         | 
| 35 | 
            +
            embeddings = model.encode(sentences)
         | 
| 36 | 
            +
            print(embeddings)
         | 
| 37 | 
            +
            ```
         | 
| 38 | 
            +
             | 
| 39 | 
            +
             | 
| 40 | 
            +
             | 
| 41 | 
            +
            ## Usage (HuggingFace Transformers)
         | 
| 42 | 
            +
            Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            ```python
         | 
| 45 | 
            +
            from transformers import AutoTokenizer, AutoModel
         | 
| 46 | 
            +
            import torch
         | 
| 47 | 
            +
             | 
| 48 | 
            +
             | 
| 49 | 
            +
            def cls_pooling(model_output, attention_mask):
         | 
| 50 | 
            +
                return model_output[0][:,0]
         | 
| 51 | 
            +
             | 
| 52 | 
            +
             | 
| 53 | 
            +
            # Sentences we want sentence embeddings for
         | 
| 54 | 
            +
            sentences = ['This is an example sentence', 'Each sentence is converted']
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            # Load model from HuggingFace Hub
         | 
| 57 | 
            +
            tokenizer = AutoTokenizer.from_pretrained('nthakur/dragon-plus-context-encoder')
         | 
| 58 | 
            +
            model = AutoModel.from_pretrained('nthakur/dragon-plus-context-encoder')
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            # Tokenize sentences
         | 
| 61 | 
            +
            encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            # Compute token embeddings
         | 
| 64 | 
            +
            with torch.no_grad():
         | 
| 65 | 
            +
                model_output = model(**encoded_input)
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            # Perform pooling. In this case, cls pooling.
         | 
| 68 | 
            +
            sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            print("Sentence embeddings:")
         | 
| 71 | 
            +
            print(sentence_embeddings)
         | 
| 72 | 
            +
            ```
         | 
| 73 | 
            +
             | 
| 74 | 
            +
             | 
| 75 | 
            +
             | 
| 76 | 
            +
            ## Evaluation Results
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            <!--- Describe how your model was evaluated -->
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=nthakur/dragon-plus-context-encoder)
         | 
| 81 | 
            +
             | 
| 82 | 
            +
             | 
| 83 | 
            +
             | 
| 84 | 
            +
            ## Full Model Architecture
         | 
| 85 | 
            +
            ```
         | 
| 86 | 
            +
            SentenceTransformer(
         | 
| 87 | 
            +
              (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel 
         | 
| 88 | 
            +
              (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
         | 
| 89 | 
            +
            )
         | 
| 90 | 
            +
            ```
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            ## Citing & Authors
         | 
| 93 | 
            +
            Have a look at [DRAGON](https://github.com/facebookresearch/dpr-scale/tree/main/dragon).
         | 
| 94 | 
            +
            <!--- Describe where people can find more information -->
         | 
    	
        config.json
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "_name_or_path": "facebook/dragon-plus-context-encoder",
         | 
| 3 | 
            +
              "architectures": [
         | 
| 4 | 
            +
                "BertModel"
         | 
| 5 | 
            +
              ],
         | 
| 6 | 
            +
              "attention_probs_dropout_prob": 0.1,
         | 
| 7 | 
            +
              "classifier_dropout": null,
         | 
| 8 | 
            +
              "gradient_checkpointing": false,
         | 
| 9 | 
            +
              "hidden_act": "gelu",
         | 
| 10 | 
            +
              "hidden_dropout_prob": 0.1,
         | 
| 11 | 
            +
              "hidden_size": 768,
         | 
| 12 | 
            +
              "initializer_range": 0.02,
         | 
| 13 | 
            +
              "intermediate_size": 3072,
         | 
| 14 | 
            +
              "layer_norm_eps": 1e-12,
         | 
| 15 | 
            +
              "max_position_embeddings": 512,
         | 
| 16 | 
            +
              "model_type": "bert",
         | 
| 17 | 
            +
              "num_attention_heads": 12,
         | 
| 18 | 
            +
              "num_hidden_layers": 12,
         | 
| 19 | 
            +
              "pad_token_id": 0,
         | 
| 20 | 
            +
              "position_embedding_type": "absolute",
         | 
| 21 | 
            +
              "torch_dtype": "float32",
         | 
| 22 | 
            +
              "transformers_version": "4.30.2",
         | 
| 23 | 
            +
              "type_vocab_size": 2,
         | 
| 24 | 
            +
              "use_cache": true,
         | 
| 25 | 
            +
              "vocab_size": 30522
         | 
| 26 | 
            +
            }
         | 
    	
        config_sentence_transformers.json
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "__version__": {
         | 
| 3 | 
            +
                "sentence_transformers": "2.2.2",
         | 
| 4 | 
            +
                "transformers": "4.30.2",
         | 
| 5 | 
            +
                "pytorch": "2.0.1+cu117"
         | 
| 6 | 
            +
              }
         | 
| 7 | 
            +
            }
         | 
    	
        modules.json
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            [
         | 
| 2 | 
            +
              {
         | 
| 3 | 
            +
                "idx": 0,
         | 
| 4 | 
            +
                "name": "0",
         | 
| 5 | 
            +
                "path": "",
         | 
| 6 | 
            +
                "type": "sentence_transformers.models.Transformer"
         | 
| 7 | 
            +
              },
         | 
| 8 | 
            +
              {
         | 
| 9 | 
            +
                "idx": 1,
         | 
| 10 | 
            +
                "name": "1",
         | 
| 11 | 
            +
                "path": "1_Pooling",
         | 
| 12 | 
            +
                "type": "sentence_transformers.models.Pooling"
         | 
| 13 | 
            +
              }
         | 
| 14 | 
            +
            ]
         | 
    	
        pytorch_model.bin
    ADDED
    
    | @@ -0,0 +1,3 @@ | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            version https://git-lfs.github.com/spec/v1
         | 
| 2 | 
            +
            oid sha256:ce9a1580e60d4e1f7a1a49b2aeb6138b0eaa9c9b766c1bb6fb7ad60e27f1be2c
         | 
| 3 | 
            +
            size 438000173
         | 
    	
        sentence_bert_config.json
    ADDED
    
    | @@ -0,0 +1,4 @@ | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "max_seq_length": 512,
         | 
| 3 | 
            +
              "do_lower_case": false
         | 
| 4 | 
            +
            }
         | 
    	
        special_tokens_map.json
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "cls_token": "[CLS]",
         | 
| 3 | 
            +
              "mask_token": "[MASK]",
         | 
| 4 | 
            +
              "pad_token": "[PAD]",
         | 
| 5 | 
            +
              "sep_token": "[SEP]",
         | 
| 6 | 
            +
              "unk_token": "[UNK]"
         | 
| 7 | 
            +
            }
         | 
    	
        tokenizer.json
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        tokenizer_config.json
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            {
         | 
| 2 | 
            +
              "clean_up_tokenization_spaces": true,
         | 
| 3 | 
            +
              "cls_token": "[CLS]",
         | 
| 4 | 
            +
              "do_basic_tokenize": true,
         | 
| 5 | 
            +
              "do_lower_case": true,
         | 
| 6 | 
            +
              "mask_token": "[MASK]",
         | 
| 7 | 
            +
              "model_max_length": 1000000000000000019884624838656,
         | 
| 8 | 
            +
              "never_split": null,
         | 
| 9 | 
            +
              "pad_token": "[PAD]",
         | 
| 10 | 
            +
              "sep_token": "[SEP]",
         | 
| 11 | 
            +
              "strip_accents": null,
         | 
| 12 | 
            +
              "tokenize_chinese_chars": true,
         | 
| 13 | 
            +
              "tokenizer_class": "BertTokenizer",
         | 
| 14 | 
            +
              "unk_token": "[UNK]"
         | 
| 15 | 
            +
            }
         | 
    	
        vocab.txt
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
