私の質問を文脈に入れて、いくつかの(神経)言語モデルを訓練し、テスト/比較したいと思います。データ準備ではなくモデルに焦点を当てるために、私はnltkのBrownコーパスを使用し、nltkで提供されたNgramsモデルをベースラインとして訓練することを選択しました。NLTKのNgramモデルとperplexity
私の最初の質問は、疑いのあるnltkのNgramモデルの動作に関するものです。 コードは、私がそれをここに貼り付け短めですので:NGRAMモデリングが非常にある4.6のパープレキシティで
... build
... train
len(corpus) = 1161192, len(vocabulary) = 13817, len(train) = 1103132, len(test) = 58060
perplexity(test) = 4.60298447026
それはそう:
import nltk
print "... build"
brown = nltk.corpus.brown
corpus = [word.lower() for word in brown.words()]
# Train on 95% f the corpus and test on the rest
spl = 95*len(corpus)/100
train = corpus[:spl]
test = corpus[spl:]
# Remove rare words from the corpus
fdist = nltk.FreqDist(w for w in train)
vocabulary = set(map(lambda x: x[0], filter(lambda x: x[1] >= 5, fdist.iteritems())))
train = map(lambda x: x if x in vocabulary else "*unknown*", train)
test = map(lambda x: x if x in vocabulary else "*unknown*", test)
print "... train"
from nltk.model import NgramModel
from nltk.probability import LidstoneProbDist
estimator = lambda fdist, bins: LidstoneProbDist(fdist, 0.2)
lm = NgramModel(5, train, estimator=estimator)
print "len(corpus) = %s, len(vocabulary) = %s, len(train) = %s, len(test) = %s" % (len(corpus), len(vocabulary), len(train), len(test))
print "perplexity(test) =", lm.perplexity(test)
私は非常に疑わしい見つけることは、私は次のような結果を得ることですが、そのコーパスで良い。私の解釈が正しければ、モデルは平均して約5回の試行で正しい単語を推測することができるはずです(13817の可能性がありますが...)。あなたはこの混乱の価値についてあなたの経験を共有することができたら(私は本当にそれを信じていません)?私はネット上のnltkのngramモデルについて何の苦情も見つけませんでした(しかし、おそらく私は間違っています)。 Ngramモデルとコンピューティングの混乱のためのNLTKの良い選択肢を知っていますか?
ありがとうございます!
NLTKでのngramの実装は間違っているようです。 SRILM(http://www.speech.sri.com/projects/srilm/)は〜150の混乱を与えます(はるかに信憑性があります)。それでも、NLTKの人気を考えると、私は誰もこれを以前に経験していないことに驚いています... – zermelozf