lhchan commited on
Commit
6eda7be
1 Parent(s): c2707cf
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.txt ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Uncased Finnish Sentence BERT model
2
+
3
+ Finnish Sentence BERT trained from FinBERT
4
+
5
+ ## Training
6
+
7
+ FinBERT model: TurkuNLP/bert-base-finnish-uncased-v1
8
+ Data: The data provided [here] (https://turkunlp.org/paraphrase.html), including the Finnish Paraphrase Corpus and the automatically collected paraphrase candidates (500K positive and 5M negative)
9
+ Pooling: mean pooling
10
+ Task: Binary prediction, whether two sentences are paraphrases or not. Note: the labels 3 and 4 are considered paraphrases, and labels 1 and 2 non-paraphrases. [Details on labels] (https://aclanthology.org/2021.nodalida-main.29/)
11
+
12
+ ## Usage
13
+
14
+ The same as in [HuggingFace documentation] (https://huggingface.co/sentence-transformers/bert-base-nli-mean-tokens). Either through `SentenceTransformer` or `HuggingFace Transformers`
15
+
16
+ ### SentenceTransformer
17
+
18
+ ```
19
+ from sentence_transformers import SentenceTransformer
20
+ sentences = ["Tämä on esimerkkilause.", "Tämä on toinen lause."]
21
+
22
+ model = SentenceTransformer('TurkuNLP/sbert-uncased-finnish-paraphrase')
23
+ embeddings = model.encode(sentences)
24
+ print(embeddings)
25
+ ```
26
+
27
+ ### HuggingFace Transformers
28
+
29
+ ```
30
+ from transformers import AutoTokenizer, AutoModel
31
+ import torch
32
+
33
+
34
+ #Mean Pooling - Take attention mask into account for correct averaging
35
+ def mean_pooling(model_output, attention_mask):
36
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
37
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
38
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
39
+
40
+
41
+ # Sentences we want sentence embeddings for
42
+ sentences = ["Tämä on esimerkkilause.", "Tämä on toinen lause."]
43
+
44
+ # Load model from HuggingFace Hub
45
+ tokenizer = AutoTokenizer.from_pretrained('TurkuNLP/sbert-uncased-finnish-paraphrase')
46
+ model = AutoModel.from_pretrained('TurkuNLP/sbert-uncased-finnish-paraphrase')
47
+
48
+ # Tokenize sentences
49
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
50
+
51
+ # Compute token embeddings
52
+ with torch.no_grad():
53
+ model_output = model(**encoded_input)
54
+
55
+ # Perform pooling. In this case, mean pooling.
56
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
57
+
58
+ print("Sentence embeddings:")
59
+ print(sentence_embeddings)
60
+ ```
added_tokens.json ADDED
@@ -0,0 +1 @@
 
1
+ {}
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "TurkuNLP/bert-base-finnish-uncased-v1",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "transformers_version": "4.4.1",
21
+ "type_vocab_size": 2,
22
+ "use_cache": true,
23
+ "vocab_size": 50101
24
+ }
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.BERT"
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:cb4b16cbfeed535c1ec01bc33d11d178bef1373e51e20d893c1add27abeac658
3
+ size 498127732
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ {
2
+ "max_seq_length": 128,
3
+ "do_lower_case": true
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_config.json ADDED
@@ -0,0 +1 @@
 
1
+ {"do_lower_case": true, "do_basic_tokenize": true, "never_split": null, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "TurkuNLP/bert-base-finnish-uncased-v1"}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff