dchaplinsky commited on
Commit
f37ac3e
1 Parent(s): 06fb7e8

First release

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .DS_Store
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,161 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - multilingual
4
+ - ar
5
+ - bg
6
+ - ca
7
+ - cs
8
+ - da
9
+ - de
10
+ - el
11
+ - en
12
+ - es
13
+ - et
14
+ - fa
15
+ - fi
16
+ - fr
17
+ - gl
18
+ - gu
19
+ - he
20
+ - hi
21
+ - hr
22
+ - hu
23
+ - hy
24
+ - id
25
+ - it
26
+ - ja
27
+ - ka
28
+ - ko
29
+ - ku
30
+ - lt
31
+ - lv
32
+ - mk
33
+ - mn
34
+ - mr
35
+ - ms
36
+ - my
37
+ - nb
38
+ - nl
39
+ - pl
40
+ - pt
41
+ - ro
42
+ - ru
43
+ - sk
44
+ - sl
45
+ - sq
46
+ - sr
47
+ - sv
48
+ - th
49
+ - tr
50
+ - uk
51
+ - ur
52
+ - vi
53
  license: apache-2.0
54
+ library_name: sentence-transformers
55
+ tags:
56
+ - sentence-transformers
57
+ - feature-extraction
58
+ - sentence-similarity
59
+ - transformers
60
+ language_bcp47:
61
+ - fr-ca
62
+ - pt-br
63
+ - zh-cn
64
+ - zh-tw
65
+ pipeline_tag: sentence-similarity
66
  ---
67
+
68
+ # lang-uk/ukr-paraphrase-multilingual-mpnet-base
69
+
70
+ This is a [sentence-transformers](https://www.SBERT.net) model fine-tuned for Ukrainian language: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
71
+
72
+ The original model used for fine-tuning is `sentence-transformers/paraphrase-multilingual-mpnet-base-v2`. See our paper [Contextual Embeddings for Ukrainian: A Large Language Model Approach to Word Sense Disambiguation](https://aclanthology.org/2023.unlp-1.2/) for details.
73
+
74
+
75
+ ## Usage (Sentence-Transformers)
76
+
77
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
78
+
79
+ ```
80
+ pip install -U sentence-transformers
81
+ ```
82
+
83
+ Then you can use the model like this:
84
+
85
+ ```python
86
+ from sentence_transformers import SentenceTransformer
87
+ sentences = ["This is an example sentence", "Each sentence is converted"]
88
+
89
+ model = SentenceTransformer('lang-uk/ukr-paraphrase-multilingual-mpnet-base')
90
+ embeddings = model.encode(sentences)
91
+ print(embeddings)
92
+ ```
93
+
94
+
95
+
96
+ ## Usage (HuggingFace Transformers)
97
+ 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.
98
+
99
+ ```python
100
+ from transformers import AutoTokenizer, AutoModel
101
+ import torch
102
+
103
+
104
+ #Mean Pooling - Take attention mask into account for correct averaging
105
+ def mean_pooling(model_output, attention_mask):
106
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
107
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
108
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
109
+
110
+
111
+ # Sentences we want sentence embeddings for
112
+ sentences = ['This is an example sentence', 'Each sentence is converted']
113
+
114
+ # Load model from HuggingFace Hub
115
+ tokenizer = AutoTokenizer.from_pretrained('lang-uk/ukr-paraphrase-multilingual-mpnet-base')
116
+ model = AutoModel.from_pretrained('lang-uk/ukr-paraphrase-multilingual-mpnet-base')
117
+
118
+ # Tokenize sentences
119
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
120
+
121
+ # Compute token embeddings
122
+ with torch.no_grad():
123
+ model_output = model(**encoded_input)
124
+
125
+ # Perform pooling. In this case, average pooling
126
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
127
+
128
+ print("Sentence embeddings:")
129
+ print(sentence_embeddings)
130
+ ```
131
+
132
+
133
+
134
+ ## Citing & Authors
135
+
136
+
137
+ If you find this model helpful, feel free to cite our publication [Contextual Embeddings for {U}krainian: A Large Language Model Approach to Word Sense Disambiguation](https://aclanthology.org/2023.unlp-1.2/):
138
+ ```bibtex
139
+ @inproceedings{laba-etal-2023-contextual,
140
+ title = "Contextual Embeddings for {U}krainian: A Large Language Model Approach to Word Sense Disambiguation",
141
+ author = "Laba, Yurii and
142
+ Mudryi, Volodymyr and
143
+ Chaplynskyi, Dmytro and
144
+ Romanyshyn, Mariana and
145
+ Dobosevych, Oles",
146
+ editor = "Romanyshyn, Mariana",
147
+ booktitle = "Proceedings of the Second Ukrainian Natural Language Processing Workshop (UNLP)",
148
+ month = may,
149
+ year = "2023",
150
+ address = "Dubrovnik, Croatia",
151
+ publisher = "Association for Computational Linguistics",
152
+ url = "https://aclanthology.org/2023.unlp-1.2",
153
+ doi = "10.18653/v1/2023.unlp-1.2",
154
+ pages = "11--19",
155
+ abstract = "This research proposes a novel approach to the Word Sense Disambiguation (WSD) task in the Ukrainian language based on supervised fine-tuning of a pre-trained Large Language Model (LLM) on the dataset generated in an unsupervised way to obtain better contextual embeddings for words with multiple senses. The paper presents a method for generating a new dataset for WSD evaluation in the Ukrainian language based on the SUM dictionary. We developed a comprehensive framework that facilitates the generation of WSD evaluation datasets, enables the use of different prediction strategies, LLMs, and pooling strategies, and generates multiple performance reports. Our approach shows 77,9{\%} accuracy for lexical meaning prediction for homonyms.",
156
+ }
157
+ ```
158
+
159
+ Copyright: Yurii Laba, Volodymyr Mudryi, Dmytro Chaplynskyi, Mariana Romanyshyn, Oles Dobosevych, [Ukrainian Catholic University](https://ucu.edu.ua/en/), [lang-uk project](https://lang.org.ua/en/), 2023
160
+
161
+ An original model used for fine-tuning was trained by [sentence-transformers](https://www.sbert.net/).
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "sentence-transformers/paraphrase-multilingual-mpnet-base-v2",
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
+ "gradient_checkpointing": false,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "layer_norm_eps": 1e-05,
17
+ "max_position_embeddings": 514,
18
+ "model_type": "xlm-roberta",
19
+ "num_attention_heads": 12,
20
+ "num_hidden_layers": 12,
21
+ "output_hidden_states": true,
22
+ "output_past": true,
23
+ "pad_token_id": 1,
24
+ "position_embedding_type": "absolute",
25
+ "torch_dtype": "float32",
26
+ "transformers_version": "4.26.0",
27
+ "type_vocab_size": 1,
28
+ "use_cache": true,
29
+ "vocab_size": 250002
30
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.7.0",
5
+ "pytorch": "1.9.0+cu102"
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:6182e20a3aeb704b2de42520343f1b1855472d0bb37de55f610038793c1bc5b7
3
+ size 1112245805
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": "old_models/paraphrase-multilingual-mpnet-base-v2/0_Transformer"}