saihtaungkham commited on
Commit
a8cd25a
·
1 Parent(s): 34b397b

Upload 7 files

Browse files

First commit of the model.

README.md CHANGED
@@ -1,3 +1,163 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+
5
+ # Burmese RoBERTa
6
+
7
+ ## Description
8
+ The model is adopted from the RoBERTa base model and trained using Masked Language Modeling (MLM) with the following datasets:
9
+
10
+ 1. `oscar-corpus/OSCAR-2301`
11
+ 2. `5w4n/OSCAR-2019-Burmese-fix`
12
+ 3. Wikipedia
13
+ 4. [myParaphrase](https://github.com/ye-kyaw-thu/myParaphrase)
14
+ 5. [myanmar_news](https://huggingface.co/datasets/myanmar_news)
15
+ 6. [FLORES-200](https://github.com/facebookresearch/flores/tree/main/flores200)
16
+ 7. [myPOS](https://github.com/ye-kyaw-thu/myPOS.git)
17
+ 8. [BurmeseProverbDataSet](https://github.com/vincent-paing/BurmeseProverbDataSet.git)
18
+ 9. [TALPCo](https://github.com/matbahasa/TALPCo.git)
19
+
20
+ ## Model Usage
21
+
22
+
23
+ ```python
24
+ from transformers import pipeline
25
+
26
+ model_name = "saihtaungkham/BurmeseRoBERTa"
27
+
28
+ fill_mask = pipeline(
29
+ "fill-mask",
30
+ model=model_name,
31
+ tokenizer=model_name,
32
+ )
33
+
34
+ print(fill_mask("ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ [MASK] ဖြစ်သည်။"))
35
+ ```
36
+
37
+ ```shell
38
+ [{'score': 0.5182967782020569,
39
+ 'token': 1071,
40
+ 'token_str': 'မြို့တော်',
41
+ 'sequence': 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ မြို့တော် ဖြစ်သည်။'},
42
+ {'score': 0.029216164723038673,
43
+ 'token': 28612,
44
+ 'token_str': 'အကြီးဆုံးမြို့',
45
+ 'sequence': 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ အကြီးဆုံးမြို့ ဖြစ်သည်။'},
46
+ {'score': 0.013689162209630013,
47
+ 'token': 2034,
48
+ 'token_str': 'လေဆိပ်',
49
+ 'sequence': 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ လေဆိပ် ဖြစ်သည်။'},
50
+ {'score': 0.01367204450070858,
51
+ 'token': 17641,
52
+ 'token_str': 'ရုံးစိုက်ရာမြို့',
53
+ 'sequence': 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ ရုံးစိုက်ရာမြို့ ဖြစ်သည်။'},
54
+ {'score': 0.010110817849636078,
55
+ 'token': 2723,
56
+ 'token_str': 'အရှေ့ပိုင်း',
57
+ 'sequence': 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ အရှေ့ပိုင်း ဖြစ်သည်။'}]
58
+ ```
59
+
60
+ ## Extract text embedding from the sentence
61
+ ```python
62
+ import torch
63
+ from transformers import AutoModelForMaskedLM, AutoTokenizer
64
+
65
+ model_name = "saihtaungkham/BurmeseRoBERTa"
66
+
67
+ # Loading the model
68
+ model = AutoModelForMaskedLM.from_pretrained(model_name)
69
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
70
+
71
+ # Sample data
72
+ input_texts = [
73
+ "ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ စီးပွားရေးမြို့တော်ဖြစ်သည်။",
74
+ "ဘန်ကောက်သည် ထိုင်းနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။",
75
+ "နေပြည်တော်သည် မြန်မာနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။",
76
+ "ဂျပန်ကို အလည်သွားမယ်။",
77
+ "ဗိုက်ဆာတယ်။",
78
+ "ထိုင်းအစားအစာကို ကြိုက်တယ်။",
79
+ "ခွေးလေးကချစ်စရာလေး",
80
+ "မင်းသမီးလေးက ချစ်စရာလေး"
81
+ ]
82
+
83
+ # Function for encode our sentences
84
+ def encode(inputs):
85
+ return tokenizer(
86
+ inputs,
87
+ truncation=True,
88
+ padding="max_length",
89
+ max_length=512,
90
+ return_attention_mask=True,
91
+ return_tensors="pt",
92
+ )
93
+
94
+
95
+ # Enter the evaluation mode
96
+ model.eval()
97
+
98
+ for idx in range(len(input_texts)):
99
+ target_sentence = input_texts[idx]
100
+ compare_sentences = input_texts[:]
101
+ compare_sentences.remove(target_sentence)
102
+ outputs = []
103
+ with torch.no_grad():
104
+ for token in compare_sentences:
105
+ model_output = model(**encode([target_sentence, token]))
106
+ # If you would like to extract the sentences embedding,
107
+ # the following line does the job for you.
108
+ sentence_embeddings = model_output[0].mean(dim=1)
109
+
110
+ # Check the sentence similarity.
111
+ similarity_score = torch.nn.functional.cosine_similarity(
112
+ sentence_embeddings[0].reshape(1, -1),
113
+ sentence_embeddings[1].reshape(1, -1)
114
+ )
115
+ outputs.append((target_sentence, token, similarity_score.item()))
116
+ # print(f"{target_sentence} vs {token} => {similarity_score}")
117
+
118
+ print("*" * 50)
119
+ # Sort the score in descending order.
120
+ outputs.sort(key=lambda x: x[2], reverse=True)
121
+ top_k = 3
122
+ [print(result) for result in outputs[:top_k]]
123
+ ```
124
+
125
+ ```shell
126
+ **************************************************
127
+ ('ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ စီးပွားရေးမြို့တော်ဖြစ်သည်။', '���ေပြည်တော်သည် မြန်မာနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 0.9941556453704834)
128
+ ('ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ စီးပွားရေးမြို့တော်ဖြစ်သည်။', 'ဘန်ကောက်သည် ထိုင်းနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 0.9840704202651978)
129
+ ('ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ စီးပွားရေးမြို့တော်ဖြစ်သည်။', 'ဂျပန်ကို အလည်သွားမယ်။', 0.9625985026359558)
130
+ **************************************************
131
+ ('ဘန်ကောက်သည် ထိုင်းနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ စီးပွားရေးမြို့တော်ဖြစ်သည်။', 0.9840705394744873)
132
+ ('ဘန်ကောက်သည် ထိုင်းနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 'နေပြည်တော်သည် မြန်မာနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 0.9832078814506531)
133
+ ('ဘန်ကောက်သည် ထိုင်းနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 'ဂျပန်ကို အလည်သွားမယ်။', 0.9640133380889893)
134
+ **************************************************
135
+ ('နေပြည်တော်သည် မြန်မာနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 'ရန်ကုန်သည် မြန်မာနိုင်ငံ၏ စီးပွားရေးမြို့တော်ဖြစ်သည်။', 0.9941557049751282)
136
+ ('နေပြည်တော်သည် မြန်မာနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 'ဘန်ကောက်သည် ထိုင်းနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 0.9832078218460083)
137
+ ('နေပြည်တော်သည် မြန်မာနိုင်ငံ၏ မြို့တော်ဖြစ်သည်။', 'ဂျပန်ကို အလည်သွားမယ်။', 0.9571995139122009)
138
+ **************************************************
139
+ ('ဂျပန်ကို အလည်သွားမယ်။', 'ဗိုက်ဆာတယ်။', 0.9784848093986511)
140
+ ('ဂျပန်ကို အလည်သွားမယ်။', 'ထိုင်းအစားအစာကို ကြိုက်တယ်။', 0.9755436182022095)
141
+ ('ဂျပန်ကို အလည်သွားမယ်။', 'မင်းသမီးလေးက ချစ်စရာလေး', 0.9682475924491882)
142
+ **************************************************
143
+ ('ဗိုက်ဆာတယ်။', 'ဂျပန်ကို အလည်သွားမယ်။', 0.9784849882125854)
144
+ ('ဗိုက်ဆာတယ်။', 'ထိုင်းအစားအစာကို ကြိုက်တယ်။', 0.9781478047370911)
145
+ ('ဗိုက်ဆာတယ်။', 'ခွေးလေးကချစ်စရာလေး', 0.971768856048584)
146
+ **************************************************
147
+ ('ထိုင်းအစားအစာကို ကြိုက်တယ်။', 'ဗိုက်ဆာတယ်။', 0.9781478047370911)
148
+ ('ထိုင်းအစားအစာကို ကြိုက်တယ်။', 'ဂျပန်ကို အလည်သွားမယ်။', 0.975543737411499)
149
+ ('ထိုင်းအစားအစာကို ကြိုက်တယ်။', 'မင်းသမီးလေးက ချစ်စရာလေး', 0.9729770421981812)
150
+ **************************************************
151
+ ('ခွေးလေးကချစ်စရာလေး', 'မင်းသမီးလေးက ချစ်စရာလေး', 0.996442437171936)
152
+ ('ခွေးလေးကချစ်စရာလေး', 'ဗိုက်ဆာတယ်။', 0.971768856048584)
153
+ ('ခွေးလေးကချစ်စရာလေး', 'ထိုင်းအစားအစာကို ကြိုက်တယ်။', 0.9697750806808472)
154
+ **************************************************
155
+ ('မင်းသမီးလေးက ချစ်စရာလေး', 'ခွေးလေးကချစ်စရာလေး', 0.9964425563812256)
156
+ ('မင်းသမီးလေးက ချစ်စရာလေး', 'ထိုင်းအစားအစာကို ကြိုက်တယ်။', 0.9729769229888916)
157
+ ('မင်းသမီးလေးက ချစ်စရာလေး', 'ဗိုက်ဆာတယ်။', 0.9686307907104492)
158
+ ```
159
+
160
+ # Credit
161
+ I thank the original author and contributor mentioned in the dataset sections.
162
+ We have the technologies but need the datasets to make the model work. The transformer model has been available since 2017. However, it is still challenging to train the model due to the low language resources available over the internet. This model will be a stepping stone for us to create a more open model for the Myanmar language and benefit our community.
163
+ Anyone is welcome to contact me regarding the license and contribution to the improvement of this model.
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForMaskedLM"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "roberta",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "position_embedding_type": "absolute",
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.35.2",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 52004
26
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2bcba0096c710dff8d28c5d95c0e8625cb1ad765602bcb93b0a5b39095a2555
3
+ size 504166184
special_tokens_map.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "[CLS]",
4
+ "eos_token": "</s>",
5
+ "mask_token": "[MASK]",
6
+ "pad_token": "[PAD]",
7
+ "sep_token": "[SEP]",
8
+ "unk_token": "<unk>"
9
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<unk>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<s>",
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
+ "52000": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "52001": {
36
+ "content": "[PAD]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "52002": {
44
+ "content": "[CLS]",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "52003": {
52
+ "content": "[MASK]",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ }
59
+ },
60
+ "bos_token": "<s>",
61
+ "clean_up_tokenization_spaces": true,
62
+ "cls_token": "[CLS]",
63
+ "eos_token": "</s>",
64
+ "mask_token": "[MASK]",
65
+ "model_max_length": 512,
66
+ "pad_token": "[PAD]",
67
+ "sep_token": "[SEP]",
68
+ "tokenizer_class": "PreTrainedTokenizerFast",
69
+ "truncation": true,
70
+ "unk_token": "<unk>"
71
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca8c59cbb52f95918e9431a41576e43da9972b3df6a274b161a1e0b3fa4f661d
3
+ size 4728