ramnathv commited on
Commit
1a856a5
1 Parent(s): 60fa148

Add new SentenceTransformer model.

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
1_Pooling/config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
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
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false
9
+ }
README.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ license: apache-2.0
4
+ language:
5
+ - cs
6
+ - da
7
+ - de
8
+ - en
9
+ - es
10
+ - fi
11
+ - fr
12
+ - he
13
+ - hr
14
+ - hu
15
+ - id
16
+ - it
17
+ - nl
18
+ - 'no'
19
+ - pl
20
+ - pt
21
+ - ro
22
+ - ru
23
+ - sv
24
+ - tr
25
+ - vi
26
+ tags:
27
+ - sentence-transformers
28
+ - feature-extraction
29
+ - sentence-similarity
30
+ - transformers
31
+ datasets:
32
+ - clips/mfaq
33
+ widget:
34
+ - text: "<Q>How many models can I host on HuggingFace?"
35
+ example_title: source_sentence
36
+ ---
37
+
38
+ # MFAQ
39
+
40
+ We present a multilingual FAQ retrieval model trained on the [MFAQ dataset](https://huggingface.co/datasets/clips/mfaq), it ranks candidate answers according to a given question.
41
+
42
+ ## Installation
43
+
44
+ ```
45
+ pip install sentence-transformers transformers
46
+ ```
47
+
48
+ ## Usage
49
+ You can use MFAQ with sentence-transformers or directly with a HuggingFace model.
50
+ In both cases, questions need to be prepended with `<Q>`, and answers with `<A>`.
51
+
52
+ #### Sentence Transformers
53
+ ```python
54
+ from sentence_transformers import SentenceTransformer
55
+
56
+ question = "<Q>How many models can I host on HuggingFace?"
57
+ answer_1 = "<A>All plans come with unlimited private models and datasets."
58
+ answer_2 = "<A>AutoNLP is an automatic way to train and deploy state-of-the-art NLP models, seamlessly integrated with the Hugging Face ecosystem."
59
+ answer_3 = "<A>Based on how much training data and model variants are created, we send you a compute cost and payment link - as low as $10 per job."
60
+
61
+ model = SentenceTransformer('clips/mfaq')
62
+ embeddings = model.encode([question, answer_1, answer_3, answer_3])
63
+ print(embeddings)
64
+ ```
65
+
66
+ #### HuggingFace Transformers
67
+
68
+ ```python
69
+ from transformers import AutoTokenizer, AutoModel
70
+ import torch
71
+
72
+ def mean_pooling(model_output, attention_mask):
73
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
74
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
75
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
76
+
77
+ question = "<Q>How many models can I host on HuggingFace?"
78
+ answer_1 = "<A>All plans come with unlimited private models and datasets."
79
+ answer_2 = "<A>AutoNLP is an automatic way to train and deploy state-of-the-art NLP models, seamlessly integrated with the Hugging Face ecosystem."
80
+ answer_3 = "<A>Based on how much training data and model variants are created, we send you a compute cost and payment link - as low as $10 per job."
81
+
82
+ tokenizer = AutoTokenizer.from_pretrained('clips/mfaq')
83
+ model = AutoModel.from_pretrained('clips/mfaq')
84
+
85
+ # Tokenize sentences
86
+ encoded_input = tokenizer([question, answer_1, answer_3, answer_3], padding=True, truncation=True, return_tensors='pt')
87
+
88
+ # Compute token embeddings
89
+ with torch.no_grad():
90
+ model_output = model(**encoded_input)
91
+
92
+ # Perform pooling. In this case, max pooling.
93
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
94
+ ```
95
+
96
+ ## Training
97
+ You can find the training script for the model [here](https://github.com/clips/mfaq).
98
+
99
+ ## People
100
+ This model was developed by [Maxime De Bruyn](https://www.linkedin.com/in/maximedebruyn/), Ehsan Lotfi, Jeska Buhmann and Walter Daelemans.
101
+
102
+ ## Citation information
103
+ ```
104
+ @misc{debruyn2021mfaq,
105
+ title={MFAQ: a Multilingual FAQ Dataset},
106
+ author={Maxime De Bruyn and Ehsan Lotfi and Jeska Buhmann and Walter Daelemans},
107
+ year={2021},
108
+ eprint={2109.12870},
109
+ archivePrefix={arXiv},
110
+ primaryClass={cs.CL}
111
+ }
112
+ ```
added_tokens.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "<A>": 250003,
3
+ "<Q>": 250002,
4
+ "<link>": 250004
5
+ }
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "clips-mfaq-test/",
3
+ "architectures": [
4
+ "XLMRobertaModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.25,
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
+ "tokenizer_class": "XLMRobertaTokenizerFast",
24
+ "torch_dtype": "float32",
25
+ "transformers_version": "4.35.2",
26
+ "type_vocab_size": 1,
27
+ "use_cache": true,
28
+ "vocab_size": 250005
29
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.10.2",
5
+ "pytorch": "1.9.0"
6
+ }
7
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c18b358dbd0bbf823fb81ba9f0df77ed11f19ae1bb6ba900489189c4ea9b6780
3
+ size 1112206312
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
+ ]
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,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<Q>",
4
+ "<A>",
5
+ "<link>"
6
+ ],
7
+ "bos_token": {
8
+ "content": "<s>",
9
+ "lstrip": false,
10
+ "normalized": false,
11
+ "rstrip": false,
12
+ "single_word": false
13
+ },
14
+ "cls_token": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "eos_token": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false
27
+ },
28
+ "mask_token": {
29
+ "content": "<mask>",
30
+ "lstrip": true,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false
34
+ },
35
+ "pad_token": {
36
+ "content": "<pad>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false
41
+ },
42
+ "sep_token": {
43
+ "content": "</s>",
44
+ "lstrip": false,
45
+ "normalized": false,
46
+ "rstrip": false,
47
+ "single_word": false
48
+ },
49
+ "unk_token": {
50
+ "content": "<unk>",
51
+ "lstrip": false,
52
+ "normalized": false,
53
+ "rstrip": false,
54
+ "single_word": false
55
+ }
56
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c202c2904979914d10811ca26aaf9672c41820a3d25cb432040fe1405be30ffb
3
+ size 17083552
tokenizer_config.json ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "250001": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "250002": {
44
+ "content": "<Q>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "250003": {
52
+ "content": "<A>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "250004": {
60
+ "content": "<link>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ }
67
+ },
68
+ "additional_special_tokens": [
69
+ "<Q>",
70
+ "<A>",
71
+ "<link>"
72
+ ],
73
+ "bos_token": "<s>",
74
+ "clean_up_tokenization_spaces": true,
75
+ "cls_token": "<s>",
76
+ "eos_token": "</s>",
77
+ "mask_token": "<mask>",
78
+ "max_length": 128,
79
+ "model_max_length": 128,
80
+ "pad_to_multiple_of": null,
81
+ "pad_token": "<pad>",
82
+ "pad_token_type_id": 0,
83
+ "padding_side": "right",
84
+ "sep_token": "</s>",
85
+ "stride": 0,
86
+ "tokenizer_class": "XLMRobertaTokenizer",
87
+ "truncation_side": "right",
88
+ "truncation_strategy": "longest_first",
89
+ "unk_token": "<unk>"
90
+ }