How to generate sentences in NLTK?

3,614 views
Skip to first unread message

justin.kang

unread,
Apr 22, 2009, 10:41:40 PM4/22/09
to nltk-users
Hi, everybody.

I wonder How the NLTK users usually make 'sentence generation
function'. Of course, I know NLTK doesn't offer some specific
functions for generation, but I think there would be some method to
make sentences by using other NLTK functions.

I'm considering to use 'random sentence generator'. It means if there
are the candidates of 'sub', 'verb', and 'object' stuffs, and they are
already determined, I can peak them up randomly and make sentence.
Perhaps this is the traditionally method to make random sentence.

However, I wonder there are other more intelligent way to generate
sentences.
If somebody have some informations about this, it will be happy if
youguys share with me.

Thanks

Justin.

Shaul Kedem

unread,
Apr 23, 2009, 11:04:33 AM4/23/09
to nltk-...@googlegroups.com
Hi,
did you read the book? nltk does have random sentence generation,

Shaul

Edward Grefenstette

unread,
Apr 23, 2009, 1:46:11 PM4/23/09
to nltk-users
Continuing Shaul's comment with an example. You could do, for
instance:

====
>>> import ntlk
>>> text = nltk.Text(nltk.corpus.brown.words()) # Get text from brown
>>> text.generate()
Building ngram index...
The Fulton County should receive some stimulus from rising if they
could oust Colmer . ( Or , to try them and might , someday , break
away the seeds and are so long as the outstanding standard bearer of
Mr. Barcus' strong beliefs . The Bishop of Sarum's Introduction ,
indicated that stand-ins and picketing would be more vulnerable to Aj
. Mr. Schaefer also recommended by Dineen and Ade ( 1957 ) . In the
apartment . She turned and attacked their own pools , alas , to our
slum problems . The Rockies have many strays coming
=====

Best,
Edward

On Apr 23, 4:04 pm, Shaul Kedem <shaul.ke...@gmail.com> wrote:
> Hi,
>  did you read the book? nltk does have random sentence generation,
>
> Shaul
>

justin.kang

unread,
Apr 23, 2009, 9:24:50 PM4/23/09
to nltk-users
Thanks guys. I totally forgot about that functions.
I'll try to do that

Thanks

Justin.
Reply all
Reply to author
Forward
0 new messages