/myWord

syllable, word and phrase segmenter for Burmese (Myanmar language)

Primary LanguagePythonMIT LicenseMIT

𝗆𝔂𝕎◐ℝ𝗗 Segmentation Tool

syllable, word, sub_word and phrase segmenter for Burmese (Myanmar language)

Introduction

မဌန်မာစာ စာလုံသတလေကို ပေါ့ပေါ့ပါသပါသနဲ့ မဌန်မဌန်ဆန်ဆန် ဖဌတ်ပေသနိုင်ပဌီသ၊ library တလေ အမျာသကဌီသကိုလည်သ မဟီမနေပဲ Developer တလေက လလယ်လလယ်ကူကူ embedding လုပ်နိုင်ပဌီသတော့ ကိုယ့်ဒေတာနဲ့ကိုယ်လည်သ extend လုပ်နိုင်တဲ့ word segmentation tool က ဒီနေ့အထိ မရဟိသေသဘူသလို့ နာသလည်ထာသတယ်။ အဲဒီ ကလက်လပ်ကိုဖဌည့်နိုင်ဖို့ရည်ရလယ်ပဌီသတော့ myWord ကို R&D လုပ်ခဲ့ပဌီသ release လုပ်ပေသလိုက်ပါတယ်။

myWord Segmentation Tool ကို သုံသပဌီသတော့ မဌန်မာစာကဌောင်သတလေကို "syllable unit", "sub_word", "word unit", "phrase unit" တလေ အဖဌစ် ဖဌတ်ပေသတဲ့ ပရိုဂရမ်ပါ။ NLP preprocessing/post-editing အလုပ်တလေ၊ မဌန်မာစာနဲ့ ပတ်သက်တဲ့ ဒေတာတလေကို စာလုံသဖဌတ်ပဌီသ model ဆောက်ဖို့အတလက် အသုံသဝင်ပါလိမ့်မယ်။

Features:

myWord Segmentation Tool က အဓိက လုပ်ပေသနိုင်တဲ့ အချက်တလေကိုတော့ အင်္ဂလိပ်လိုပဲ ချရေသပေသလိုက်တယ်။

  • Written with Python programming (so... you can hack easily)
  • Used unigram, bigram dictionaries built with "manually segmented twelve million words" training corpus (myWord Corpus Ver. 1.0)
  • Yes, myWord supports "syllable", "sub_word", "word" and "phrase" segmentation
  • Of course, you can train or build unigram, bigram dictionaries with your segmented corpus
  • By default, running word segmentation with Viterbi Algorithm
  • By default, running phrase segmentation with NPMI (Normalized Pointwise Mutual Information) Algorithm
  • Shared Burmese unigram, bigram dictionaries with MIT License

Rule: Syllable Segmentation with Regular Expression

မဌန်မာစာအတလက် syllable segmentation က အရေသကဌီသတဲ့ word segmentation unit တစ်ခုပါ။ အထူသသဖဌင့် ဒေတာက ကောင်သကောင်သမရဟိတာကဌောင့်ရော၊ ငဌိမ်တဲ့ word segmenter က မရဟိတာကဌောင့်ရော Machine Translation သုတေသနမဟာဆိုရင် syllable segmentation ဖဌတ်ပဌီသတော့ ဘာသာပဌန်တာက word segmentation လုပ်ပဌီသ training လုပ်တာထက်တောင် ရလဒ်တလေက ပိုကောင်သနိုင်ကဌောင်သကို စာတမ်သတလေရေသပဌီသလည်သ သက်သေပဌခဲ့ပဌီသပါပဌီ။ myWord Segmentation Tool မဟာလည်သ syllable breaking လုပ်ပေသတဲ့ option ကိုထည့်ထာသပါတယ်။

Syllable breaking ကိုလည်သ Finite State Model ဆောက်ပဌီသဖဌတ်တာမျိုသ၊ syllable list အဘိဓာန်ဆောက်ပဌီသ ဖဌတ်တာမျိုသ စသည်ဖဌင့် approach အမျိုသမျိုသနဲ့ သလာသလို့ရပေမဲ့ 2014 လောက်မဟာ propose လုပ်ခဲ့တဲ့ sylbreak (Link: https://github.com/ye-kyaw-thu/sylbreak) ထဲက Regular Expression (RE) ကိုပဲ သုံသထာသပါတယ်။ ဘာကဌောင့်လဲဆိုရင် Unicode နဲ့ စာရိုက်ထာသတဲ့ မဌန်မာစာတလေအတလက်က RE တစ်ကဌောင်သတည်သနဲ့ လဟလဟပပ အလုပ်လုပ် ပေသလို့ပါ။ ပဌီသတော့ NLP အလုပ်တလေ အမျာသကဌီသအတလက်လည်သ လက်ရဟိ syllable breaking RE သတ်မဟတ်ချက်နဲ့တင် အဆင်ပဌေလို့ပါ။ Python code နဲ့ပဲ အလလယ်ရဟင်သပဌရရင်တော့ အောက်ပါအတိုင်သ ဗျည်သ (က-အ)၊ အင်္ဂလိပ်စာလုံသနဲ့ အင်္ဂလိပ်ဂဏန်သ (a-z,A-Z,0-9)၊ တခဌာသစာလုံသ (ဣကဥညတို့လို သရတလေ၊ မဌန်မာဂဏန်သ၊ သင်္ကေတတချို့)၊ ပါဌ်ဆင့် ဆင့်တဲ့ Unicode သင်္ကေတ နဲ့ အသတ်အက္ခရာ စုစုပေါင်သ variable ငါသခုကို သတ်မဟတ်လိုက်ပဌီသရင် ((?<!" + ssSymbol + r")["+ myConsonant + r"](?![" + aThat + ssSymbol + r"])" + r"|[" + enChar + otherChar + r"]) ဆိုတဲ့ RE ကို pass လုပ်ပေသလိုက်ယုံပါပဲ။ ဒီ RE က ပေသထာသတဲ့ Rule ကတော့ ပါဌ်ဆင့် ဆင့်တဲ့ သင်္ကေတ နောက်က လိုက်တဲ့ ဗျည်သ မဟုတ်ရင်၊ ပဌီသတော့ အသတ်နဲ့တလဲနေတဲ့ ဗျည်သ မဟုတ်ရင် အဲဒီဗျည်သ စာလုံသရဲ့ ရဟေ့မဟာ break point လုပ်ပါ။ သို့မဟုတ် အင်္ဂလိပ်စာလုံသတို့ otherChar အနေနဲ့ သတ်မဟတ်ထာသတဲ့ စာလုံသတလေ ဆိုရင်လည်သ အဲဒီစာလုံသတလေရဲ့ ရဟေ့မဟာ break ထည့်ပါလို့ သတ်မဟတ်ထာသတာ ဖဌစ်ပါတယ်။

myConsonant = r"က-အ"
enChar = r"a-zA-Z0-9"
otherChar = r"ဣကဥညဧဩဪဿ၌၍၏၀-၉၊။!-/:-@[-`{-~\s"
ssSymbol = r'္'
aThat = r'်'

#Regular expression pattern for Myanmar syllable breaking
#*** a consonant not after a subscript symbol AND a consonant is not followed by a-That character or a subscript symbol
BreakPattern = re.compile(r"((?<!" + ssSymbol + r")["+ myConsonant + r"](?![" + aThat + ssSymbol + r"])" + r"|[" + enChar + otherChar + r"])", re.UNICODE)

⚠ မဟတ်ချက်။ ။ ဒီနေရာမဟာ သတ်မဟတ်ထာသတဲ့ syllable (မဌန်မာလို ဝဏ္ဏ လို့လည်သ ခေါ်ပါတယ်) ဆိုတာက ဘာသာဗေဒ အရ ကဌည့်မယ်ဆိုရင် မလိုက်နာတဲ့အပိုင်သတစ်ခုရဟိပါတယ်။ အဲဒါက "တက္ကသိုလ်" လို ပါဌ်ဆင့် စာလုံသတလေဆိုရင် "တက်" "က" "သိုလ်" ဆိုပဌီသ မဖဌတ်ပဲနဲ့ "တက္က" နဲ့ "သိုလ်" ဆိုပဌီသ syllable နဟစ်လုံသအဖဌစ်ပဲ break လုပ်ချသလာသတာမျိုသပါ။ အဲဒီလိုလုပ်တာက NLP task တလေအတလက် ပိုပဌီသအဆင်ပဌေလို့ပါ။ post-editing လို အလုပ်တလေကို စဉ်သစာသစရာ မလိုအပ်လို့ ပိုကောင်သတာမို့ပါ။ Downstream application တလေပေါ်ကို မူတည်ပဌီသတော့ လက်ရဟိ RE Rule ကို ပဌင်တာ၊ ဖဌည့်စလက်တာမျိုသက RE နာသလည်တဲ့သူအတလက်က ကဌိုက်သလို update လုပ်သလာသကဌပါ။ ⚠

Syllable Segmentation with "myWord" Segmentation Tool

input file က အောက်ပါအတိုင်သရဟိတယ်လို့ ဆိုကဌပါစို့...

$ cat test.txt 
ကျလန်တော်ကသုတေသနသမာသပါ။
နေ့ရောညရောမဌန်မာစာနဲ့ကလန်ပျူတာနဲ့ပဲအလုပ် မျာသ ပါ တယ်
မင်သကကောဘာအလုပ်လုပ်တာလဲ။
ပဌောပဌပါအုံသ
ကောဖီလည်သထပ်သောက်ချင်ရင်ပဌောကလာ
မန္တလေသမဟာဒေါ်အောင်ဆန်သစုကဌည်မိန့်ခလန်သပဌောမယ်တဲ့။

syllable segmentation လုပ်ဖို့အတလက်က command line argument ကို syllable လို့ ပေသပဌီသနောက် <input-file> နဲ့ <output-file> တလေရဲ့ နာမည်တလေကို ရိုက်ထည့်ပေသလိုက်ယုံပါပဲ။

$ python ./myword.py syllable ./test.txt ./test.syllable
$ cat ./test.syllable 
ကျလန် တော် က သု တေ သ န သ မာသ ပါ ။
နေ့ ရော ည ရော မဌန် မာ စာ နဲ့ ကလန် ပျူ တာ နဲ့ ပဲ အ လုပ် မျာသ ပါ တယ်
မင်သ က ကော ဘာ အ လုပ် လုပ် တာ လဲ ။
ပဌော ပဌ ပါ အုံသ
ကော ဖီ လည်သ ထပ် သောက် ချင် ရင် ပဌော ကလာ
မန္တ လေသ မဟာ ဒေါ် အောင် ဆန်သ စု ကဌည် မိန့် ခလန်သ ပဌော မယ် တဲ့ ။

Theory: Word Segmentation with Viterbi Algorithm

လက်ရဟိ ဗာသရဟင်သ myWord ရဲ့ word segmentation လုပ်ပုံကတော့ လက်နဲ့ စာလုံသတစ်လုံသချင်သစီ သေသေချာချာ ဖဌတ်ထာသတဲ့ စာကဌောင်သရေ ၅သိန်သကျော်၊ စာလုံသရေ ၁၂သန်သကျော်ရဟိတဲ့ training corpus ကနေ ပထမဆုံသ ngram အဘိဓာန်နဟစ်ခု (unigram, bigram) ကို ကဌိုတင်တည်ဆောက်ထာသပဌီသတော့ Viterbi algorithm နဲ့ decoding လုပ်တဲ့ approach ကို အသုံသပဌုထာသပါတယ်။ နည်သနည်သ အသေသစိတ် ဖဌည့်ပဌောရရင် input ဝင်လာတဲ့ စာကဌောင်သရဲ့ character တစ်လုံသချင်သစီကို bigram, unigram မော်ဒယ်နဟစ်ခုနဲ့ score လုပ်သလာသပဌီသတော့၊ အဖဌစ်နိုင်ဆုံသ စာလုံသတလဲ ကို Viterbi algorithm ကိုသုံသပဌီသတော့ ရလေသတဲ့ နည်သလမ်သပါ။ Score လုပ်တဲ့အခါမဟာ အရင်ဆုံသ bigram အဘိဓာန်မဟာ ရဟိရင် အဲဒီ Probability ကို ယူပဌီသတော့၊ bigram အဘိဓာန်မဟာ အဲဒီ စာလုံသတလဲက ရဟာမတလေ့ရင်တော့ unigram အဘိဓာန်က probability ကို ယူပါတယ်။

Viterbi Algorithm က 1967 မဟာ Andrew J. Viterbi ဆိုတဲ့ အင်ဂျင်နီယာက propose လုပ်ခဲ့တဲ့ algorithm ပါ။ ဒီ algorithm က Dynamic Programming Algorithm အုပ်စုထဲမဟာ ပါပဌီသတော့ Automatic Speech Recognition (ASR), Data recording, Part-Of-Speech (POS) tagging, DNA sequencing, Space Communication စသည်ဖဌင့် ဧရိယာမျိုသစုံမဟာ အသုံသပဌုနေကဌပါတယ်။ ကျလန်တော်တို့ နေ့စဉ် အသုံသပဌုနေတဲ့ မိုဘိုင်သဖုန်သဆက်သလယ်မဟုတလေမဟာလည်သ Viterbi algorithm ကို သုံသထာသပါတယ်။ အဲဒါကဌောင့် လလန်ခဲ့တဲ့ နဟစ်ပေါင်သ ၅၀ အတလင်သမဟာ တကယ်ကို နာမည်ကဌီသတဲ့ algorithm တစ်ခုဖဌစ်ပဌီသ လက်တလေ့ သိထာသရင်လည်သ ကိုယ့်အလုပ်တလေအတလက် အသုံသဝင်တာမို့ ကလန်ပျူတာသမာသတလေ၊ အင်ဂျင်နီယာတလေအနေနဲ့က မသိမဖဌစ်လို့ကို ပဌောရပါလိမ့်မယ်။ တကယ်တမ်သ အသေသစိတ် လေ့လာချင်တဲ့ သူတလေက သူနဲ့ ဆက်စပ်နေတဲ့ Markov Process, Markov Property, Markov Chain, Hidden Markov Model (HMM) တို့ကို အရင်လေ့လာပါလို့ အကဌံပေသချင်ပါတယ်။ ဥပမာ တစ်ခုအနေနဲ့ Viterbi ရဲ့ အလုပ်လုပ်ပုံကို ပဌောရရင်... ဆိုကဌပါစို့ ကျလန်တော်တို့မဟာ HMM POS tagging လုပ်ပေသမဲ့ HMM မော်ဒယ်က ဆောက်ထာသပဌီသသာသဆိုရင် စာကဌောင်သ အသစ်တစ်ကဌောင်သကို အဲဒီ HMM မော်ဒယ်ကို pass လုပ်ပဌီသတော့ POS tagging လုပ်ခိုင်သတဲ့အခါမဟာ စာကဌောင်သ ထဲမဟာ ပါတဲ့ စာလုံသ အရေအတလက်ပေါ်ကို မူတည်ပဌီသတော့ ဖဌစ်နိုင်ချေရဟိတဲ့ tag sequence တလေက အမျာသကဌီသမို့လို့ အဖဌစ်နိုင်ဆုံသသော POS tag sequence ကို မော်ဒယ်က predict လုပ်တဲ့ အခါမျိုသမဟာ Viterbi ကို သုံသပဌီသ best path ကို ရဟာလို့ ရပါတယ်။ အဲဒီလို မလုပ်ပဲ brute force searching နဲ့ ရဟိသမျဟ path အကုန်ကိုတလက်ပဌီသမဟသာ ရလေသမယ်ဆိုပဌီသ စဉ်သစာသရင် ကလန်ပျူတာ memory က မနိုင်ပါဘူသ။ ဘာကဌောင့်လဲဆိုတော့ ngram အဘိဓာန်အပဌင်၊ HMM မဟာက Observed state နဲ့ Hidden state ဆိုပဌီသ နဟစ်ပိုင်သပါတာကဌောင့် ကျလန်တော်တို့က transition probability (POS-tag တစ်ခုနဲ့ တစ်ခုအကဌာသ) ရော emmission probability (POS-tag နဲ့ word အကဌာသ) ရော ကို တလက်ကဌရမဟာမို့ စာလုံသအရေအတလက်က မျာသလာတာနဲ့ အမျဟ operation က exponentially တိုသလာမဟာမို့ပါ။ ကလန်ပျူတာသမာသတလေ အမျာသစု သိထာသကဌတဲ့ Computational Complexity အနေနဲ့ ကဌည့်မယ်ဆိုရင် Brute Force algorithm က O(S^T) ဖဌစ်ပဌီသတော့ Viterbi algorithm က O(T*S^2) လို့ ဖော်ပဌလို့ ရပါတယ်။ ဒီနေရာမဟာ ပဌောနေတဲ့ "S" က HMM network ထဲမဟာ ရဟိနေတဲ့ state အရေအတလက် (i.e. the number of states) ကို ကိုယ်စာသပဌုပဌီသတော့၊ "T" ကတော့ စာကဌောင်သ တစ်ကဌောင်သမဟာ ရဟိတဲ့ စာလုံသအရေအတလက် (i.e. the length of the data sequence) ကို ကိုယ်စာသပဌုတာကဌောင့် Viterbi Algorithm က computational cost ကို အမျာသကဌီသ လျော့သလာသစေပါတယ်။

Word segmentation အလုပ်ကိုလည်သ graph အနေနဲ့ မဌင်ကဌည့်ပဌီသ စဉ်သစာသကဌည့်ကဌရအောင်။ ရဟင်သပဌရတာ လလယ်ကူအောင်လို့ input စာကဌောင်သကို မဌန်မာစာလုံသ "ဆရာက" ဆိုတဲ့ စာလုံသ နဟစ်လုံသပါတဲ့ စကာသစုလေသကိုပဲ ဥပမာသုံသပဌီသတော့ ရဟင်သပဌပါမယ်။ ဝင်လာတဲ့ စာကဌောင်သကို character တစ်လုံသချင်သစီ ဖဌတ်ပဌီသတော့ node တစ်ခုချင်သစီအတလက် probability တလေကို တလက်ပဌီသ break point ကို စဉ်သစာသတဲ့ နေရာမဟာ Brute force နဲ့သာဆိုရင် node အကုန်ကို တလက်ပဌီသမဟ final word boundary ကို ဆုံသဖဌတ်နိုင်မဟာ ဖဌစ်ပါတယ်။ သို့သော် Viterbi algorithm ရဲ့ အလုပ်လုပ်ပုံကတော့ memory မဟာ ရဟေ့က တလက်ခဲ့တဲ့ node တစ်ခုချင်သစီအထိ probability distribution ကို မဟတ်သာသထာသပဌီသတော့ လမ်သတဝက် node တနေရာရာမဟာ လက်ရဟိ အချိန်အထိ တလက်ခဲ့တဲ့ ရလဒ်တလေထဲကနေ မလိုအပ်တော့တဲ့ path တလေကို ဖဌုတ်ချထာသခဲ့ပဌီသ ဖဌစ်နိုင်ချေအရဟိဆုံသ best path ကိုပဲ ဆင့်ဆင့်ပဌီသ ဦသတည်တလက်သလာသတဲ့ ပုံစံပါ။ Algorithm အနေနဲ့ အလုပ်လုပ်ပုံကို တိတိကျကျ ပဌောရရင်တော့ forward order နဲ့ backward order ဆိုပဌီသတော့ နဟစ်ပိုင်သပါဝင်ပဌီသ၊ forward မဟာက node တစ်ခုချင်သစီကို ရောက်ဖို့အတလက် လာတဲ့ best path တလေကို တလက်သလာသပါတယ်။ Backward order အပိုင်သကတော့ စာကဌောင်သ အစကနေ အဆုံသအထိ best path ကို ဖောက်သလာသတဲ့ ပုံစံပါ။ Backward operation ရဲ့ calculation လုပ်တဲ့ပုံစံကတော့ စာကဌောင်သအဆုံသကနေ စာကဌောင်သရဟေ့ဆုံသကို ပဌောင်သပဌန် ပဌန်သလာသတဲ့ ပုံစံနဲ့တလက်ပါတယ်။ အဲဒါကဌောင့်မို့လို့လည်သ Backward လို့သုံသတာပါ။

ပထမဆုံသ လေ့လာတဲ့သူတလေအတလက်က follow လိုက်ဖို့ ခက်နိုင်တာကဌောင့် "ဆရာက" ဆိုတဲ့ စာကဌောင်သတို့လေသကိုပဲ graph အနေနဲ့ မဌင်ပဌီသ best path ကို ဘယ်လို တလက်သလဲ ဆိုတာကို အိုက်ဒီယာရသလာသဖို့ စဉ်သစာသကဌည့်ကဌရအောင်။ Fig.1 ကိုတည်ပဌီသတော့ ရဟင်သသလာသပါမယ်။ ပုံမဟာ ပဌထာသသလိုပါပဲ graph မဟာက node တလေရဟိမယ်။ အဲဒီ node တလေကို ဆက်နေတဲ့ path တလေလည်သ ရဟိပါလိမ့်မယ်။ node တစ်ခုချင်သစီက character တစ်လုံသချင်သစီကို ကိုယ်စာသပဌုပဌီသတော့ path တစ်ခုချင်သစီက input စာကဌောင်သကို ဘယ်လို ပုံစံမျိုသနဲ့ segmentation လုပ်သလာသမယ်ဆိုတဲ့ လမ်သကဌောင်သတလေ ဖဌစ်ပါတယ်။ Path တစ်ခုစီမဟာ ဖဌတ်သလာသမယ့်စာလုံသနဲ့အတူ တလဲရေသထာသတဲ့ ဂဏန်သတလေက path weight တလေဖဌစ်ပဌီသ၊ လက်ရဟိ စာလုံသဖဌတ်ဖို့လုပ်နေတဲ့ စာကဌောင်သရဲ့ unigram negative log property တလေ လို့ယူဆပေသပါ။

word segmentation as graph

Fig.1 Word segmentation as graph for the input sentence "ဆရာက"

ပရိုဂရမ်အနေနဲ့က အလုပ်လုပ်တဲ့အခါမဟာ character လေသလုံသဖဌစ်တဲ့ "ဆ" "ရ" "ာ" နဲ့ "က" ကို တလဲလို့ ရတဲ့ sequence pattern အကုန်လုံသကို စဉ်သစာသရတာမို့ တကယ်က အောက်ပါ path တလေကို ထည့်သလင်သစဉ်သစာသရပါတယ်။

  • Path1: 0--->1--->2--->3--->4 = 2.0 + 2.5 + 4.1 + 1.0 = 9.6 = ဆ | ရ | ာ | က
  • Path2: 0--->2--->3--->4 = 3.3 + 4.1 + 1.0 = 8.4 = ဆရ | ာ | က
  • Path3: 0--->3--->4 = 1.2 + 1.0 = 2.2 = ဆရာ | က
  • Path4: 0--->4 = 2.8 = ဆရာက
  • Path5: 0--->2--->4 = 3.3 + 3.8 = 7.1 = ဆရ | ာက
  • Path6: 0--->1--->4 = 2.0 + 3.9 = 5.9 = ဆ | ရာက
  • Path7: 0--->1--->3--->4 = 2.0 + 2.6 + 1.0 = 5.6 = ဆ | ရာ | က

အထက်မဟာ ပဌထာသတဲ့ path တလေထဲကမဟ Viterbi algorithm က best path သို့မဟုတ် shortest path ကိုရလေသမဟာ ဖဌစ်ပါတယ်။ အဲဒါကဌောင့် Path3: 0--->3--->4 = 1.2 + 1.0 = 2.2 က path တလေအာသလုံသထဲမဟာ တန်ဖိုသအနိမ့်ဆုံသမို့လို့ semented output အနေနဲ့က "ဆရာ | က" ဆိုပဌီသတော့ မဟန်မဟန်ကန်ကန် word segmentation လုပ်ပေသမဟာ ဖဌစ်ပါတယ်။ တကယ်တမ်သတလက်တဲ့အခါမဟာ စာလုံသ တစ်လုံသချင်သစီရဲ့ probability က unigram အဘိဓာန်က လာတာဖဌစ်ပဌီသတော့ negative log probability ကို သုံသတာကဌောင့် အောက်ပါ ပုံစံမျိုသတလက်တာ ဖဌစ်ပါတယ်။ Shortest path ကို ရလေသတဲ့ အလုပ်ကို Backward operation မဟာ လုပ်သလာသတာ ဖဌစ်ပါတယ်။

-log(P( ဆရာ )) + -log(P( က )) = 1.2 + 1.0 = 2.2

အထက်က Fig.1 မဟာ ပဌခဲ့တဲ့ "ဆရာက" ဆိုတဲ့ input စာကဌောင်သအတလက် စာလုံသ ဖဌတ်လို့ရတဲ့ လမ်သကဌောင်သတလေ အမျိုသမျိုသရဟိတဲ့အထဲကနေ shortest path ကို graph အနေနဲ့ ဆလဲပဌရရင်တော့ အောက်ပါလို ပုံမျိုသ (Fig. 2) ကို ဆလဲလို့ ရပါလိမ့်မယ်။

shortest path

Fig.2 the shortest path for the input sentence "ဆရာက"

တကယ့် လက်တလေ့မဟာက ဆရာနဲ့ စတဲ့ မဌန်မာစာလုံသတလေက corpus ထဲမဟာ အမျာသကဌီသရဟိမဟာမို့ ဒေတာမျာသမျာသနဲ့ ngram အဘိဓာန်ကို ဆောက်ထာသရင် ဆောက်ထာသသလို စာကဌောင်သ ရဟည်ရင် ရဟည်သလို word boundary ကို ခန့်မဟန်သဖို့အတလက်က ကလန်ပျူတာက တလက်ရမယ့် path တလေက သန်သနဲ့ချီပဌီသ ရဟိသလာသနိုင်ပါတယ်။ အဲဒါကဌောင့် HMM လိုမော်ဒယ်တလေရဲ့ decoding မဟာ Viterbi algorithm ကို သုံသကဌတာဖဌစ်ပါတယ်။

မဌန်မာစာအတလက် Word Segmentation tool ကို implementation လုပ်ဖို့ စဉ်သစာသတဲ့အခါမဟာလည်သ ဒေတာသာ ရဟိမယ်ဆိုရင် လလယ်လလယ်ကူကူနဲ့ training လုပ်ပဌီသ ရိုသရဟင်သပဌီသ powerful ဖဌစ်တဲ့ algorithm နဲ့ စာလုံသတလေကို ဖဌတ်ပေသဖို့ စဉ်သစာသတဲ့အခါမဟာ Viterbi algorithm ကိုပဲ သုံသဖို့ ဆုံသဖဌတ်ခဲ့ပါတယ်။ ရဟေ့က ဆရာတလေဖဌစ်တဲ့ Dr. Peter Norvig (အမေရိကန် ကလန်ပျူတာသိပ္ပံပညာရဟင်, Google LLC ရဲ့ ဒါရိုက်တာ) က ရေသသာသထာသတဲ့ Beautiful Data စာအုပ်ရဲ့ Chapter 14: Natural Language Corpus Data ရဲ့ အခန်သမဟာသုံသထာသတဲ့ ngram အဘိဓာန်ဆောက်ပဌီသတော့ Viterbi table ဆောက်ပဌီသ စာလုံသဖဌတ်ပဌထာသတာကို မဟီငဌမ်သထာသပါတယ်။ Coding ကလည်သ updated version code, Mark Dong ကို မဟီငဌမ်သထာသပါတယ်။ ကိုယ့် corpus နဲ့ ngram အဘိဓာန်ကို ဆောက်နိုင်အောင် ရေသတဲ့အပိုင်သနဲ့ plain text ဖိုင် ngram အဘိဓာန်တလေအစာသ binary အဘိဓာန်တလေကို သုံသတဲ့ အပိုင်သတလေကို ဖဌည့်စလက် coding လုပ်ခဲ့ပါတယ်။ Recursion limit ကိုလည်သ sys.setrecursionlimit(10**6) ဆိုပဌီသ ထည့်ခဲ့ပါတယ်။ myWord Segmentation tool မဟာ ရေသထာသတဲ့ viterbi function က အောက်ပါအတိုင်သပါ။ coding ဖတ်နိုင်တဲ့သူတလေက coding ကိုဖတ်ရင်သ Vitabi algorithm နဲ့ word segmentation ကို ဘယ်လို လုပ်သလာသတယ်ဆိုတာကို လေ့လာတာက ပိုမဌန်ချင်လည်သ မဌန်နိုင်ပါတယ်။

@functools.lru_cache(maxsize=2**10)
#maxlen=20
def viterbi(text, prev='<S>', maxlen=20):
    if not text:
        return 0.0, []
    
    print("text: ", text)
    textlen = min(len(text), maxlen)
    splits = [(text[:i + 1], text[i + 1:]) for i in range(textlen)]

    candidates = []
    for first_word, remain_word in splits:
        #pdb.set_trace()
        first_prob = math.log10(conditionalProb(first_word, prev))
        print("first_prob of condProb(", first_word, ", ", prev, "): ", first_prob )
        remain_prob, remain_word = viterbi(remain_word, first_word)
        print("remain_prob: ", remain_prob, ", remain_word: ", remain_word)
        candidates.append((first_prob + remain_prob, [first_word] + remain_word))
        #print("first_prob: ", str(first_prob), ", remain_prob: ", remain_prob, ", [first_word]:", [first_word], ", remain_word: ", remain_word)
        print("Candidates: ", candidates)
        
    print("max(candidates): " + str(max(candidates)))
    print("====================")
    return max(candidates)

အလုပ်လုပ်ပုံကို trace လုပ်ရတာ လလယ်အောင်လို့ print statement တလေကိုပါ ထပ်ဖဌည့်ပဌီသ viterbi function ကို "ဆရာက" ဆိုတဲ့ စာကဌောင်သတစ်ကဌောင်သတည်သကိုပဲ ထည့်ပဌီသ run ပေသထာသပါတယ်။ ကလန်ပျူတာ terminal screen မဟာ ရိုက်ထုတ်ပေသလာတဲ့ စာကဌောင်သတလေကတော့ အောက်ပါအတိုင်သပါ။ ဒီ function က recursive function အနေနဲ့ ခေါ်သုံသထာသတာကိုလည်သ ဂရုပဌုပါ။

$ python ./myword.py word ./one_line.txt ./one_line.word 
text:  ဆရာက
first_prob of condProb( ဆ ,  <S> ):  -2.3682169728893223
text:  ရာက
first_prob of condProb( ရ ,  ဆ ):  0.15368326096895993
text:  ာက
first_prob of condProb( ာ ,  ရ ):  -4.1075915061395
text:  က
first_prob of condProb( က ,  ာ ):  0.39394528587814026
remain_prob:  0.0 , remain_word:  []
Candidates:  [(0.39394528587814026, ['က'])]
max(candidates): (0.39394528587814026, ['က'])
====================
remain_prob:  0.39394528587814026 , remain_word:  ['က']
Candidates:  [(-3.71364622026136, ['ာ', 'က'])]
first_prob of condProb( ာက ,  ရ ):  -6.010681493131443
remain_prob:  0.0 , remain_word:  []
Candidates:  [(-3.71364622026136, ['ာ', 'က']), (-6.010681493131443, ['ာက'])]
max(candidates): (-3.71364622026136, ['ာ', 'က'])
====================
remain_prob:  -3.71364622026136 , remain_word:  ['ာ', 'က']
Candidates:  [(-3.5599629592924003, ['ရ', 'ာ', 'က'])]
first_prob of condProb( ရာ ,  ဆ ):  -0.7926188753050689
text:  က
first_prob of condProb( က ,  ရာ ):  0.39394528587814026
remain_prob:  0.0 , remain_word:  []
Candidates:  [(0.39394528587814026, ['က'])]
max(candidates): (0.39394528587814026, ['က'])
====================
remain_prob:  0.39394528587814026 , remain_word:  ['က']
Candidates:  [(-3.5599629592924003, ['ရ', 'ာ', 'က']), (-0.39867358942692865, ['ရာ', 'က'])]
first_prob of condProb( ရာက ,  ဆ ):  -7.010681493131443
remain_prob:  0.0 , remain_word:  []
Candidates:  [(-3.5599629592924003, ['ရ', 'ာ', 'က']), (-0.39867358942692865, ['ရာ', 'က']), (-7.010681493131443, ['ရာက'])]
max(candidates): (-0.39867358942692865, ['ရာ', 'က'])
====================
remain_prob:  -0.39867358942692865 , remain_word:  ['ရာ', 'က']
Candidates:  [(-2.766890562316251, ['ဆ', 'ရာ', 'က'])]
first_prob of condProb( ဆရ ,  <S> ):  -6.010681493131443
text:  ာက
first_prob of condProb( ာ ,  ဆရ ):  -4.1075915061395
remain_prob:  0.39394528587814026 , remain_word:  ['က']
Candidates:  [(-3.71364622026136, ['ာ', 'က'])]
first_prob of condProb( ာက ,  ဆရ ):  -6.010681493131443
remain_prob:  0.0 , remain_word:  []
Candidates:  [(-3.71364622026136, ['ာ', 'က']), (-6.010681493131443, ['ာက'])]
max(candidates): (-3.71364622026136, ['ာ', 'က'])
====================
remain_prob:  -3.71364622026136 , remain_word:  ['ာ', 'က']
Candidates:  [(-2.766890562316251, ['ဆ', 'ရာ', 'က']), (-9.724327713392803, ['ဆရ', 'ာ', 'က'])]
first_prob of condProb( ဆရာ ,  <S> ):  -1.2541214501247606
text:  က
first_prob of condProb( က ,  ဆရာ ):  0.39394528587814026
remain_prob:  0.0 , remain_word:  []
Candidates:  [(0.39394528587814026, ['က'])]
max(candidates): (0.39394528587814026, ['က'])
====================
remain_prob:  0.39394528587814026 , remain_word:  ['က']
Candidates:  [(-2.766890562316251, ['ဆ', 'ရာ', 'က']), (-9.724327713392803, ['ဆရ', 'ာ', 'က']), (-0.8601761642466204, ['ဆရာ', 'က'])]
first_prob of condProb( ဆရာက ,  <S> ):  -4.709651497467462
remain_prob:  0.0 , remain_word:  []
Candidates:  [(-2.766890562316251, ['ဆ', 'ရာ', 'က']), (-9.724327713392803, ['ဆရ', 'ာ', 'က']), (-0.8601761642466204, ['ဆရာ', 'က']), (-4.709651497467462, ['ဆရာက'])]
max(candidates): (-0.8601761642466204, ['ဆရာ', 'က'])
====================

Building Unigram, Bigram Dictionaries for Word Unit

ကိုယ့်မဟာ manual word segmentation လုပ်ထာသပဌီသသာသ corpus က အဆင့်သင့်ရဟိတယ်ဆိုရင် myword နဲ့ n-gram dictionary ဆောက်ဖို့အတလက်က အောက်ပါအတိုင်သ command ပေသပါ။
ဒီနေရာမဟာ myword က unigram, bigram အဘိဓာန်တလေကို text file format အနေနဲ့ရော binary file format အနေနဲ့ရော ဆောက်ပေသသလာသမဟာမို့ အဲဒီ output filename တလေကို --unigram_word_txt unigram-word.txt, --bigram_word_txt bigram-word.txt, --unigram_word_bin unigram-word.bin, --bigram_word_bin bigram-word.bin ဆိုပဌီသ ကိုယ်ပေသချင်တဲ့ ဖိုင်နာမည်တလေကို assign လုပ်သလာသလို့ ရပါတယ်။

Word n-gram dictionary building with full dictionary filenames parameters:

$ python ./myword.py build_dict --unigram_word_txt unigram-word.txt --bigram_word_txt bigram-word.txt --unigram_word_bin unigram-word.bin --bigram_word_bin bigram-word.bin ./corpus2.1k 

တကယ်လို့ default ngram dictionary နာမည်တလေနဲ့ပဲ ဆောက်သလာသမယ်၊ ဖိုင်နာမည်တလေကို သီသသန့် assign လုပ်တာမျိုသ မလုပ်ဘူသ ဆိုရင်တော့ အောက်ပါအတိုင်သ command အတိုနဲ့ပဲ ngram အဘိဓာန်တလေကို ဆောက်သလာသလို့ ရပါတယ်။
Word n-gram dictionary building with default filenames:

$ python ./myword.py build_dict ./corpus2.1k 

Word Segmentation with "myWord" Segmentation Tool

myword နဲ့ word segmentation လုပ်တာကို default n-gram dictionary တလေကိုပဲ သုံသပဌီသ စာလုံသဖဌတ်မယ်ဆိုရင်တော့ အောက်ပါအတိုင်သ command ပေသရပါတယ်။
ဒီနေရာမဟာ ./test.txt ဖိုင်က input file ဖဌစ်ပဌီသတော့ ./test.word ကတော့ စာလုံသဖဌတ်ပဌီသ ထလက်လာတဲ့ ဖိုင်ကိုသိမ်သစေချင်တဲ့ နာမည်ပါ။

Word segmentation with default n-gram dictionaries:

$ python ./myword.py word ./test.txt ./test.word

input ဖိုင်က အောက်ပါအတိုင်သ သုံသထာသပါတယ်။
(space တလေပါနေလည်သ myword က auto remove လုပ်ပေသသလာသမဟာမို့ တကူှတက space တလေကို ဖဌုတ်ပဌီသမဟ input လုပ်စရာမလိုပါဘူသ။ ခုက ဥပမာအနေနဲ့ မဌင်သာအောင်သာ ပဌထာသတာပါ)

$ cat test.txt
ကျလန်တော်ကသုတေသနသမာသပါ။
နေ့ရောညရောမဌန်မာစာနဲ့ကလန်ပျူတာနဲ့ပဲအလုပ် မျာသ ပါ တယ်
မင်သကကောဘာအလုပ်လုပ်တာလဲ။
ပဌောပဌပါအုံသ
ကောဖီလည်သထပ်သောက်ချင်ရင်ပဌောကလာ
မန္တလေသမဟာဒေါ်အောင်ဆန်သစုကဌည်မိန့်ခလန်သပဌောမယ်တဲ့။

word segmented လုပ်ပဌီသ ထလက်လာတဲ့ output ဖိုင်က အောက်ပါအတိုင်သပါ။

$ cat test.word
ကျလန်တော် က သုတေသန သမာသ ပါ ။
နေ့ ရော ည ရော မဌန်မာ စာ နဲ့ ကလန်ပျူတာ နဲ့ ပဲ အလုပ် မျာသ ပါ တယ်
မင်သ က ကော ဘာ အလုပ် လုပ် တာ လဲ ။
ပဌော ပဌ ပါ အုံသ
ကောဖီ လည်သ ထပ် သောက် ချင် ရင် ပဌော ကလာ
မန္တလေသ မဟာ ဒေါ်အောင်ဆန်သစုကဌည် မိန့်ခလန်သ ပဌော မယ် တဲ့ ။

⚠ unigram, bigram dictionary တလေကို ဆောက်တဲ့အခါမဟာ text file format အနေနဲ့ရော binary file format အနေနဲ့ရော ဆောက်ပေသသလာသပေမဲ့ word segmentation လုပ်တဲ့အခါမဟာတော့ binary dictionary နဟစ်ခုပဲ လိုအပ်ပါတယ်။ text file format အဘိဓာန်တလေက developer/researcher တလေအနေနဲ့ မျက်လုံသနဲ့ စစ်ကဌည့်ပဌီသ corpus ကို update လုပ်တာ သို့မဟုတ် အဘိဓာန်ကို update လုပ်ပဌီသ binary အဖဌစ် ပဌောင်သတာတလေ လုပ်နိုင်အောင်လို့ facility အနေနဲ့ ထည့်ပေသထာသတာပါ။ ⚠

word segmentation လုပ်တဲ့ အခါမဟာ unigram, bigram အဘိဓာန်တလေကို assign လုပ်ပဌီသ ဖဌတ်မယ်ဆိုရင်တော့ အောက်ပါအတိုင်သ command ပေသပဌီသ run ပါ။
(Word segmentation with unigram, binary n-gram dictionaries)

$ python ./myword.py word --unigram_word_bin ./unigram-word.bin --bigram_word_bin ./bigram-word.bin ./test.txt ./test.word

Word Segmentation ဖဌတ်တဲ့အခါမဟာ default က space နဲ့ခဌာသပေသမဟာ ဖဌစ်ပေမဲ့ delimiter ကိုလည်သ အမျိုသမျိုသ ပဌောင်သလို့ ရပါတယ်။ ဥပမာ delimiter ကို pipe အဖဌစ်ထာသပဌီသ word segmentation လုပ်ချင်တယ် ဆိုရင်တော့ အောက်ပါအတိုင်သ command ပေသ run ပါ။

(Word segmentation with delimiter "pipe")

$ python ./myword.py word --delimiter "|" ./test.txt ./test.word

ထလက်လာတဲ့ segmented output ဖိုင်က အောက်ပါအတိုင်သပါ။

ကျလန်တော်|က|သုတေသန|သမာသ|ပါ|။
နေ့|ရော|ည|ရော|မဌန်မာ|စာ|နဲ့|ကလန်ပျူတာ|နဲ့|ပဲ|အလုပ်|မျာသ|ပါ|တယ်
မင်သ|က|ကော|ဘာ|အလုပ်|လုပ်|တာ|လဲ|။
ပဌော|ပဌ|ပါ|အုံသ
ကောဖီ|လည်သ|ထပ်|သောက်|ချင်|ရင်|ပဌော|ကလာ
မန္တလေသ|မဟာ|ဒေါ်အောင်ဆန်သစုကဌည်|မိန့်ခလန်သ|ပဌော|မယ်|တဲ့|။

Theory: Unsupervised Phrase Segmentation with NPMI

Phrase Segmentation လုပ်တာက Normalized pointwise mutual information (NPMI) နဲ့ပါ။
Assoc. Prof. Daichi Mochihashi ရဲ့ ဂျပန်လိုရေသထာသတဲ့ blog ကို တလေ့ပဌီသ မဌန်မာစာအတလက် စမ်သကဌည့်ဖို့ အိုက်ဒီယာ ရခဲ့ပါတယ်။ သူ ရဟင်သပဌထာသတာကိုပဲ အခဌေခံပဌီသ ဗမာစာအတလက် စမ်သခဲ့တဲ့ အပိုင်သကို ရဟင်သပဌသလာသပါမယ်။

Wrod2Vec နဲ့ ပတ်သက်တဲ့ နာမည်ကဌီသ စာတမ်သနဟစ်စောင် ကို အရင်ဆုံသ refer လုပ်ကဌမဟ အသေသစိတ် ဇာတ်ရည်လည်ပါလိမ့်မယ်။

ပထမစာတမ်သ ဖဌစ်တဲ့ Efficient Estimation of Word Representations in Vector Space, (Mikolov et al., 2013) စာတမ်သထဲမဟာ အောက်ပါအတိုင်သ ဖော်ပဌထာသတာကို တလေ့ရပါလိမ့်မယ်။

We have included in our test set only single token words, thus multi-word entities are not present (such as New York).

ပထမစာတမ်သရဲ့ test set မဟာ single token word တလေပဲ သုံသထာသကဌောင်သ ဖော်ပဌထာသပါတယ်။ ဆိုလိုတာက "New York", "ice cream", "high school", "hot dog", "living room", "full moon", "up to date", "part-time work", "state of the art" တို့လို စာလုံသ နဟစ်လုံသနဲ့ အထက်တလဲနေတဲ့ စကာသလုံသတလေ (word) တလေကို word2vec အနေနဲ့ train လုပ်မယ်ဆိုရင် အရင်ဆုံသ အမဌဲတမ်သ တလဲပဌီသသုံသနေတဲ့ စာလုံသတလဲတလေ တနည်သအာသဖဌင့် phrase တလေကို ငါတို့က ကဌိုသိဖို့ လိုအပ်ပါတယ်။ အဲဒီလို သိပဌီသမဟသာ word2vec ကို train မလုပ်ခင်မဟာ preprocessing အနေနဲ့ ဥပမာ "new_york", "ice_cream", ..., "up_to_date", "part_time_work", "state_of_the_art" အဖဌစ် underscore နဲ့ တလဲတာမျိုသ လုပ်ပဌီသ စာလုံသတစ်လုံသအနေနဲ့ training corpus ထဲမဟာ ကဌိုပဌင်ထာသဖို့ လိုအပ်ပါလိမ့်မယ်။ အဲဒီ လိုမျိုသ NLP task အတလက်က supervised approach နဲ့ ဆိုရင် NER (Name Entity Recognition) model နဲ့ လုပ်လို့ ရပေမဲ့ NER model ဆောက်ဖို့အတလက်က NER corpus က ရဟိနေမဟ ဖဌစ်ပါလိမ့်မယ်။ အဲဒါကဌောင့် NER corpus ကို မသုံသပဲနဲ့ unsupervised approach အနေနဲ့ သလာသမယ်ဆိုရင် ဘယ်လို လုပ်လို့ ရနိုင်တယ် ဆိုတာကို Word2Vec ရဲ့ဒုတိယစာတမ်သလို့ ပဌောလို့ရတဲ့ Distributed Representations of Words and Phrases and their Compositionality, (Mikolov et al., 2013) စာတမ်သရဲ့ Section 4. Learning Phrases မဟာ Formula No. 6 အနေနဲ့ အောက်ပါအတိုင်သ ဖော်ပဌထာသတာကို တလေ့ရပါလိမ့်မယ်။

formula no.6 of Word2Vec Paper

ဒီနေရာမဟာ ပဌောနေတဲ့ n (v, w), n (v), n (w) တလေက bigram နဲ့ unigram frequency တလေ ဖဌစ်ပဌီသတော့ ÎŽ က frequency နိမ့်တဲ့ စကာသလုံသတလဲတလေက ထိပ်ပိုင်သကို ရောက်မလာဖို့အတလက် ထိန်သညဟိတဲ့ discount factor ပါ။ Phrase တလေကို ဆလဲထုတ်နိုင်ဖို့အတလက်က threshold တစ်ခု သတ်မဟတ်ထာသပဌီသ အဲဒီ threshold value အထက်မဟာ ရဟိတဲ့ bigram စကာသလုံသတလဲတလေကို ရလေသယူလိုက်ယုံပါပဲ။ Threshold value အထက် ဆိုတာကို probability အနေနဲ့ စဉ်သစာသကဌည့်ရင် p (v, w) = n (v, w) / N, p (v) = n (v) / N, p (w) = n ဆိုပဌီသ ဖော်မဌူလာအနေနဲ့ ရေသလို့ ရပါတယ်။ ဒီနေရာမဟာ "N" ဆိုတာက unigram စုစုပေါင်သတန်ဖိုသပါ။ ÎŽ ကို ဖယ်ပဌီသတော့ score တလက်ဖို့အတလက် စဉ်သစာသရင် အောက်ပါအတိုင်သ ရေသလို့ ရပါတယ်

score (v, w) = n (v, w) / (n (v) * n (w)) = (p (v, w) * N) / (p (v) * N * p (w) * N) = p (v, w) / (p (v) * p (w) * N)

ဒါကဌောင့် ဒီ score တလက်တဲ့ အပိုင်သက self-mutual information PMI တလက်တဲ့ PMI (v, w) = log p (v, w) / (p (v) * p (w)) ဆိုတဲ့ ဖော်မဌူလာနဲ့ အကုန်လုံသလိုလို ဆင်တူဖဌစ်တာကို တလေ့ရပါလိမ့်မယ်။ ဒါပေမဲ့ သေသေချာချာ ပဌန် နဟိုင်သယဟဉ်ကဌည့်တဲ့ အခါမဟာ၊ အော်ရဂျင်နယ် ဖော်မဌူလာမဟာက 1/N ဆိုတဲ့ factor က ပါဝင်ပဌီသတော့ အဲဒါက corpus အပေါ်မဟာ မူတည်နေလို့ ထလက်လာမယ့် score က အခဌေခံအာသဖဌင့် corpus ရဲ့ length ပေါ်မဟာ သလာသပဌီသ မူတည်နေပါတယ်။ corpus ကို အပဌောင်သအလဲ ထပ်တိုသတာမျိုသ မလုပ်ပဲ fixed လုပ်ထာသပဌီသတော့ threshold တန်ဖိုသကို search လုပ်တာမျိုသလုပ်ရင်တော့ အတိုင်သအတာ တစ်ခုအထိ ပဌေလည်ပေမဲ့ threshold ရဲ့ အဓိပ္ပါယ်က နာသလည်ရခက်တဲ့အပဌင် length မတူတဲ့ စာကဌောင်သတလေကို သုံသပဌီသတော့ score တလေကို နဟိုင်သယဟဉ်ကဌည့်ပဌီသသလာသမယ်ဆိုရင် ရလာတဲ့ phrase တလေက ပုံမဟန် လူတလေက သုံသနေကဌတဲ့ phrase နဲ့တော့ တထပ်တည်သ ကျမဟာ မဟုတ်ပါဘူသ။

corpus ကို independent ဖဌစ်ဖို့အတလက်က original score တန်ဖိုသကို N နဲ့ မဌဟောက်လို့ ရပါတယ်။ သို့သော် အခုပဌောနေတဲ့ score ဆိုတာက PMI ကို တလက်တာ ဖဌစ်တာကဌောင့်

  • PMI ရဲ့က အာသနည်သချက်က low frequency word တလေကို အာသနည်သတာ
  • PMI scale ကလည်သ ဒေတာပေါ်မူတည်ပဌီသနေတာ

စတဲ့ အချက်တလေလည်သ ရဟိတာကဌောင့် Normalized PMI (NPMI) (Bouma 2009) ကို သုံသသင့်တယ်လို့ ထင်ပါတယ်။
NPMI ဆိုတာက အောက်ပါအတိုင်သ သတ်မဟတ်ထာသပါတယ်။

NPMI (v, w) = log p (v, w) / (p (v) * p (w)) / (-log p (v, w))

NPMI ကို -1≩NPMI(v,w)≩1 ဆိုတဲ့ range အတလင်သမဟာ သတ်မဟတ်ထာသတာကဌောင့် 1 ဖဌစ်နေတဲ့ အချိန်မဟာ v နဲ့ w တို့ဟာ တိုက်ရိုက် correlation ဖဌစ်နေပဌီသ -1 ဖဌစ်နေတဲ့ အချိန်မဟာတော့ inverse correlation ဖဌစ်နေကဌောင်သကို နာသလည်ရ လလယ်ကူပါတယ်။ ပဌီသတော့ PMI မဟာတုန်သက ရဟိခဲ့တဲ့ "p(v)" တို့ "p(w)" တို့ရဲ့ တန်ဖိုသတလေက အရမ်သ သေသငယ်တဲ့ အခါမဟာ score ကို ဖောင်သပလစေနိုင်တဲ့ အာသနည်သချက်ကိုလည်သ ရဟောင်ပဌီသသလာသ ဖဌစ်သလာသပါလိမ့်မယ်။ အဲဒီလိုသာဆိုရင် Word2vec ရဲ့ အော်ရဂျင်နယ်စာတမ်သမဟာ သုံသခဲ့တဲ့ heuristic discount coefficient တန်ဖိုသ ဖဌစ်တဲ့ ÎŽ လည်သ မလိုအပ်တော့ပါဘူသ။

အဲဒါကဌောင့် script တစ်ပုဒ် ရေသပဌီသတော့ phrase အော်တိုဖဌတ်တာကို စမ်သ ကဌည့်ဖဌစ်ခဲ့ပါတယ်။ Phrase recognition သို့မဟုတ် phrase segmentation လုပ်တဲ့ core အပိုင်သကိုပဲ ရေသဖို့အတလက် unigram, bigram frequency တလေကို dictionary နဟစ်ခုအနေနဲ့ သိမ်သထာသခဲ့ပဌီသ၊ word bigram (v, w) က phrase ဖဌစ်မဖဌစ်ကို ဆုံသဖဌတ်တဲ့ အပိုင်သကိုပဲ Python script နဲ့ ရေသပဌရရင် အောက်ပါအတိုင်သ ဖဌစ်ပါလိမ့်မယ်။

def compute_phrase (unigram, bigram, threshold = 0.5):
    N = sum (list (unigram.values ​​()))
    phrases = {}
    for bi, freq in bigram.items ():
        if freq> 1:
            v = bi [0]; w = bi [1]
            npmi = (log (N) + log (freq) --log (unigram [v]) --log (unigram [w])) \
                    / (log (N) --log (freq))
            if npmi> threshold:
                phrases [bi] = npmi
    return phrases

Threshold တန်ဖိုသက ဂျပန်စာအတလက်က 0.5 ထာသပဌီသ စမ်သခဲ့ပေမဲ့ မဌန်မာစာအတလက်က (0.1...0.5) ထာသပဌီသ အမျိုသမျိုသ စမ်သကဌည့်ခဲ့ပါတယ်။
အထက်ပါ algorithm ကို word segmentation လုပ်ထာသတဲ့ မဌန်မာစာ corpus တစ်ခုလုံသကို pass လုပ်ပဌီသသလာသတဲ့ အခါမဟာ စာလုံသနဟစ်လုံသတလဲ စကာသစု (two-word phrase) တလေကို ရရဟိလာမဟာ ဖဌစ်ပါတယ်။ တကယ်လို့ ဒုတိယအကဌိမ် pass လုပ်ပဌီသသလာသရင်တော့ စာလုံသ နဟစ်လုံသ ကနေ လေသလုံသအထိ တလဲလျက်ရဟိနေတတ်တဲ့ စကာသစု (two- to four-word phrase) တလေကို ရရဟိလာမဟာ ဖဌစ်ပါတယ်။ အဲဒါကဌောင့် သီအိုရီအရကတော့ passing ကို n pass အထိ လုပ်မယ် ဆိုရင် 2 ကနေ 2^n စာလုံသတလဲ phrase တလေကို ရရဟိနိုင်မဟာ ဖဌစ်ပါတယ်။

Phrase Segmentation with "myWord" Segmentation Tool

လက်နဲ့စာလုံသ ဖဌတ်ထာသတဲ့ (i.e. manual word segmentation) လုပ်ထာသတဲ့ စာကဌောင်သရေ ၅သိန်သကျော် ရဟိတဲ့ မဌန်မာစာ corpus ကို သုံသပဌီသ phrase segmentation experiment တချို့ လုပ်ကဌည့်ကဌရအောင်။

Threshold value=0.1, frequency=3, 1 time pass အနေနဲ့ run ကဌည့်ထာသပါတယ်။

$ time python ./myword.py train_phrase -l 1 -t 0.1 -f 3 --unigram_phrase_txt unigram.l1.t0.1f3.txt --bigram_phrase_txt bigram.l1.t0.1f3.txt --unigram_phrase_bin unigram.l1.t0.1f3.bin --bigram_phrase_bin bigram.l1.t0.1f3.bin ./corpus2 ./train.l1t0.1f3.out
{'command': 'train_phrase', 'iteration': 1, 'threshold': 0.1, 'minfreq': 3, 'unigram_phrase_txt': 'unigram.l1.t0.1f3.txt', 'bigram_phrase_txt': 'bigram.l1.t0.1f3.txt', 'unigram_phrase_bin': 'unigram.l1.t0.1f3.bin', 'bigram_phrase_bin': 'bigram.l1.t0.1f3.bin', 'input': './corpus2', 'output': './train.l1t0.1f3.out'}
computing phrases: threshold = 0.1 minfreq = 3
pass [1/1]..
- computing phrases..
- writing output..
done.

real	1m4.555s
user	1m3.892s
sys	0m0.484s

pass က တစ်ခါပဲ လုပ်တာမို့ corpus ထဲမဟာ ပါဝင်တဲ့ bigram စာလုံသတလဲတလေရဲ့ frequency ပေါ်မူတည်ပဌီသ threshold value ပေါ်ကို မူတည်ပဌီသ ဆလဲထုတ်လို့ ရလာတဲ့ မဌန်မာစာ phrase ဥပမာ တချို့က အောက်ပါအတိုင်သပါ။

$ tail ./train.l1t0.1f3.out
သူ_ဟာ လက်ဝဟေ့ပလဲ မဟာ အနိုင်_ရ နိုင် စရာ_ရဟိ တယ်
သူ_ဟာ လက်ဝဟေ့ ထိုသသတ်ပလဲ မဟာ_ရဟုံသနိမ့် ဖို့_မ ဖဌစ်_နိုင် လောက် ဘူှ
သူငယ်_ကလေသ ဟာ ငါသ_မျဟာသ နေ_တယ်
သူ ကံကောင်သ ရင် ငါသ တစ်_ကောင် မိ နိုင် တယ်
သစ်ကိုင်သ ဟာ သိပ်_မ ခိုင် ဘူှ
၎င်သ ဟာ‍ ကျိုသ ချင် ကျိုသ_သလာသ နိုင် တယ်
သစ်ကိုင်သ_ကျိုသ ကျ_သလာသ ရင်_ကောင်ကလေသ ဟာ မဌစ်_ထဲ ကို ကျ_သလာသ ဖို့ အလာသအလာ_ရဟိ တယ်
သူ မဌစ်_ထဲ ကို ကျ_သလာသ ရင် သူ ရေစို ဖို့ ဖဌစ် ကောင်သ ဖဌစ်_နိုင် လိမ့်_မယ်
ရုပ်ပုံ ထဲ_မဟာ ပျာသ တစ်_ကောင် ရဟိ_တယ်
၎င်သ ဘာ_လုပ် နိုင် မယ်_လို့ ခင်ဗျာသ ထင်_သလဲ

Threshold value=0.1, frequency=3, 2 time pass ထာသပဌီသ run ထာသပါတယ်။

$ time python ./myword.py train_phrase -l 2 -t 0.1 -f 3 --unigram_phrase_txt unigram.l2.t0.1f3.txt --bigram_phrase_txt bigram.l2.t0.1f3.txt --unigram_phrase_bin unigram.l2.t0.1f3.bin --bigram_phrase_bin bigram.l2.t0.1f3.bin ./corpus2 ./train.l2t0.1f3.out
{'command': 'train_phrase', 'iteration': 2, 'threshold': 0.1, 'minfreq': 3, 'unigram_phrase_txt': 'unigram.l2.t0.1f3.txt', 'bigram_phrase_txt': 'bigram.l2.t0.1f3.txt', 'unigram_phrase_bin': 'unigram.l2.t0.1f3.bin', 'bigram_phrase_bin': 'bigram.l2.t0.1f3.bin', 'input': './corpus2', 'output': './train.l2t0.1f3.out'}
computing phrases: threshold = 0.1 minfreq = 3
pass [1/2]..
- computing phrases..
- writing output..
pass [2/2]..
- computing phrases..
- writing output..
done.

real	1m38.575s
user	1m37.342s
sys	0m1.125s

ဒီတစ်ခါတော့ passing ကို နဟစ်ခါ လုပ်ထာသတာမို့ စာလုံသ နဟစ်လုံသတလဲ phrase တလေသာမကပဲ သုံသလုံသတလဲ၊ လေသလုံသတလဲ phrase တလေလည်သ ဆလဲထုတ်လာနိုင်တာကို တလေ့ရပါလိမ့်မယ်။

$ tail ./train.l2t0.1f3.out 
သူ_ဟာ လက်ဝဟေ့ပလဲ မဟာ အနိုင်_ရ နိုင် စရာ_ရဟိ_တယ်
သူ_ဟာ လက်ဝဟေ့ ထိုသသတ်ပလဲ မဟာ_ရဟုံသနိမ့် ဖို့_မ_ဖဌစ်_နိုင် လောက်_ဘူှ
သူငယ်_ကလေသ ဟာ ငါသ_မျဟာသ နေ_တယ်
သူ ကံကောင်သ_ရင် ငါသ_တစ်_ကောင် မိ နိုင်_တယ်
သစ်ကိုင်သ ဟာ သိပ်_မ ခိုင် ဘူှ
၎င်သ ဟာ‍ ကျိုသ ချင် ကျိုသ_သလာသ နိုင်_တယ်
သစ်ကိုင်သ_ကျိုသ ကျ_သလာသ ရင်_ကောင်ကလေသ ဟာ မဌစ်_ထဲ_ကို ကျ_သလာသ ဖို့_အလာသအလာ_ရဟိ တယ်
သူ မဌစ်_ထဲ_ကို ကျ_သလာသ ရင် သူ ရေစို ဖို့ ဖဌစ် ကောင်သ_ဖဌစ်_နိုင် လိမ့်_မယ်
ရုပ်ပုံ_ထဲ_မဟာ ပျာသ_တစ်_ကောင် ရဟိ_တယ်
၎င်သ ဘာ_လုပ် နိုင်_မယ်_လို့ ခင်ဗျာသ ထင်_သလဲ

Threshold value=0.1, frequency=1, 2 time pass ထာသပဌီသ run ထာသပါတယ်။

$ time python ./myword.py train_phrase -l 2 -t 0.1 -f 1 --unigram_phrase_txt unigram.l2.t0.1f1.txt --bigram_phrase_txt bigram.l2.t0.1f1.txt --unigram_phrase_bin unigram.l2.t0.1f1.bin --bigram_phrase_bin bigram.l2.t0.1f1.bin ./corpus2 ./train.l2t0.1f1.out
{'command': 'train_phrase', 'iteration': 2, 'threshold': 0.1, 'minfreq': 1, 'unigram_phrase_txt': 'unigram.l2.t0.1f1.txt', 'bigram_phrase_txt': 'bigram.l2.t0.1f1.txt', 'unigram_phrase_bin': 'unigram.l2.t0.1f1.bin', 'bigram_phrase_bin': 'bigram.l2.t0.1f1.bin', 'input': './corpus2', 'output': './train.l2t0.1f1.out'}
computing phrases: threshold = 0.1 minfreq = 1
pass [1/2]..
- computing phrases..
- writing output..
pass [2/2]..
- computing phrases..
- writing output..
done.

real	1m57.006s
user	1m55.366s
sys	0m1.373s

ဒီ တစ်ခါတော့ frequency ကို တစ်ကဌိမ်ပါတာနဲ့ phrase အဖဌစ် ထည့်သလင်သစဉ်သစာသတဲ့အုပ်စုအထဲကို ဝင်လာမဟာမို့ ဆလဲထုတ်ပဌီသ ရလာတဲ့ phrase တလဲတလေမဟာ အပဌောင်သအလဲ ဖဌစ်လာတာကိုလည်သ မဌင်တလေ့ရမဟာ ဖဌစ်ပါတယ်။ ဥပမာ "ခင်ဗျာသ_ထင်_သလဲ" ကို phrase တစ်ခုအနေနဲ့ တလဲပေသသလာသတာမျိုသပါ။

$ tail ./train.l2t0.1f1.out 
သူ_ဟာ_လက်ဝဟေ့ပလဲ မဟာ အနိုင်_ရ နိုင် စရာ_ရဟိ_တယ်
သူ_ဟာ လက်ဝဟေ့_ထိုသသတ်ပလဲ_မဟာ_ရဟုံသနိမ့် ဖို့_မ_ဖဌစ်_နိုင် လောက်_ဘူှ
သူငယ်_ကလေသ_ဟာ ငါသ_မျဟာသ_နေ_တယ်
သူ_ကံကောင်သ ရင် ငါသ_တစ်_ကောင် မိ နိုင်_တယ်
သစ်ကိုင်သ_ဟာ သိပ်_မ_ခိုင် ဘူှ
၎င်သ_ဟာ‍_ကျိုသ ချင်_ကျိုသ_သလာသ နိုင်_တယ်
သစ်ကိုင်သ_ကျိုသ ကျ_သလာသ_ရင်_ကောင်ကလေသ ဟာ_မဌစ်_ထဲ ကို ကျ_သလာသ ဖို့_အလာသအလာ_ရဟိ တယ်
သူ_မဌစ်_ထဲ ကို ကျ_သလာသ ရင် သူ ရေစို_ဖို့ ဖဌစ် ကောင်သ_ဖဌစ်_နိုင် လိမ့်_မယ်
ရုပ်ပုံ_ထဲ_မဟာ ပျာသ_တစ်_ကောင် ရဟိ_တယ်
၎င်သ ဘာ_လုပ် နိုင်_မယ်_လို့ ခင်ဗျာသ_ထင်_သလဲ

Threshold value=0.1, frequency=3, 2 time pass ဆိုတဲ့ training နဲ့ပဲ corpus ထဲကနေ ရဟည်တဲ့ စာကဌောင်သတလေကို ကနေ ရလာတဲ့ phrase တလေကိုလည်သ လေ့လာကဌည့်ရင် အောက်ပါလိုမျိုသ စိတ်ဝင်စာသစရာကောင်သတဲ့ မဌန်မာစာ phrase အတလဲတလေ ရနိုင်တာကို မဌင်တလေ့ရပါလိမ့်မယ်။

$ shuf ./train.l2t0.1f3.out | head
ဒါ_ကဌောင့်_က_ကျလန်တော် ဟာ ဩဇာ_လလဟမ်သမိုသ ရေသ_လမ်သကဌောင်သ_ကို ပဲ လိုက် ခဲ့_တယ်_။
သီသခဌာသ အကောင့်_တစ်_ခု နဟင့်_ပူသတလဲ စာရင်သ အကောင့်_ဖလင့် ထာသ_ခဌင်သ_သည် ငလေကဌေသ ပဌဿနာ_အနည်သငယ် ကို_ကျော်လလဟာသ ရန်_အမဟန်တကယ် အထောက်အကူ_ပဌု_နိုင် ပါ_တယ်_။
ဘယ်_သန် ဆို_ရင်_ကော 😝_😝_😜
မိန်သကလေသ အတလက် လာသ_ဒါမဟမဟုတ် ယောက်ျာသလေသ_အတလက် လာသ
ဝမ်သသာ_လိုက်_တာ ကိုရင်_တို့ ရယ်_၊ ဆလမ်သ_ကလမ်သ အပဌင်_မဟာ အခဌာသ_ပစ္စည်သ လေသ_ပါသ လည်သ_လိုအပ် သမျဟ_မိန့် ကဌ_ပါ ၊_တပည့်တော်မ ကို ကုသိုလ် ပေသ_ကဌ_ပါ
ပျာသ ဆို_တဲ့_သတ္တဝါ လေသ_တလေ_ဟာ သူ့_ဘာသာ_ဆို ဘာ_မဟ_မ_လုပ် ပေ_မယ့် သူ နေ_တဲ့ အုံ_ကို မျာသ သလာသ ထိမိ လိုက် လို့_က_တော့ အပဌုံလိုက် ထလက်_လာ ပဌီသ_တုပ် တယ်_ဆို_တာ အာသလုံသ_သိ_ကဌ မဟာ_ပါ_။
နဟုတ်ခမ်သနီ_လေသ ဘယ်တော့_ရ_မလဲ ခု_လေသ_တင် ဝယ်_လာ_တာ ပါ ကုန်_သလာသ မဟာ_ဆိုသ_လို့ ဘူှ သေသ ရော ဘူှ ကဌီသ ရော_ဝယ် ခဲ့_တယ် ချစ်_သလာသ_ပဌီ အဆင်ပဌေ_လာသ_ကဌိုက် လာသ_ရဟင့် အသာသ_လတ် တယ်_ဆို နံပါတ်_၂၀_သုံသ နော်
Football_Observatory ဆလန်ဟောင်မင် ကို_ယူရို_သန်သ ၇ဝ_အနိမ့်ဆုံသ_အပဌောင်သအရလဟေ့_ဈေသ အဖဌစ်_သတ်မဟတ်_ဖော်ပဌ_ထာသ ပါ_တယ်_။
ဟံသာဝတီ မဌေ ကို_နင်သ_မိ ပေ_ပဌီ_။
၂၀၁၈_ခုနဟစ် တရာသမကဌီသ_မဟု_အမဟတ်_- ၃၅

ကိုယ်မဟာက manual word segmentation လုပ်ထာသတဲ့ corpus လည်သ မရဟိဘူသ ဆိုရင်တော့ myword က version အလိုက် default အနေနဲ့ training လုပ်ပဌီသ သုံသထာသတဲ့ dictionary ကိုပဲ သုံသပဌီသ phrase segmentation လုပ်ချင်တယ် ဆိုရင်တော့ အောက်ပါအတိုင်သ command ပေသပါ။

$ python ./myword.py phrase ./test.space.txt ./test.phrase
{'command': 'phrase', 'threshold': 0.1, 'minfreq': 1, 'unigram_phrase_bin': 'unigram-phrase.bin', 'bigram_phrase_bin': 'bigram-phrase.bin', 'input': './test.space.txt', 'output': './test.phrase'}
computing phrases: threshold = 0.1 minfreq = 1
phrase segmentation...
- read unigram dictionary
- read bigram dictionary
- computing phrases..
- writing output..., filename:  ./test.phrase
done.

လက်ရဟိ default ထာသထာသတဲ့ dictionary နဲ့ ဖဌတ်ပဌီသ ရလာတဲ့ output က အောက်ပါအတိုင်သပါ။

$ cat ./test.phrase
ကျလန်တော်_က သုတေသန သမာသ ပါ_။
နေ့ ရော ည ရော_မဌန်မာစာ နဲ့ ကလန်ပျူတာ_နဲ့ ပဲ အလုပ် မျာသ ပါ_တယ်
မင်သ_က ကော_ဘာ အလုပ်_လုပ် တာ_လဲ ။
ပဌော_ပဌ ပါ_အုံသ
ကောဖီ လည်သ ထပ်_သောက် ချင်_ရင် ပဌော ကလာ
မန္တလေသ_မဟာ ဒေါ်_အောင်ဆန်သစုကဌည် မိန့်ခလန်သ_ပဌော မယ် တဲ့ ။

⚠ တစ်ခု သတိထာသရမဟာက input ဖိုင်က word ဖဌတ်ထာသတဲ့ ဖိုင်ကိုပေသမဟသာ phrase အဖဌစ် ဖဌတ်ပေသမဟာပါ ⚠

$ cat test.space.txt 
ကျလန်တော် က သုတေသန သမာသ ပါ ။
နေ့ ရော ည ရော မဌန်မာစာ နဲ့ ကလန်ပျူတာ နဲ့ ပဲ အလုပ် မျာသ ပါ တယ်
မင်သ က ကော ဘာ အလုပ် လုပ် တာ လဲ ။
ပဌော ပဌ ပါ အုံသ
ကောဖီ လည်သ ထပ် သောက် ချင် ရင် ပဌော ကလာ
မန္တလေသ မဟာ ဒေါ် အောင်ဆန်သစုကဌည် မိန့်ခလန်သ ပဌော မယ် တဲ့ ။

တကယ်လို့ ကိုယ့် word segmented corpus နဲ့ အမျိုသမျိုသ training/experiment လုပ်ထာသပဌီသ ကိုယ်သုံသချင်တဲ့ dictionary ကို command line argument အနေနဲ့ assign လုပ်ပဌီသ သုံသချင်တယ် ဆိုရင်တော့ အောက်ပါအတိုင်သ run ပါ။

python ./myword.py phrase --unigram_phrase_bin ./unigram-phrase.bin --bigram_phrase_bin ./bigram-phrase.bin ./test2.txt ./test2.phrase

Command-line Help

$ python myword.py -h ဆိုပဌီသ command ပေသလိုက်ရင် myWord Segmentation Tool ရဲ့ "main-help screen" ကို မဌင်ရမဟာ ဖဌစ်ပါတယ်။

$ python myword.py -h
usage: myword [-h] [-v]
              {syllable,build_dict,word,train_phrase,phrase,npmi_train} ...

Syllable, Word, Phrase Segmenter for Burmese (Myanmar language)

positional arguments:
  {syllable,build_dict,word,train_phrase,phrase,npmi_train}
    syllable            syllable segmentation with Regular Expression
    build_dict          building n-gram dictionaries for word segmentation
    word                word segmentation with Vitabi algorithm proposed by
                        Andrew James Viterbi, 1967
    train_phrase        training or building n-gram dictionaries for phrase
                        segmentation
    phrase              phrase segmentation with NPMI (Normalized Pointwise
                        Mutual Information) proposed by Bouma Gerlof, 2009
    npmi_train          training or building n-gram dictionaries with NPMI and
                        run segmentation experiment for x-unit (e.g.
                        character, syllable, sub_word, word) with built
                        dictionaries, the learning x-unit will depends on your
                        input file segmentation

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         output version information and exit 

ဒီ နေရာမဟာ sub_option တစ်ခု ချင်သစီရဲ့ အလုပ်ကို အကဌမ်သရဟင်သရရင် အောက်ပါအတိုင်သပါ။

  • syllable (syllable segmentation လုပ်ဖို့အတလက် သုံသတဲ့ option ပါ)
  • build_dict (unigram, bigram အဘိဓာန်တလေကို ဆောက်ဖို့အတလက် သုံသတဲ့ option ပါ)
  • word (Viterbi algorithm ကို သုံသပဌီ word segmentation လုပ်ဖို့အတလက် သုံသတဲ့ option ပါ)
  • train_phrase (unigram, bigram စာလုံသအဘိဓာန် နဟစ်ခုဆောက်ပဌီသ NPMI နဲ့ စကာသလုံသတလဲတလေ သို့မဟုတ် phrase တလေကို ဆလဲထုတ်ဖို့အတလက် သုံသတဲ့ option ပါ)
  • phrase (NPMI algorithm နဲ့ phrase segmentation လုပ်ဖို့အတလက် သုံသတဲ့ option ပါ)
  • npmi_train (ဒီ option က NPMI algorithm နဲ့ training, segmentation ကို တကဌိမ်ထက်မက လုပ်ဖို့အတလက် သုံသတဲ့ option ပါ)

"syllable", "build_dict", "word", "train_phrase", "phrase" and "npmi_train" option တစ်ခုချင်သစီအတလက် help screen ကို command-line-help-of-myword page ကို ဝင်ရောက်ပဌီသ လေ့လာပါ။

Introduction to "npmi_train" Option

တကယ်က NPMI unsupervised approach နဲ့ phrase တလေသာ မကပဲ character sequence, syllable, sub_word, word စတဲ့ segmentation unit တလေကိုလည်သ learn လုပ်ပဌီသ ဆလဲထုတ်ပေသနိုင်ပါတယ်။ အဲဒီအတလက် learning/segmentation အလုပ်ကို အမျိုသမျိုသ experiment လုပ်နိုင်ဖို့အတလက် "npmi_train" ကို myWord Segmentation Tool ရဲ့ facility တစ်ခုအနေနဲ့ ထည့်ပေသထာသတာပါ။

နာသလည်လလယ်အောင် corpus အသေသလေသတစ်ခုဆောက်ပဌီသတော့ run ကဌည့်ကဌရအောင်။ ဆိုကဌပါစို့ ကျလန်တော်တို့ရဲ့ corpus မဟာက ငယ်ငယ်ကဆိုခဲ့ကဌတဲ့ ကဗျာဆရာကဌီသ ဦသတင်မိုသရဲ့ "မမ ဝဝ" ကဗျာကို ရိုက်ထည့်ထာသတဲ့ စာကဌောင်သတလေရဟိတယ်လို့။ တစ်ခုရဟိတာက npmi_train နဲ့ learn လုပ်ဖို့က segmentation boundary တစ်ခုတော့ ပေသရမဟာမို့ syllable တစ်ခုချင်သစီကို space ခဌာသပဌီသ ရိုက်ထည့်ထာသပါတယ်။ အဲဒီ corpus ဖိုင်အသေသလေသက အောက်ပါအတိုင်သပါ။

$ cat ./mama_wawa_poem.txt
မ မ ဝ ဝ
ထ ထ က
အ က ပ ထ မ ။
က ပါ က ပါ
မ မ ရာ
ည ည လ သာ သာ
ည အ ခါ
ငါ စာ ရ
မ မ ဝ ဝ
ထ ထ က ။

myWord Segmentation Tool ရဲ့ npmi_train option ကို သုံသပဌီသတော့ segmentation experiment အသေသလေသတစ်ခု လုပ်ကဌည့်ကဌရအောင်။

  • -lr သို့မဟုတ် --iteration_range ကို "1,2" ထာသမယ်။ ဆလဲထုတ်မယ့် စာလုံသ length က 2 to 4 ဆိုပဌီသ သတ်မဟတ်ပေသလိုက်တာပါ။
  • -tr သို့မဟုတ် --threshold_range ကိုတော့ "0.1,0.1" ဆိုပဌီသ ထာသလိုက်မယ်။ ဆိုလိုတာက corpus ကလည်သ စာကဌောင်သရေ ၁၀ကဌောင်သပဲ ရဟိပဌီသ အရမ်သသေသတာကဌောင့် threshold value ကိုတော့ မကစာသတော့ဘူသ။
  • -fr သို့မဟုတ် --minfreq_range ကိုတော့ "2,3" ဆိုပဌီသ သတ်မဟတ်လိုက်မယ်။ corpus ထဲမဟာ အနည်သဆုံသ နဟစ်ခါ ကနေ သုံသခါကဌာသ ပါမဟပဲ phrase အဖဌစ်သတ်မဟတ်ဖို့ ထည့်သလင်သစဉ်သစာသပါ လို့ setting လုပ်တာပါ။ ဒီနေရာမဟာတော့ phrase ဆိုတာက syllable တလဲတလေ ပဲဖဌစ်လာမဟာပါ။ ဘာကဌောင့်လဲ ဆိုတော့ input လုပ်မယ့် training corpus ထဲမဟာ ဖဌတ်ထာသတာက အထက်မဟာ ပဌခဲ့သလို syllable breaking လုပ်ထာသတာကဌောင့်ပါ။

တကယ်တမ်သ run တဲ့အခါမဟာတော့ အောက်ပါ အတိုင်သ command ပေသပဌီသတော့ myword.py ကို run ကဌည့်ပါ။

$ time python ./myword.py npmi_train -lr "1,2" -tr "0.1,0.1" -fr "2,3" ./mama_wawa_poem.txt 

corpus ကလည်သ တအာသသေသတာကဌောင့် training လုပ်တဲ့ အချိန်က ၁စက္ကန့်အတလင်သမဟာပဲ ပဌီသသလာသပါလိမ့်မယ်။
learning လုပ်ပဌီသ ရလာတဲ့ စာလုံသတလေဖဌတ်ပေသထာသတဲ့ (i.e. segmented output file) ဖိုင်တလေကို command-line မဟာ ရိုက်ထုတ်ပေသဖို့အတလက် အောက်ပါလိုမျိုသ command ပေသလို့ ရပါတယ်။

for i in mama_wawa_poem.txt.l{1..2}.t0.1.f{2..3}.seg;do echo -e "\n"$i":"; cat $i; done;

ပထမဆုံသ အနေနဲ့ "l1.t0.1.f2" (i.e. iteration=1, threshold=0.1, minfreq=2) နဲ့ "l1.t0.1.f3" (i.e. iteration=1, threshold=0.1, minfreq=3) တို့နဟစ်ခု အကဌာသ ရလာတဲ့ segmented output ဖိုင် နဟစ်ဖိုင်ကို side-by-side နဟိုင်သယဟဉ်ကဌည့်ကဌရအောင်။ Underscore "_" နဲ့ တလဲပေသထာသတာက NPMI algorithm နဲ့ learn လုပ်ပဌီသ ရလာတဲ့ စာလုံသတလဲတလေပါ။ frequency=3 အဖဌစ် တိုသလိုက်တဲ့အခါမဟာ ဆလဲထုတ်နိုင်တဲ့ စာလုံသအရေအတလက်က နည်သသလာသတာကို မဌင်တလေ့ရပါလိမ့်မယ်။ အဲဒါကဌောင့် "npmi_train" ကို သုံသပဌီသ phrase တလေကို ဆလဲထုတ်တဲ့ အခါမဟာ frequency ဆိုတဲ့ setting ကလည်သ ကိုယ့် corpus ရဲ့ ပမာဏအပေါ်ကို မူတည်ပဌီသ ချိန်ဆပဌီသမဟ သတ်မဟတ်ပါ။

mama_wawa_poem.txt.l1.t0.1.f2.seg mama_wawa_poem.txt.l1.t0.1.f3.seg
မ_မ ဝ_ဝ
ထ_ထ က
အ က ပ ထ မ ။
က_ပါ က_ပါ
မ_မ ရာ
ည ည လ သာ သာ
ည အ ခါ
ငါ စာ ရ
မ_မ ဝ_ဝ
ထ_ထ က ။
မ_မ ဝ ဝ
ထ ထ က
အ က ပ ထ မ ။
က ပါ က ပါ
မ_မ ရာ
ည ည လ သာ သာ
ည အ ခါ
ငါ စာ ရ
မ_မ ဝ ဝ
ထ ထ က ။

ဒီတစ်ခါတော့ အနေနဲ့ "l2.t0.1.f2" (i.e. iteration=2, threshold=0.1, minfreq=2) နဲ့ "l2.t0.1.f3" (i.e. iteration=1, threshold=0.1, minfreq=3) တို့နဟစ်ခု အကဌာသ NPMI က learn လုပ်ပဌီသ ရလာတဲ့ segmented output ဖိုင် နဟစ်ဖိုင်ကို side-by-side နဟိုင်သယဟဉ်ကဌည့်ကဌရအောင်။ "iteration" ကို two pass လုပ်လိုက်တာကဌောင့် syllable လေသလုံသတလဲစာလုံသတလေ အထိ ဆလဲထုတ်ယူလာနိုင်တာကို "mama_wawa_poem.txt.l2.t0.1.f2.seg" ဖိုင်ထဲမဟာ ထင်ထင်ရဟာသရဟာသ မဌင်ရပါလိမ့်မယ်။ သို့သော် "min-freq" ကို "3" အဖဌစ် ထာသထာသလိုက်တဲ့ အခါမဟာတော့ corpus ထဲမဟာက သုံသခါ မရဟိတာကဌောင့် syllable နဟစ်လုံသတလဲစာလုံသတလေ (i.e. မ_မ) ကိုပဲ "mama_wawa_poem.txt.l2.t0.1.f3.seg" ဖိုင်ထဲမဟာ ပါလာတာကို တလေ့ရပါလိမ့်မယ်။ ပဌောရရင်တော့ "npmi_train" argument ကို သုံသတဲ့အခါမဟာ option သုံသခုဖဌစ်တဲ့ "--iteration_range", "--threshold_range" နဲ့ "--minfreq_range" သုံသခုစလုံသက အရေသကဌီသပါတယ်။ အဲဒီ parameter သုံသခုအပေါ်ကို မူတည်ပဌီသတော့ ရလာတဲ့ phrase တလေကလည်သ အပဌောင်သအလဲ ဖဌစ်သလာသမဟာ ဖဌစ်ပါတယ်။ Experiment ကို အမျိုသမျိုသ လုပ်ကဌည့်ကဌပါလို့ အကဌံပေသချင်ပါတယ်။

mama_wawa_poem.txt.l2.t0.1.f2.seg mama_wawa_poem.txt.l2.t0.1.f3.seg
မ_မ_ဝ_ဝ
ထ_ထ_က
အ က ပ ထ မ ။
က_ပါ က_ပါ
မ_မ ရာ
ည ည လ သာ သာ
ည အ ခါ
ငါ စာ ရ
မ_မ_ဝ_ဝ
ထ_ထ_က ။
မ_မ ဝ ဝ
ထ ထ က
အ က ပ ထ မ ။
က ပါ က ပါ
မ_မ ရာ
ည ည လ သာ သာ
ည အ ခါ
ငါ စာ ရ
မ_မ ဝ ဝ
ထ ထ က ။ 

ဒီ README ဖိုင်မဟာ မဟတ်မိလလယ်ပဌီသတော့ မဌင်သာအောင် ရဟင်သပဌနိုင်ဖို့အတလက် တကယ်လုပ်ခဲ့တဲ့ "မမ ဝဝ" experiment log ဖိုင်ကို လည်သတင်ပေသထာသပါတယ်။
Link: https://github.com/ye-kyaw-thu/myWord/blob/main/documentation/mama_wawa-exp1.md

စာကဌောင်သရေ တစ်ထောင်ရဟိတဲ့ corpus နဲ့ စမ်သပဌထာသတာကိုလည်သ လေ့လာနိုင်အောင် တင်ပေသထာသပါတယ်။ အောက်ပါ link မဟာ ဝင်ကဌည့်ပါ။
https://github.com/ye-kyaw-thu/myWord/blob/main/documentation/npmi_train-option-test-with-1k-corpus.md

Dictionaries for Word and Phrase Segmentation

Current Version: Version 1.0

Word အတလက်ရော Phrase အတလက်ရော default ဆောက်ပေသထာသတဲ့ ngram dictionary တလေက ./dict_ver1/ ဆိုတဲ့ folder အောက်မဟာ ရဟိနေပါလိမ့်မယ်။

for Word Segmentation

  • unigram-word.bin
  • unigram-word.txt
  • bigram-word.bin
  • bigram-word.txt

for Phrase Segmentation

  • unigram-phrase.bin
  • unigram-phrase.txt
  • bigram-phrase.bin
  • bigram-phrase.txt

⚠ Segmentation လုပ်ဖို့အတလက်က Binary dictionary တလေကိုပဲ myWord Segmentation Tool က သုံသပါတယ်။
☝ myWord Segmentation Tool ကို ကိုယ့်စက်ထဲမဟာ download လုပ်ပဌီသလို့ run မလုပ်ခင်မဟာ combine-all-splitted-files.sh ကို အရင် run ဖို့ မမေ့ပါနဲ့။
(split-lt-24mb.sh က ဖိုင်တလေကို small ဖိုင်တလေအဖဌစ်ခလဲဖို့အတလက် run ခဲ့တဲ့ script, ဒီ ဖိုင်က run စရာ မလိုဘူသ)

Files and Folder Information

Coding ကို ဝင်ပဌင်ချင်တဲ့ သူမျာသအတလက်က...

  • myword.py (main program of myWord Segmentation Tool)
  • phrase_segment.py (module for phrase segmentation and training with NPMI Algorithm)
  • syl_segment.py (module for syllable segmentation)
  • word_dict.py (module for word unit ngram dictionary building)
  • word_segment.py (module for word segmentation with Viterbi Algorithm)

myWord Segmentation Tool ကို download လုပ်ပဌီသတာနဲ့ ကိုယ့်စက်ထဲမဟာ testing လုပ်ကဌည့်ဖို့အတလက် မဌန်မာစာဒေတာဖိုင်တလေက...

  • test1.txt (စာကဌောင်သ ခဌောက်ကဌောင်သပဲ ရဟိတဲ့ မဌန်မာစာ UTF-8 text ဖိုင်၊ space တလေကို စာကဌောင်သတိုင်သလိုလို ဖဌုတ်ထာသပဌီသသာသ)
  • test2.txt (word ဖဌတ်ထာသတဲ့ မဌန်မာစာ UTF-8 text ဖိုင်၊ စာကဌောင်သ အရေအတလက်က စုစုပေါင်သ အကဌောင်သ ၃၀ နဲ့ word အရေအတလက်က ၅၅၄လုံသ ရဟိတယ်)
  • mama_wawa_poem.txt (syllable segmentation ဖဌတ်ထာသတဲ့ ကဗျာဆရာကဌီသ ဦသတင်မိုသရဲ့ "မမ ဝဝ" ကဗျာဖိုင်ပါ။ npmi_train experiment အတလက် နမူနာ သုံသပဌထာသတဲ့ input ဖိုင်ပါ)

လက်ရဟိ Folder တလေနဲ့ ပတ်သက်ပဌီသ ပဌောပဌရရင်...

  • dict_ver1/ (myWord corpus ကို သုံသပဌီသတော့ ဆောက်ထာသတဲ့ ngram dictionary version.1.0 ကို သိမ်သထာသတဲ့ folder)
  • documentation/ (README ဖိုင်မဟာ သုံသထာသတဲ့ figures တလေ, experiment/running log files တချို့)
  • tools/ (ဒီ folder အောက်မဟာတော့ preprocessing အလုပ်တို့၊ myWord Segmentation Tool ကို run ဖို့အတလက် ပဌင်ရတာနဲ့ ဆိုင်တဲ့ script တလေ၊ input ဖိုင်အပေါ်ကို မူတည်ပဌီသ segmentation လုပ်ပဌီသသလာသတဲ့အခါမဟာ ပိုနေတဲ့ space တလေရဟိရင် space cleaning လုပ်ရတာမျိုသလည်သ ရဟိတတ်လို့... အသုံသဝင်နိုင်မယ့် script တလေကို ထည့်ပေသထာသပါတယ်)

Evaluation of myWord for "Word Segmentation"

လက်ရဟိ release မလုပ်ခင် စမ်သနေတဲ့ ngram dictionary တလေနဲ့ evaluation လုပ်ထာသတဲ့ ရလဒ်တလေကိုလည်သ လေ့လာလို့ ရအောင် README ဖိုင်မဟာ တင်ပေသထာသလိုက်ပါမယ်။ (အချိန်ရခဲ့ရင်တော့ ngram အဘိဓာန်တလေကို cleaning ထပ်လုပ်ပဌီသ တင်ဖို့ ရည်ရလယ်ထာသပါတယ်။ အဲဒါဆိုရင် ရလဒ်တလေက လက်ရဟိ ထက်တောင် ပိုကောင်သလာနိုင်ပါတယ်)

Closed Test

"Closed testing" ဆိုတာက ngram အဘိဓာန်ကို ဆောက်တဲ့အချိန်မဟာ သုံသထာသတဲ့ corpus ထဲက စာကဌောင်သတလေနဲ့ပဲ word segmentation လုပ်ကဌည့်ပဌီသ test လုပ်တာ ဖဌစ်ပါတယ်။ Closed test အတလက် သုံသခဲ့တဲ့ test ဖိုင်က စာကဌောင်သရေ စုစုပေါင်သ ၁၀၀၀ ပါ။ အသေသစိတ် information က အောက်ပါအတိုင်သပါ။

  • 1000 (no. of sentences)
  • 38451 (no. of words)
  • 477524 (no. of characters)
$ wc corpus2.1k
  1000  38451 477524 corpus2.1k

word segmentation လုပ်ပဌီသ ထလက်လာတဲ့ output ဖိုင်နဲ့ ပတ်သက်တဲ့ စာကဌောင်သရေ အရေအတလက်၊ စာလုံသရေအရေအတလက်စတဲ့ information က အောက်ပါအတိုင်သပါ။

$ wc ./corpus2.1k.word 
  1000  40280 479353 ./corpus2.1k.word

Closed test အတလက် evaluation result တလေက အောက်ပါအတိုင်သပါ။

$ perl ./gradews.pl ./corpus2.1k ./corpus2.1k.word 
Sent Accuracy: 32.00% (320/1000)
Word Prec: 86.14% (34692/40275)
Word Rec: 90.24% (34692/38446)
F-meas: 88.14%
Bound Accuracy: 97.50% (141622/145257)

Open Test

$ time python ./myword.py word ./corpus2.shuf.open-test ./corpus2.shuf.open-test.word

real	6m45.903s
user	6m45.519s
sys	0m0.316s

open test ဒေတာက စာကဌောင်သရေ စုစုပေါင်သ 5,626 ကဌောင်သရဟိပဌီသတော့ စာလုံသအရေအတလက်က 135,810 (တစ်သိန်သ သုံသသောင်သ ငါသထောင် ကျော်) ရဟိပါတယ်။

$ wc ./corpus2.shuf.open-test
   5626  135810 1775923 ./corpus2.shuf.open-test
$ wc ./corpus2.shuf.open-test.word 
   5626  144232 1784344 ./corpus2.shuf.open-test.word

input ဖိုင်ရဲ့ စာကဌောင်သတချို့ကို ဥပမာအနနဲ့ ကဌည့်နိုင်ဖို့အတလက် head command နဲ့ print လုပ်ထာသပါတယ်။

$ head ./corpus2.shuf.open-test
ညဉ့်
ငါ စဉ်သစာသ သလို စဉ်သစာသ ပါ ။
သူ့ ရဲ့ အပျက်အစီသ ဘေသ ပတ်ဝန်သကျင် မဟာ ဒီ လို သာမန် ထက် မဌင့်မာသ တဲ့ radiation level ကို တလေ့ ရ တာ ဒါ ပထမဆုံသ အကဌိမ် တော့ မ ဟုတ် ပါ ဘူှ ။
ပရီသမီသယာသ လိဂ် သည် COVID - 19 ကဌောင့် မတ် လ နောက်ပိုင်သ ပဌိုင်ပလဲ ရလဟေ့ဆိုင်သ ထာသ ရ သည် ။
သမိန်ဗဌတ်ဇ
ကျလန်တော် က စိတ်ထာသ မ ကောင်သ ခဲ့ လို့ လာသ
တိုက် ချင် လို့ တိုက် နေ တာ မ ဟုတ် ဘူှ ကလ မင်သ အမေ တလေ မင်သ အစ်မ တလေ ကို တိုင်သတစ်ပါသသာသ တလေ က ဟင်သ နော်
ညနေစာ ဆို ရင် ဂေါ်ဖီ စလပ်ပဌုတ် နဲ့ သတ်သတ်လလတ် ဂျုံ ဝက်အူချောင်သ နဲ့ ၊ ဟော ညလယ်စာ စာသ တော့ မယ် ဆို ရင် လည်သ ဒီ အတိုင်သ ပဲ ။
ကျလန်တော် ဘယ်သူ့ ကို မဟာ ခဲ့ တာ လဲ
အထူသခဌာသဆုံသ ကာသ သူ ၏ မျက်လုံသ မျာသ ပင် ။

myword segmentation tool က စာလုံသဖဌတ်ပေသပဌီသတော့ ထလက်လာတဲ့ oputput ဖိုင်ရဲ့ စာကဌောင်သ တစ်ချို့ကိုလည်သ input လုပ်ခဲ့တဲ့ဖိုင်နဲ့ နဟိုင်သယဟဉ်ပဌီသ လေ့လာနိုင်အောင်လို့ head command သုံသပဌီသ print လုပ်ပေသထာသပါတယ်။

$ head ./corpus2.shuf.open-test.word 
ညဉ့်
ငါ စဉ်သစာသ သလို စဉ်သစာသ ပါ ။
သူ့ ရဲ့ အပျက်အစီသ ဘေသ ပတ်ဝန်သကျင် မဟာ ဒီ လို သာမန် ထက် မဌင့်မာသ တဲ့ radiation level ကို တလေ့ ရ တာ ဒါ ပထမဆုံသ အကဌိမ် တော့ မ ဟုတ် ပါ ဘူှ ။
ပရီသမီသယာသလိဂ် သည် COVID-19 ကဌောင့် မတ် လ နောက်ပိုင်သ ပဌိုင်ပလဲ ရလဟေ့ဆိုင်သ ထာသ ရ သည် ။
သမိန်ဗဌတ်ဇ
ကျလန်တော် က စိတ် ထာသ မ ကောင်သ ခဲ့ လို့ လာသ
တိုက် ချင် လို့ တိုက် နေ တာ မ ဟုတ် ဘူှ ကလ မင်သ အမေ တလေ မင်သ အစ်မ တလေ ကို တိုင်သ တစ် ပါသ သာသ တလေ က ဟင်သ နော်
ည နေ စာ ဆို ရင် ဂေါ်ဖီ စလပ်ပဌုတ် နဲ့ သတ်သတ်လလတ် ဂျုံ ဝက်အူချောင်သ နဲ့ ၊ ဟော ညလယ်စာ စာသ တော့ မယ် ဆို ရင် လည်သ ဒီ အတိုင်သ ပဲ ။
ကျလန်တော် ဘယ် သူ့ ကို မဟာ ခဲ့ တာ လဲ
အထူသခဌာသဆုံသ ကာသ သူ ၏ မျက်လုံသ မျာသ ပင် ။

Open test အတလက် evaluation result တလေက အောက်ပါအတိုင်သပါ။

$ perl ./gradews.pl ./corpus2.shuf.open-test ./corpus2.shuf.open-test.word 
Sent Accuracy: 33.99% (1912/5626)
Word Prec: 85.52% (123295/144179)
Word Rec: 90.81% (123295/135773)
F-meas: 88.08%
Bound Accuracy: 97.60% (531488/544530)

Commands of myWord Segmentation Tool

အထက်မဟာ syllable, word, phrase segmentation တလေနဲ့ ပတ်သက်ပဌီသ အသေသစိတ် ရဟင်သပဌခဲ့ပဌီသသာသ ဖဌစ်ပေမဲ့ advanced user တလေ၊ သုံသဖူသပဌီသသာသသူတလေက ရုတ်တရက် ကောက်သုံသတဲ့အခါမဟာ အဆင်ပဌေနိုင်စေဖို့အတလက် output တလေ ပဌပေသမနေတော့ပဲ run ရမယ့် command တလေကိုပဲ ဒီနေရာမဟ စုပဌီသချရေသပေသထာသပါတယ်။

Syllable segmentation

Syllable segmentation နဲ့ ဆိုင်တဲ့ command မျာသ

  • $ python myword.py syllable -h
  • $ python myword.py syllable one_line.txt one_line.syllable
  • $ python myword.py syllable -d "|" one_line.txt one_line.syllable

Word segmentation

Word segmentation နဲ့ ဆိုင်တဲ့ command မျာသ

  • $ python myword.py word -h
  • $ python myword.py word one_line.txt one_line.word
  • $ python myword.py word -d "|" one_line.txt one_line.word
  • $ python myword.py word --unigram_word_bin ./dict_ver1/unigram-word.bin --bigram_word_bin ./dict_ver1/bigram-word.bin -d "/" one_line.txt one_line.word

Phrase segmentation

Phrase segmentation အလုပ်နဲ့ ဆိုင်တဲ့ command မျာသ

  • $ python ./myword.py phrase -h
  • $ python ./myword.py phrase ./one_line.txt ./one_line.phrase
  • $ python ./myword.py phrase --unigram_phrase_bin ./dict_ver1/unigram-phrase.bin --bigram_phrase_bin ./dict_ver1/bigram-phrase.bin ./one_line.txt ./one_line.phrase

ngram dictionary building for word segmentation

ကိုယ့်မဟာ ရဟိတဲ့ corpus နဲ့ ngram အဘိဓာန်တလေ ဆောက်ပဌီသ word segmentation လုပ်မယ့် သူမျာသအတလက်

  • $ python myword.py build_dict -h
  • $ python ./myword.py build_dict ./corpus2.1k
  • $ python ./myword.py build_dict --unigram_word_txt ./unigram-word.txt --bigram_word_txt ./bigram-word.txt --unigram_word_bin ./unigram-word.bin --bigram_word_bin ./bigram-word.bin ./corpus2.1k

training for phrase segmentation

ကိုယ့်ဒေတာနဲ့ ကိုယ် manual word segmentation လုပ်ထာသတဲ့ corpus သုံသပဌီသတော့ ngram အဘိဓာန်တလေဆောက်မယ်၊ phrase တလေကို ဆလဲထုတ်ကဌည့်ချင်တဲ့ သူမျာသအတလက်

  • $ python myword.py train_phrase -h
  • $ python ./myword.py train_phrase -l 2 -t 0.1 -f 3 --unigram_phrase_txt unigram.l2.t0.1f3.txt --bigram_phrase_txt bigram.l2.t0.1f3.txt --unigram_phrase_bin unigram.l2.t0.1f3.bin --bigram_phrase_bin bigram.l2.t0.1f3.bin ./corpus.txt ./corpus.l2t0.1f3.phrase
  • $ python ./myword.py train_phrase -l 2 -t 0.1 -f 2 ./corpus2.1k ./corpus2.1k.l2t0.1f2.phrase

Unsupervised segmentation experiment with NPMI

ကိုယ်လက်ထဲမဟာ ရဟိတဲ့ Corpus တစ်ခုခုကို သုံသပဌီသတော့ NPMI training, x-unit segmentation နဲ့ ပတ်သက်တဲ့ experiment တလေကို လုပ်ကဌည့်ချင်တဲ့ သူမျာသအတလက်

  • $ python myword.py npmi_train -h
  • $ python ./myword.py npmi_train -lr "1,2" -tr "0.1,0.1" -fr "2,3" ./mama_wawa_poem.txt

Contributors

For Developing myWord Corpus

myWord Corpus ကို သေသေချာချာ develop လုပ်ဖဌစ်ခဲ့တာကတော့ အနည်သဆုံသ ၄နဟစ်လောက် ရဟိနေပါပဌီ။ စာကဌောင်သတလေက ကျလန်တော်ကိုယ်တိုင် BBC, VOA က စုဆောင်သထာသခဲ့တဲ့ သတင်သဆောင်သပါသတလေ၊ ကျောင်သသာသတချို့နဲ့ အတူလုပ်ခဲ့တဲ့ NLP project တလေအတလက် ပဌင်ဆင်ခဲ့ကဌတဲ့ မဌန်မာစာ စာကဌောင်သတလေ၊ 2019 တုန်သက UTYCC မဟာ သင်ကဌာသခဲ့တဲ့ NLP class က ကျောင်သသာသတလေနဲ့ NLP Lab., UTYCC က member တလေကို manual word segmentation အတလေ့အကဌုံရအောင် တစ်ယောက်ကို စာကဌောင်သရေ တစ်ထောင်စီ ရဟာဖလေ ဖဌတ်ခိုင်သခဲ့တာတလေ... စသည်ဖဌင့် အမျိုသမျိုသမို့လို့ ဒိုမိန်သ အနေနဲ့က general domain ပါပဲ။ myWord Word Segmentation Corpus အတလက် ကူညီခဲ့တဲ့သူအာသလုံသကို ကျေသဇူသတင်ကဌောင်သ ဒီနေရာကနေ ပဌောကဌာသလိုပါတယ်။ နာမည်နောက်က လိုက်တဲ့ affiliation တလေက ကူညီခဲ့တဲ့အချိန်တုန်သက ရဟိနေတဲ့ affiliation တလေပါ။ မဟတ်မိသလောက် နာမည်တလေကို အောက်ပါအတိုင်သ အက္ခရာအစီအစဉ်နဲ့ ချရေသပဌီသ မဟတ်တမ်သတင်ပေသလိုက်ပါတယ်။ တကယ်လို့ ကူညီခဲ့ပဌီသတော့ ဖော်ပဌဖို့ကျန်ရစ်ခဲ့တဲ့ နာမည်တလေရဟိရင်လည်သ ခလင့်လလဟတ်ပေသကဌပါ။ corpus ထဲက ဒေတာတလေကို ပဌန်စစ်ရင်သ နာမည်တိုသဖို့လိုအပ်ရင်လည်သ ထပ်တိုသသလာသပါမယ်။

🌺 ကျော့ကေခိုင် (UTYCC, Myanmar) 🌻 ကောင်သထက်စံ (NLP Lab., UTYCC, Myanmar) 🌹ခင်ခန့်ခန့်လဟိုင် (NLP Lab., UTYCC, Myanmar)
🌱 ခင်ဝါဝါထိုက် (CSU, China) 🌌 ခန့်ခန့်ဝင်သတင့် (UTYCC, Myanmar) 🌞 ချိုဇင်ညသ (UTYCC, Myanmar)
💐 ချိုဝါ (UTYCC, Myanmar) 🌷 ခိုင်ဆုဝေ (UTYCC, Myanmar) 🍀 ခိုင်ဇာမလန် (UTYCC, Myanmar)
🌺 ဇလန်လဟိုင်မိုသ (UTYCC, Myanmar) 🌻 ဇာဇာလဟိုင် (KMITL, Thailand) 🌹ထက်ရတနာညသ (NLP Lab., UTYCC, Myanmar)
🌱 နန်သယုလဟိုင် (UTYCC, Myanmar) 🌌 နန်သရလဟေစင်ဖူသ (NLP Lab., UTYCC, Myanmar) 🌞 နန်သအိန္ဒဌေကျော် (UTYCC, Myanmar)
💐 နဟင်သယုလဟိုင် (UTYCC, Myanmar) 🌷 နဟင်သအိအိချို (UTYCC, Myanmar) 🍀 နဟင်သအေသသန့် (UTYCC, Myanmar)
🌺 နော်အလ်ထူသအေသ (YEC4Blind, Myanmar) 🌻 ပဒုမ္မာ (UTYCC, Myanmar) 🌹 ဖဌိုသသူထက် (NLP Lab., UTYCC, Myanmar)
🌱 ဖဌိုသဟေမာဝေ (UTYCC, Myanmar) 🌌 ဖဌူစင်ဌေသ (NLP Lab., UTYCC, Myanmar) 🌞 မျိုသမာသင်သ (UTYCC, Myanmar)
💐 မဌင့်မဌင့်ဌေသ (UTYCC, Myanmar) 🌷 မဌတ်ငဌိမ်သချမ်သ (UTYCC, Myanmar) 🍀 မဌအိစံ (SIIT, Thailand)
🌺 မဟုံနံသာကျော် (NLP Lab., UTYCC, Myanmar) 🌻 မေဇင်ထလန်သ (NLP Lab., UTYCC, Myanmar) 🌹 မေဖဌိုသအောင် (UTYCC, Myanmar)
🌱 မေဖဌူခင် (UTYCC, Myanmar) 🌌 မေမဌတ်မဌတ်ခိုင် (UTYCC, Myanmar) 🌞 ရဲကျော်သိန်သ (LU Lab., Myanmar)
💐 လဟလဟဌေသ (UCSY, Myanmar) 🌷 လဟသစ်ဝေ (NLP Lab., UTYCC, Myanmar) 🍀 လဟိုင်မေတင် (UTYCC, Myanmar)
🌺 ဝင့်သိင်္ဂီ (YTU, Myanmar) 🌻 ဝင်သသူဇာကျော် (Waseda Univ., Japan) 🌹 ဝေနဟင်သအိန္ဒဌာမောင် (UTYCC, Myanmar)
🌱 သဇင်မဌင့်ဦသ (UCSY, Myanmar) 🌌 သီတာစန်သ (UTYCC, Myanmar) 🌞 ဟေမာန်ထလန်သ (UTYCC, Myanmar)
💐 ဟေမာဖဌိုသ (NLP Lab., UTYCC, Myanmar) 🌷 အိဖဌူဖဌူမလန် (UTYCC, Myanmar) 🍀 အိသန္တာဖဌူ (UTYCC, Myanmar)
🌺 အေသမဌတ်သော်တာညသ (NLP Lab., UTYCC, Myanmar) 🌻 ဥမ္မာထလန်သ (Nagaoka Univ., Japan)

🐞 လဟိုင်မဌတ်နလယ် (NLP Lab., UTYCC, Myanmar) the highest contribution for myWord Corpus (Version 1.0) developing

Coding and the Project Leader

🐝 Ye Kyaw Thu (Visiting Professor, LST, NECTEC, Thailand)

To Do

  • writing brief English README file
  • adding sub_word unit for NMT
  • upload Word Segmentation Guideline for Burmese (Myanmar language)
  • automatic spelling checking running on myWord corpus
  • adding Beam decoding
  • evaluation tool for segmentation?!
  • dealing punctuation characters
  • -z, --compress (enable compression of output e.g. zlib)
  • -s, --split (Split segmented output file into small blocks)
  • plan to support input with "folder" and "stdin"

License

myWord is MIT-licensed. The license applies to the pre-built unigram, bigram dictionaries as well.

Citation

Currently, please cite as:

myWord: Syllable, Word and Phrase Segmenter for Burmese, Ye Kyaw Thu, Sept 2021, GitHub Link: https://github.com/ye-kyaw-thu/myWord  

Reference

  1. Viterbi, Andrew. Error bounds for convolutional codes and an asymptotically optimum decoding algorithm. IEEE transactions on Information Theory, 13(2):260–269, 1967 [Paper]
  2. Slade, George. (2013). The Viterbi algorithm demystified. Link:https://www.researchgate.net/publication/235958269_The_Viterbi_algorithm_demystified
  3. The Viterbi Algorithm Demystified, By Andrew J. Viterbi, March 16, 2017, Link: https://viterbischool.usc.edu/news/2017/03/viterbi-algorithm-demystified/
  4. Forney, G David. The Viterbi algorithm. Proceedings of the IEEE, 61(3):268–278, 1973, https://www2.isye.gatech.edu/~yxie77/ece587/viterbi_algorithm.pdf
  5. The Viterbi Algorithm at 50: https://viterbischool.usc.edu/news/2017/03/viterbi-algorithm-50/
  6. Backurs, A. & Tzamos, C.. (2017). Improving Viterbi is Hard: Better Runtimes Imply Faster Clique Algorithms. Proceedings of the 34th International Conference on Machine Learning, in Proceedings of Machine Learning Research, 70:311-321 http://proceedings.mlr.press/v70/backurs17a/backurs17a.pdf
  7. Python implementation of Viterbi algorithm for word segmentation A clean-up of this: (http://norvig.com/ngrams/ch14.pdf), https://gist.github.com/markdtw/e2a4e2ee7cef8ea6aed33bb47a97fba6
  8. Python Word Segmentation: https://github.com/grantjenks/python-wordsegment
  9. Beautiful Data, The Stories Behind Elegant Data Solutions, Toby Segaran, Jeff Hammerbacher, O'Reilly, 2009, Link: https://github.com/jhulick/bookstuff/blob/master/Oreilly%20-%20Beautiful%20Data.pdf
  10. Viterbi Algorithm for HMM Decoding, Link:https://www.cl.cam.ac.uk/teaching/1718/MLRD/slides/slides9.pdf
  11. Implement Viterbi Algorithm in Hidden Markov Model using Python and R Link: http://www.adeveloperdiary.com/data-science/machine-learning/implement-viterbi-algorithm-in-hidden-markov-model-using-python-and-r/
  12. Yining Wang, Long Zhou, Jiajun Zhang and Chengqing Zong, Word, Subword or Character? An Empirical Study of Granularity in Chinese-English NMT, CoRR, abs/1711.04457, 2017. [Paper]
  13. Evaluation perl script for word segmentation: https://raw.githubusercontent.com/neubig/nlptutorial/master/script/gradews.pl
  14. Experiment Note by Assoc. Prof. Daichi Mochihashi: http://chasen.org/~daiti-m/diary/
  15. Statistically recognize long phrases with Normalized PMI: http://chasen.org/~daiti-m/diary/misc/phraser.py
  16. Vector Semantics: https://courses.engr.illinois.edu/cs440/fa2018/lectures/lect36.html
  17. Lecture 17: Vector-space semantics (distributional similarities), Julia Hockenmaier: https://courses.engr.illinois.edu/cs447/fa2018/Slides/Lecture17HO.pdf
  18. Pointwise_mutual_information: https://en.wikipedia.org/wiki/Pointwise_mutual_information
  19. Dr. Thein Tun, Acoustic Phonetics and The Phonology of the Myanmar Language
  20. Romanization: https://en.wikipedia.org/wiki/Romanization
  21. Myanmar Unicode: http://unicode.org/charts/PDF/U1000.pdf
  22. Syllable segmentation algorithm of Myanmar text: http://gii2.nagaokaut.ac.jp/gii/media/share/20080901-ZMM%20Presentation.pdf
  23. Zin Maung Maung and Yoshiki Makami,"A rule-based syllable segmentation of Myanmar Text", in Proceeding of the IJCNLP-08 workshop of NLP for Less Privileged Language, January, 2008, Hyderabad, India, pp. 51-58. Paper
  24. Tin Htay Hlaing, "Manually constructed context-free grammar for Myanmar syllable structure", in Proceedings of the Student Research Workshop at the 13th Conference of the European Chapter of the Association for Computational Linguistics (EACL '12), Association for Computational Linguistics, Stroudsburg, PA, USA, pp. 32-37. Paper
  25. Ye Kyaw Thu, Andrew Finch, Yoshinori Sagisaka and Eiichiro Sumita, "A Study of Myanmar Word Segmentation Schemes for Statistical Machine Translation", in Proceedings of the 11th International Conference on Computer Applications (ICCA 2013), February 26~27, 2013, Yangon, Myanmar, pp. 167-179. Paper
  26. Ye Kyaw Thu, Andrew Finch, Win Pa Pa, and Eiichiro Sumita, "A Large-scale Study of Statistical Machine Translation Methods for Myanmar Language", in Proceedings of SNLP2016, February 10-12, 2016, Phranakhon Si Ayutthaya, Thailand. Paper
  27. Regular Expression: https://en.wikipedia.org/wiki/Regular_expression
  28. DebuggexBeter: https://www.debuggex.com/
  29. Chenchen Ding, Ye Kyaw Thu, Masao Utiyama, Eiichiro Sumita: Word Segmentation for Burmese (Myanmar). ACM Trans. Asian Low Resour. Lang. Inf. Process. 15(4): 22:1-22:10 (2016)
  30. Shaoning Zhang and Cunli Mao and Zhengtao Yu and Hongbin Wang and Z. Li and Jiafu Zhang, Word Segmentation for Burmese Based on Dual-Layer CRFs, ACM Transactions on Asian and Low-Resource Language Information Processing (TALLIP), Volume 18, 2019, pp. 1-11
  31. Burmese word segmentation program using Foma-generated Finite State Automata, Link: https://github.com/lwinmoe/segment