- Notifications
You must be signed in to change notification settings - Fork1
KentoW/Ngram-language-model
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
N-gram言語モデルをPythonで実装
加算スムージングとKneser-nayスムージングを実装
# Sample code.fromngramimportNgramngram=Ngram(input_file='corpus.txt',N=3,smoothing='kneser-nay')ngram.train()ngram.ppl(input_file=args.corpus)#ATTENTION!! very slowgenerated_list=ngram.generate(window=5,mode='sample',temprature=1.1,max_word=30,delta=0.5)print("生成結果")forwords,log_probingenerated_list:print(log_prob,"".join(words[3::]))
train()
言語モデルの学習ppl()
パープレキシティの計算generate()
文の生成
input_file : 入力データ
N : N-gramのN
smoothing : スムージングの種類(vanilla, add, kneser-nay)
window : ビーム探索の探索窓幅
mode : ビーム探索の方法(greedy, sample)
temprature : ビーム探索の方法がsampleのとき、確率分布から単語をsampleする温度
max_word : 生成する単語数
delta: 加算スムージング及びKneser-nayスムージングのパラメータ
1単語をスペースで分割した1行1文先頭に#(シャープ)記号を入れてコメントアウトを記述可能
# 文1単語1 単語2 単語3 ...# 文2単語10 単語11 単語10 ......
例としてWiki.pyを使用して収集した アニメのあらすじ文章をcorpus.txtに保存
About
Ngram language model in Python. (Nグラム言語モデル)
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published