PythonでのNLTK、特に.generate()メソッドに問題があります。
generate(self、length = 100)
トリグラム言語モデルを使用して生成されたランダムなテキストを印刷します。
パラメーター:
* length (int) - The length of text to generate (default=100)
これが私が試みているものの簡略版です。
import nltk
words = 'The quick brown fox jumps over the lazy dog'
tokens = nltk.word_tokenize(words)
text = nltk.Text(tokens)
print text.generate(3)
これは常に生成されます
Building ngram index...
The quick brown
None
単語からランダムなフレーズを作成するのとは対照的です。
これが私の出力です
print text.generate()
Building ngram index...
The quick brown fox jumps over the lazy dog fox jumps over the lazy
dog dog The quick brown fox jumps over the lazy dog dog brown fox
jumps over the lazy dog over the lazy dog The quick brown fox jumps
over the lazy dog fox jumps over the lazy dog lazy dog The quick brown
fox jumps over the lazy dog the lazy dog The quick brown fox jumps
over the lazy dog jumps over the lazy dog over the lazy dog brown fox
jumps over the lazy dog quick brown fox jumps over the lazy dog The
None
再び同じテキストから始めますが、それからそれを変えます。また、オーウェルの1984年の最初の章を使用してみました。これも、常に最初の3つのトークン(この場合はスペースの1つ)から始まり、ランダムにテキストを生成します。
私はここで何が間違っているのですか?