Thomas Müller commited on
Commit
0b6e31e
1 Parent(s): ef19b2f

Init commit.

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
README.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ datasets:
5
+ - SNLI
6
+ - MNLI
7
+ pipeline_tag: sentence-similarity
8
+ tags:
9
+ - zero-shot-classification
10
+ - sentence-transformers
11
+ - feature-extraction
12
+ - sentence-similarity
13
+ - transformers
14
+ ---
15
+
16
+ A Siamese network model trained for zero-shot and few-shot text classification.
17
+
18
+ The base model is [mpnet-base](https://huggingface.co/microsoft/mpnet-base).
19
+ It was trained on [SNLI](https://nlp.stanford.edu/projects/snli/) and [MNLI](https://cims.nyu.edu/~sbowman/multinli/).
20
+
21
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space.
22
+
23
+ ## Usage (Sentence-Transformers)
24
+
25
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
26
+
27
+ ```
28
+ pip install -U sentence-transformers
29
+ ```
30
+
31
+ Then you can use the model like this:
32
+
33
+ ```python
34
+ from sentence_transformers import SentenceTransformer
35
+ sentences = ["This is an example sentence", "Each sentence is converted"]
36
+
37
+ model = SentenceTransformer('{MODEL_NAME}')
38
+ embeddings = model.encode(sentences)
39
+ print(embeddings)
40
+ ```
41
+
42
+
43
+ ## Usage (HuggingFace Transformers)
44
+ 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.
45
+
46
+ ```python
47
+ from transformers import AutoTokenizer, AutoModel
48
+ import torch
49
+
50
+
51
+ #Mean Pooling - Take attention mask into account for correct averaging
52
+ def mean_pooling(model_output, attention_mask):
53
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
54
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
55
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
56
+
57
+
58
+ # Sentences we want sentence embeddings for
59
+ sentences = ['This is an example sentence', 'Each sentence is converted']
60
+
61
+ # Load model from HuggingFace Hub
62
+ tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
63
+ model = AutoModel.from_pretrained('{MODEL_NAME}')
64
+
65
+ # Tokenize sentences
66
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
67
+
68
+ # Compute token embeddings
69
+ with torch.no_grad():
70
+ model_output = model(**encoded_input)
71
+
72
+ # Perform pooling. In this case, max pooling.
73
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
74
+
75
+ print("Sentence embeddings:")
76
+ print(sentence_embeddings)
77
+ ```
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/mpnet-base",
3
+ "architectures": [
4
+ "MPNetModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "eos_token_id": 2,
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-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "mpnet",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "relative_attention_num_buckets": 32,
21
+ "transformers_version": "4.6.0",
22
+ "vocab_size": 30527
23
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.6.0",
5
+ "pytorch": "1.7.0"
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:1c83f1bfd69577fa7210ba31a94b019b6a3f0112a2aa79a99bff92261a92cecf
3
+ size 438028807
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 128,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "[UNK]", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"do_lower_case": true, "bos_token": "<s>", "eos_token": "</s>", "sep_token": "</s>", "cls_token": "<s>", "unk_token": "[UNK]", "pad_token": "<pad>", "mask_token": "<mask>", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "microsoft/mpnet-base"}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff