deetsml commited on
Commit
45844c3
·
1 Parent(s): e19cd9a

Add SetFit model

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 1024,
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,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - text-classification
4
+ - transformers
5
+ language:
6
+ - en
7
+ metrics:
8
+ - accuracy
9
+ - precision
10
+ - recall
11
+ library_name: transformers
12
+ pipeline_tag: text-classification
13
+ ---
14
+
15
+ # {MODEL_NAME}
16
+
17
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
18
+
19
+ <!--- Describe your model here -->
20
+
21
+ ## Usage (Sentence-Transformers)
22
+
23
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
24
+
25
+ ```
26
+ pip install -U sentence-transformers
27
+ ```
28
+
29
+ Then you can use the model like this:
30
+
31
+ ```python
32
+ from sentence_transformers import SentenceTransformer
33
+ sentences = ["This is an example sentence", "Each sentence is converted"]
34
+
35
+ model = SentenceTransformer('{MODEL_NAME}')
36
+ embeddings = model.encode(sentences)
37
+ print(embeddings)
38
+ ```
39
+
40
+
41
+
42
+ ## Usage (HuggingFace Transformers)
43
+ 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.
44
+
45
+ ```python
46
+ from transformers import AutoTokenizer, AutoModel
47
+ import torch
48
+
49
+
50
+ #Mean Pooling - Take attention mask into account for correct averaging
51
+ def mean_pooling(model_output, attention_mask):
52
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
53
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
54
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
55
+
56
+
57
+ # Sentences we want sentence embeddings for
58
+ sentences = ['This is an example sentence', 'Each sentence is converted']
59
+
60
+ # Load model from HuggingFace Hub
61
+ tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
62
+ model = AutoModel.from_pretrained('{MODEL_NAME}')
63
+
64
+ # Tokenize sentences
65
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
66
+
67
+ # Compute token embeddings
68
+ with torch.no_grad():
69
+ model_output = model(**encoded_input)
70
+
71
+ # Perform pooling. In this case, mean pooling.
72
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
73
+
74
+ print("Sentence embeddings:")
75
+ print(sentence_embeddings)
76
+ ```
77
+
78
+
79
+
80
+ ## Evaluation Results
81
+
82
+ <!--- Describe how your model was evaluated -->
83
+
84
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
85
+
86
+
87
+ ## Training
88
+ The model was trained with the parameters:
89
+
90
+ **DataLoader**:
91
+
92
+ `torch.utils.data.dataloader.DataLoader` of length 14756 with parameters:
93
+ ```
94
+ {'batch_size': 4, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
95
+ ```
96
+
97
+ **Loss**:
98
+
99
+ `sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
100
+
101
+ Parameters of the fit()-Method:
102
+ ```
103
+ {
104
+ "epochs": 1,
105
+ "evaluation_steps": 0,
106
+ "evaluator": "NoneType",
107
+ "max_grad_norm": 1,
108
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
109
+ "optimizer_params": {
110
+ "lr": 2e-05
111
+ },
112
+ "scheduler": "WarmupLinear",
113
+ "steps_per_epoch": 14756,
114
+ "warmup_steps": 1476,
115
+ "weight_decay": 0.01
116
+ }
117
+ ```
118
+
119
+
120
+ ## Full Model Architecture
121
+ ```
122
+ SentenceTransformer(
123
+ (0): Transformer({'max_seq_length': 1024, 'do_lower_case': False}) with Transformer model: BartModel
124
+ (1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
125
+ )
126
+ ```
127
+
128
+ ## Citing & Authors
129
+
130
+ <!--- Describe where people can find more information -->
config.json ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/MyDrive/Mamoona/Huggingface_model/HIMsetfitMultiLabelModel2epochs/",
3
+ "_num_labels": 36,
4
+ "activation_dropout": 0.0,
5
+ "activation_function": "gelu",
6
+ "add_final_layer_norm": false,
7
+ "architectures": [
8
+ "BartModel"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "bos_token_id": 0,
12
+ "classif_dropout": 0.0,
13
+ "classifier_dropout": 0.0,
14
+ "d_model": 1024,
15
+ "decoder_attention_heads": 16,
16
+ "decoder_ffn_dim": 4096,
17
+ "decoder_layerdrop": 0.0,
18
+ "decoder_layers": 12,
19
+ "decoder_start_token_id": 2,
20
+ "dropout": 0.1,
21
+ "encoder_attention_heads": 16,
22
+ "encoder_ffn_dim": 4096,
23
+ "encoder_layerdrop": 0.0,
24
+ "encoder_layers": 12,
25
+ "eos_token_id": 2,
26
+ "forced_eos_token_id": 2,
27
+ "gradient_checkpointing": false,
28
+ "id2label": {
29
+ "0": "atmosphere",
30
+ "1": "beer list",
31
+ "2": "bottomless brunch",
32
+ "3": "breakfast",
33
+ "4": "brunch",
34
+ "5": "business",
35
+ "6": "byob",
36
+ "7": "casual",
37
+ "8": "date night",
38
+ "9": "delivery",
39
+ "10": "fine dining",
40
+ "11": "gluten free",
41
+ "12": "good value",
42
+ "13": "great cocktails",
43
+ "14": "great service",
44
+ "15": "happy hour",
45
+ "16": "healthy",
46
+ "17": "instagrammable",
47
+ "18": "kid friendly",
48
+ "19": "large groups",
49
+ "20": "late night",
50
+ "21": "live music",
51
+ "22": "lunch",
52
+ "23": "night out",
53
+ "24": "outdoor seating",
54
+ "25": "quick",
55
+ "26": "romantic",
56
+ "27": "rooftop",
57
+ "28": "small plates",
58
+ "29": "special event",
59
+ "30": "sports/tvs",
60
+ "31": "takeout",
61
+ "32": "tasting menu",
62
+ "33": "vegetarian",
63
+ "34": "walk-in",
64
+ "35": "wine list"
65
+ },
66
+ "init_std": 0.02,
67
+ "is_encoder_decoder": true,
68
+ "label2id": {
69
+ "atmosphere": 0,
70
+ "beer list": 1,
71
+ "bottomless brunch": 2,
72
+ "breakfast": 3,
73
+ "brunch": 4,
74
+ "business": 5,
75
+ "byob": 6,
76
+ "casual": 7,
77
+ "date night": 8,
78
+ "delivery": 9,
79
+ "fine dining": 10,
80
+ "gluten free": 11,
81
+ "good value": 12,
82
+ "great cocktails": 13,
83
+ "great service": 14,
84
+ "happy hour": 15,
85
+ "healthy": 16,
86
+ "instagrammable": 17,
87
+ "kid friendly": 18,
88
+ "large groups": 19,
89
+ "late night": 20,
90
+ "live music": 21,
91
+ "lunch": 22,
92
+ "night out": 23,
93
+ "outdoor seating": 24,
94
+ "quick": 25,
95
+ "romantic": 26,
96
+ "rooftop": 27,
97
+ "small plates": 28,
98
+ "special event": 29,
99
+ "sports/tvs": 30,
100
+ "takeout": 31,
101
+ "tasting menu": 32,
102
+ "vegetarian": 33,
103
+ "walk-in": 34,
104
+ "wine list": 35
105
+ },
106
+ "max_position_embeddings": 1024,
107
+ "model_type": "bart",
108
+ "multi_target_strategy": "multi-output",
109
+ "normalize_before": false,
110
+ "num_hidden_layers": 12,
111
+ "output_past": false,
112
+ "pad_token_id": 1,
113
+ "problem_type": "multi_label_classification",
114
+ "scale_embedding": false,
115
+ "torch_dtype": "float32",
116
+ "transformers_version": "4.26.0",
117
+ "use_cache": true,
118
+ "vocab_size": 50265
119
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.26.0",
5
+ "pytorch": "1.13.1+cu116"
6
+ }
7
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model_head.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9a30431b5d6c36262536b263a16f2d4e3d6bbe7bf442ba377efc2c988c20b93
3
+ size 309489
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:0a686fb75bb5b1c11fd33c8602b89bf4b16b877c3dc55a429df630b3018bd4f5
3
+ size 1625329737
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 1024,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": "<s>",
4
+ "cls_token": "<s>",
5
+ "eos_token": "</s>",
6
+ "errors": "replace",
7
+ "mask_token": "<mask>",
8
+ "model_max_length": 1024,
9
+ "name_or_path": "/content/drive/MyDrive/Mamoona/Huggingface_model/HIMsetfitMultiLabelModel2epochs/",
10
+ "pad_token": "<pad>",
11
+ "sep_token": "</s>",
12
+ "special_tokens_map_file": null,
13
+ "tokenizer_class": "BartTokenizer",
14
+ "trim_offsets": true,
15
+ "unk_token": "<unk>"
16
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff