Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating random sentences from custom text in Python's NLTK?
    text
    copied!<p>I'm having trouble with the NLTK under Python, specifically the .generate() method.</p> <blockquote> <p>generate(self, length=100)</p> <p>Print random text, generated using a trigram language model.</p> <p>Parameters:</p> <pre><code> * length (int) - The length of text to generate (default=100) </code></pre> </blockquote> <p>Here is a simplified version of what I am attempting.</p> <pre><code>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) </code></pre> <p>This will <em>always</em> generate</p> <pre><code>Building ngram index... The quick brown None </code></pre> <p>As opposed to building a random phrase out of the words.</p> <p>Here is my output when I do</p> <pre><code>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 </code></pre> <p>Again starting out with the same text, but then varying it. I've also tried using the first chapter from Orwell's 1984. Again that <strong>always</strong> starts with the first 3 tokens (one of which is a space in this case) and <em>then</em> goes on to randomly generate text.</p> <p>What am I doing wrong here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload