efederici commited on
Commit
91f1dc1
1 Parent(s): 124ce69
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 CHANGED
@@ -1,3 +1,72 @@
1
  ---
 
2
  license: apache-2.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: sentence-similarity
3
  license: apache-2.0
4
+ language:
5
+ - it
6
+ tags:
7
+ - sentence-transformers
8
+ - feature-extraction
9
+ - sentence-similarity
10
+ - transformers
11
  ---
12
+
13
+ # sentence-BERTino
14
+
15
+ This is a [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. It was trained on 1M examples from [mmarco](https://huggingface.co/datasets/unicamp-dl/mmarco/viewer/italian/train).
16
+
17
+ ## Usage (Sentence-Transformers)
18
+
19
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
20
+ ```
21
+ pip install -U sentence-transformers
22
+ ```
23
+ Then you can use the model like this:
24
+ ```python
25
+ from sentence_transformers import SentenceTransformer
26
+ sentences = ["Questo è un esempio di frase", "Questo è un ulteriore esempio"]
27
+
28
+ model = SentenceTransformer('efederici/mmarco-sentence-BERTino')
29
+ embeddings = model.encode(sentences)
30
+ print(embeddings)
31
+ ```
32
+ ## Usage (HuggingFace Transformers)
33
+
34
+ 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.
35
+ ```python
36
+ from transformers import AutoTokenizer, AutoModel
37
+ import torch
38
+
39
+
40
+ #Mean Pooling - Take attention mask into account for correct averaging
41
+ def mean_pooling(model_output, attention_mask):
42
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
43
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
44
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
45
+
46
+ # Sentences we want sentence embeddings for
47
+ sentences = ["Questo è un esempio di frase", "Questo è un ulteriore esempio"]
48
+
49
+ # Load model from HuggingFace Hub
50
+ tokenizer = AutoTokenizer.from_pretrained('efederici/mmarco-sentence-BERTino')
51
+ model = AutoModel.from_pretrained('efederici/mmarco-sentence-BERTino')
52
+
53
+ # Tokenize sentences
54
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
55
+
56
+ # Compute token embeddings
57
+ with torch.no_grad():
58
+ model_output = model(**encoded_input)
59
+ # Perform pooling. In this case, mean pooling.
60
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
61
+ print("Sentence embeddings:")
62
+ print(sentence_embeddings)
63
+ ```
64
+
65
+
66
+ ## Full Model Architecture
67
+ ```
68
+ SentenceTransformer(
69
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: DistilBertModel
70
+ (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
71
+ )
72
+ ```
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "indigo-ai/BERTino",
3
+ "activation": "gelu",
4
+ "architectures": [
5
+ "DistilBertModel"
6
+ ],
7
+ "attention_dropout": 0.1,
8
+ "dim": 768,
9
+ "dropout": 0.1,
10
+ "hidden_dim": 3072,
11
+ "initializer_range": 0.02,
12
+ "max_position_embeddings": 512,
13
+ "model_type": "distilbert",
14
+ "n_heads": 12,
15
+ "n_layers": 6,
16
+ "output_hidden_states": true,
17
+ "pad_token_id": 0,
18
+ "qa_dropout": 0.1,
19
+ "seq_classif_dropout": 0.2,
20
+ "sinusoidal_pos_embds": false,
21
+ "tie_weights_": true,
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.19.0.dev0",
24
+ "vocab_size": 32102
25
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.0",
4
+ "transformers": "4.19.0.dev0",
5
+ "pytorch": "1.11.0+cu113"
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:8a6f33399a3d367dce706388bc8bc86dd6f14eef38b69b334179242fd7f48522
3
+ size 270337273
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 @@
 
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
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, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "max_len": 512, "special_tokens_map_file": null, "full_tokenizer_file": null, "name_or_path": "indigo-ai/BERTino", "do_basic_tokenize": true, "never_split": null, "tokenizer_class": "DistilBertTokenizer"}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff