NLTK, Random Sentence Generators?

Oleg Alexander olegalexander at gmail.com
Thu Apr 12 12:57:42 EDT 2007


On Apr 12, 4:36 am, Passer By <sen... at sender.send> wrote:
> James Stroud <jstr... at mbi.ucla.edu> writes:
> > Passer By wrote:
> > > James Stroud <jstr... at mbi.ucla.edu> writes:
>
> > >>Passer By wrote:
>
> > >>>Has any created or not of examples of random sentence generators
> > >>>using n-gram models (or other models might be interesting).  I
> > >>>know of one example from a course at MIT, but besides that
> > >>>nothing.  Any help would be great.
>
> > >>Best is to just cull text from your spam folder as these are often
> > >>generated by similar means--but somehow I think you knew that.
>
> > > Emotive on Usenet? Thats original.
>
> > Anonimity on usenet? That's suspiscious.
>
> Paranoid Plunk?- Hide quoted text -
>
> - Show quoted text -

Another way to generate random text is by using context free grammars
and recursive substitution. Here are some examples of programs which
use this technique:

http://nonsense.sourceforge.net/
http://www.elsewhere.org/pomo

The programs generate from a user-defined "grammar" file, which looks
something like this:

ROOT
$sentence

SENTENCE
I $feelabout my $animal!

FEELABOUT
love
hate

ANIMAL
dog
cat

The above grammar will generate the following possible sentences:

I love my cat!
I hate my cat!
I love my dog!
I hate my dog!

Unlike a Markov generator, the output of these programs is
grammatically correct.




More information about the Python-list mailing list