saihtaungkham commited on
Commit
06e2870
1 Parent(s): 3e80194

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +136 -0
README.md CHANGED
@@ -1,3 +1,139 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ language:
4
+ - my
5
+ tags:
6
+ - burmese
7
+ - transformer
8
+ - text-generation-inference
9
+ - nlp
10
  ---
11
+
12
+ # Burmese RoBERTa Text Generation
13
+
14
+ ## Description
15
+ The model is fine-tuned from the previous [BurmeseRoBERTa](https://huggingface.co/saihtaungkham/BurmeseRoBERTa) model and trained using Causal Language Modeling (CLM) with the following datasets:
16
+
17
+ 1. `oscar-corpus/OSCAR-2301`
18
+ 2. `5w4n/OSCAR-2019-Burmese-fix`
19
+ 3. Wikipedia
20
+ 4. [myParaphrase](https://github.com/ye-kyaw-thu/myParaphrase)
21
+ 5. [myanmar_news](https://huggingface.co/datasets/myanmar_news)
22
+ 6. [FLORES-200](https://github.com/facebookresearch/flores/tree/main/flores200)
23
+ 7. [myPOS](https://github.com/ye-kyaw-thu/myPOS.git)
24
+ 8. [BurmeseProverbDataSet](https://github.com/vincent-paing/BurmeseProverbDataSet.git)
25
+ 9. [TALPCo](https://github.com/matbahasa/TALPCo.git)
26
+
27
+ ## Model Usage
28
+
29
+ ```python
30
+ from transformers import pipeline
31
+
32
+ MODEL_NAME = "saihtaungkham/BurmeseRoBERTaCLM"
33
+ generator = pipeline("text-generation", model=MODEL_NAME, tokenizer=MODEL_NAME)
34
+
35
+ prompt = "မြန်မာနိုင်ငံနှင့် ထိုင်းနိုင်ငံ"
36
+ print(generator(prompt))
37
+
38
+ # Output
39
+ # [{'generated_text': 'မြန်မာနိုင်ငံနှင့် ထိုင်းနိုင်ငံ နှစ်နိုင်ငံ ပူးပေါင်း ဆောင်ရွက် မှု ကို ဆောင်ရွက် ရန် သဘောတူ '}]
40
+ ```
41
+
42
+ ## Adjust the model output
43
+ ```python
44
+ from transformers import AutoModelForCausalLM, AutoTokenizer
45
+
46
+ MODEL_PATH = "saihtaungkham/BurmeseRoBERTaCLM"
47
+
48
+ model = AutoModelForCausalLM.from_pretrained(MODEL_PATH)
49
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
50
+
51
+ def generate_story(prompt,
52
+ model,
53
+ tokenizer,
54
+ # If step_token exceeds 512, it throws the index out-of-bounds error. The sweet spot is between 100 and 200.
55
+ step_token=100, # Max token generated each time while the model is running.
56
+ generate_steps=10, # How long to run model generation with previous input.
57
+ do_sample=True, # Enable model output tunning.
58
+ top_k=50, # Top words that the model predicted with higher scores.
59
+ top_p=0.95, # For model creativity. It is recommended to set it higher over 0.8 for better output.
60
+ num_last_sentence_windows=1, # Number of previous sentences used for better model reference. The sweet spot is 1 and 2.
61
+ print_internal=True # Whether showing the internal stage while the model is running.
62
+ ):
63
+ outputs = ""
64
+ def generate_tokens(prompt):
65
+ inputs = tokenizer(prompt,
66
+ max_length=512,
67
+ truncation=True,
68
+ return_tensors="pt").input_ids
69
+ inference_results = model.generate(
70
+ inputs,
71
+ max_new_tokens=step_token,
72
+ do_sample=do_sample,
73
+ top_k=top_k,
74
+ top_p=top_p)
75
+ return tokenizer.batch_decode(
76
+ inference_results,
77
+ skip_special_tokens=True
78
+ )[0]
79
+ outputs += generate_tokens(prompt)
80
+ if print_internal:
81
+ print(outputs)
82
+ for _ in range(generate_steps -1):
83
+ content = outputs.split("။")
84
+ if len(content) > num_last_sentence_windows:
85
+ content = content[-num_last_sentence_windows:]
86
+ content = "။".join(content)
87
+ inter_output = generate_tokens(content)
88
+ inter_output = inter_output.split("။")
89
+ fresh_content = inter_output[num_last_sentence_windows:]
90
+ if print_internal:
91
+ print("။".join(fresh_content))
92
+ outputs += "။".join(fresh_content)
93
+ else:
94
+ inter_output = generate_tokens(outputs.strip())
95
+ if print_internal:
96
+ print(inter_output)
97
+ outputs = inter_output
98
+
99
+ return outputs
100
+
101
+ prompt = "ရန်ကုန်မြို့နေပြည်သူများ"
102
+
103
+ output = generate_story(
104
+ model=model,
105
+ prompt=prompt,
106
+ tokenizer=tokenizer,
107
+ step_token=100,
108
+ generate_steps=5,
109
+ do_sample=True,
110
+ top_k=50,
111
+ top_p=0.95,
112
+ num_last_sentence_windows=1,
113
+ print_internal=True
114
+ )
115
+ print(output)
116
+
117
+ ```
118
+ ```shell
119
+ ရန်ကုန်မြို့နေပြည်သူများ ပိုမိုလုံခြုံမှုရှိစေဖို့ အစိုးရမဟုတ်တဲ့ အဖွဲ့အစည်းတစ်ခုအနေနဲ့ ပြည်သူကို ထိန်းကျောင်းဖို့ အရေးကြီးတယ်လို့ ဆိုပါတယ်။ ပြည်သူတွေ ဒီအခြေအနေတွေကို
120
+ သိရှိအောင် ဘယ်လိုလုပ်ဆောင်ရမလဲ ဆိုတာတွေကိုလည်း ဗွီ���ိုအေမြန်မာပိုင်းက မဆုမွန် ဆက်သွယ်မေးမြန်းထားပါတယ်။မေး။ ။ ဒီနေ့ ရန်ကုန်မှာ ဖြစ်နေတဲ့ ပဋိပက္ခကြီးကတော့
121
+ အကြမ်းဖက်တိုက်ဖျက်ရေး စစ်တပ်က အာဏာသိမ်းတဲ့ လုပ်ရပ်ပေါ့နော်။ စစ်ကောင်စီဘက်ကလည်း ပြည်သူတွေကို စနစ်တကျ ထိန်းကျောင်းဖို့ တာဝန်ရှိတယ်။ ပြည်သူက
122
+ ဘယ်လောက်လေးစားတယ်၊ ဘယ်လိုခံစားရတယ်၊ ဘာတွေ အလေးထားတယ်၊ ဘယ်လောက်အထိ လိုက်နာတယ်၊ ဘာကြောင့်” ဒီအကြောင်းနဲ့ ပတ်သက်ပြီး မြန်မာနိုင်ငံဆိုင်ရာ
123
+ ကုလသံ၀တမန် လက်ထောက် အမြဲတမ်းအတွင်း၀န် မစ္စ ဗီယန်ကျန်းက “ကျနော်တို့ဟာ လူ့အခွင့်အရေးချိုးဖောက်မှုတွေ ကျူးလွန်ခံနေရတာကို ကမ္ဘာက မြင်အောင် လုပ်ဖို့နဲ့ ဒီပဋိပက္ခဟာ
124
+ ပိုပြီးတော့ ရှုပ်ထွေးလာတယ်။ ပိုပြီးတော့ ရှုပ်ထွေးလာတာကို တွေ့နိုင်တယ်။ အထူးသဖြင့် ရခိုင်ပြည်နယ်မှာ ဒုက္ခသည်တွေရဲ့ ကျန်းမာရေး စောင့်ရှောက်မှုတွေကို ရခိုင်ပြည်နယ်ထဲက
125
+ မြို့နယ်တွေမှာ လုပ်ဆောင်တာဖြစ်သလို ဒုက္ခသည်စခန်းတွေ မှာ ဆေးကုသဖို့ လိုအပ်တဲ့ ဆေးဝါးတွေ လိုအပ်နေတယ်လို့ UNHCR က ဆိုပါတယ်။ ဒီအကြောင်းနဲ့ ပတ်သက်ပြီး
126
+ အပြည့်အစုံကိုတော့ ထိုင်းအခြေစိုက် ဗွီအိုအေသတင်းထောက် မအေးအေးမာက သတင်းပေးပို့ထားပါတယ်။ရခိုင်မြောက်ပိုင်း ဘူးသီးတောင်နဲ့ ရသေ့တောင်မြို့နယ်က စစ်ဘေးဒုက္ခသည်တွေ၊
127
+ ဒေသခံ ဒီအကြောင်း မဆုမွန် စုစည်းတင်ပြပေးထားပါတယ်။ရခိုင်မြောက်ပိုင်း မောင်တောနဲ့ ဘူးသီးတောင်မြို့နယ်က စစ်ဘေးဒုက္ခသည် IDP တွေ စားဝတ်နေရေးအခက်ခဲတွေ ကြုံနေရလို့
128
+ ဘင်္ဂလားဒေ့ရှ် အစိုးရက စားသောက်ကုန်တွေ၊ အဝတ်အထည်တွေနဲ့ စားနပ်ရိက္ခာတွေကို အကူအညီပေးနေပြီး ရခိုင်ပြည်နယ်တွင်းမှာ စစ်ဘေးရှောင်ဒုက္ခသည်တွေအတွက် စားနပ်ရိက္ခာ၊
129
+ ဆေးဝါးနဲ့ စားသောက်ကုန် အကူအညီတွေ အမြန်ဆုံး ကူညီပေးဖို့ အစိုးရကို တောင်းဆိုထားပါတယ်။ဘူးသီးတောင်မြို့နယ်၊ ထို့နောက် တပ်မတော်စစ်ကြောင်းများက မောင်တောမြို့နယ်
130
+ တောင်ပိုင်း၊ တဟီရကျေးရွာကို စီးနင်း တိုက်ခိုက်ခဲ့ကာ ဒေသခံပြည်သူများအား စစ်မေး မေးမြန်းရာတွင် မြန်မာ့တပ်မတော်က မိုင်း
131
+ ```
132
+
133
+ # Warning
134
+ This model uses internet-curated data and may contain bias, violence, explicit language, sexual content, and harmful responses. Please use it with care.
135
+
136
+ # Credit
137
+ I thank the original author and contributor mentioned in the dataset sections.
138
+ 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.
139
+ Anyone is welcome to contact me regarding the dataset license and contribution to the improvement of this model.