Thomas Müller commited on
Commit
845a4a0
1 Parent(s): 5229633

Initial 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,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - ar
4
+ - bg
5
+ - de
6
+ - el
7
+ - en
8
+ - es
9
+ - fr
10
+ - ru
11
+ - th
12
+ - tr
13
+ - ur
14
+ - vn
15
+ - zh
16
+ datasets:
17
+ - SNLI
18
+ - MNLI
19
+ - ANLI
20
+ - XNLI
21
+ pipeline_tag: sentence-similarity
22
+ tags:
23
+ - zero-shot-classification
24
+ - sentence-transformers
25
+ - feature-extraction
26
+ - sentence-similarity
27
+ - transformers
28
+ ---
29
+
30
+ # {MODEL_NAME}
31
+
32
+ A Siamese network model trained for zero-shot and few-shot text classification.
33
+
34
+ The base model is [xlm-roberta-base](https://huggingface.co/xlm-roberta-base).
35
+ It was trained on [SNLI](https://nlp.stanford.edu/projects/snli/) and [MNLI](https://cims.nyu.edu/~sbowman/multinli/), [ANLI](https://github.com/facebookresearch/anli) and [XNLI](https://github.com/facebookresearch/XNLI).
36
+
37
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space.
38
+
39
+ ## Usage (Sentence-Transformers)
40
+
41
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
42
+
43
+ ```
44
+ pip install -U sentence-transformers
45
+ ```
46
+
47
+ Then you can use the model like this:
48
+
49
+ ```python
50
+ from sentence_transformers import SentenceTransformer
51
+ sentences = ["This is an example sentence", "Each sentence is converted"]
52
+
53
+ model = SentenceTransformer('{MODEL_NAME}')
54
+ embeddings = model.encode(sentences)
55
+ print(embeddings)
56
+ ```
57
+
58
+
59
+ ## Usage (HuggingFace Transformers)
60
+ 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.
61
+
62
+ ```python
63
+ from transformers import AutoTokenizer, AutoModel
64
+ import torch
65
+
66
+
67
+ #Mean Pooling - Take attention mask into account for correct averaging
68
+ def mean_pooling(model_output, attention_mask):
69
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
70
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
71
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
72
+
73
+
74
+ # Sentences we want sentence embeddings for
75
+ sentences = ['This is an example sentence', 'Each sentence is converted']
76
+
77
+ # Load model from HuggingFace Hub
78
+ tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
79
+ model = AutoModel.from_pretrained('{MODEL_NAME}')
80
+
81
+ # Tokenize sentences
82
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
83
+
84
+ # Compute token embeddings
85
+ with torch.no_grad():
86
+ model_output = model(**encoded_input)
87
+
88
+ # Perform pooling. In this case, max pooling.
89
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
90
+
91
+ print("Sentence embeddings:")
92
+ print(sentence_embeddings)
93
+ ```
config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "xlm-roberta-base",
3
+ "architectures": [
4
+ "XLMRobertaModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "eos_token_id": 2,
9
+ "gradient_checkpointing": false,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 3072,
15
+ "layer_norm_eps": 1e-05,
16
+ "max_position_embeddings": 514,
17
+ "model_type": "xlm-roberta",
18
+ "num_attention_heads": 12,
19
+ "num_hidden_layers": 12,
20
+ "output_past": true,
21
+ "pad_token_id": 1,
22
+ "position_embedding_type": "absolute",
23
+ "transformers_version": "4.6.0",
24
+ "type_vocab_size": 1,
25
+ "use_cache": true,
26
+ "vocab_size": 250002
27
+ }
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:3505e3293a6fa0622d7eb4a0c261c7cbe1f21d6dbbeab0826f08ceb78b69a507
3
+ size 1112259141
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ {
2
+ "max_seq_length": 128,
3
+ "do_lower_case": false
4
+ }
sentencepiece.bpe.model ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
3
+ size 5069051
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
+ {"bos_token": "<s>", "eos_token": "</s>", "sep_token": "</s>", "cls_token": "<s>", "unk_token": "<unk>", "pad_token": "<pad>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "xlm-roberta-base"}