ngram language model
1.0.0
라플라스 스무딩 및 문장 생성을 갖춘 N- 그램 언어 모델의 파이썬 구현.
일부 nltk 함수 ( nltk.ngrams , nltk.FreqDist )가 사용되지만 대부분의 모든 것은 수작업으로 구현됩니다.
참고 : LanguageModel 클래스는 이미 문장에 의해 토큰 화 된 데이터가 제공 될 것으로 예상합니다. 포함 된 load_data 함수를 사용하는 경우 train.txt 및 test.txt 파일을 이미 처리해야합니다.
예제는 data/ 디렉토리를 참조하십시오.
data/train.txt 에서 교육을받은 Trigram 모델의 예제 및 data/test.txt 에 대해 테스트 :
Loading 3-gram model...
Vocabulary size: 23505
Generating sentences...
...
<s> <s> the company said it has agreed to sell its shares in a statement </s> (0.03163)
<s> <s> he said the company also announced measures to boost its domestic economy and could be a long term debt </s> (0.01418)
<s> <s> this is a major trade bill that would be the first quarter of 1987 </s> (0.02182)
...
Model perplexity: 51.555
생성 된 문장 옆에있는 괄호 안의 숫자는 발생하는 문장의 누적 확률입니다.
사용 정보 :
usage: N-gram Language Model [-h] --data DATA --n N [--laplace LAPLACE] [--num NUM]
optional arguments:
-h, --help show this help message and exit
--data DATA Location of the data directory containing train.txt and test.txt
--n N Order of N-gram model to create (i.e. 1 for unigram, 2 for bigram, etc.)
--laplace LAPLACE Lambda parameter for Laplace smoothing (default is 0.01 -- use 1 for add-1 smoothing)
--num NUM Number of sentences to generate (default 10)
Josh Loehr와 Robin Cosbey가 원래 저술 한 후 약간 수정했습니다. 2018 년 2 월 8 일 마지막 편집.