nltk: text.generate() does not exist, but is still referenced
I’ve been trying to follow along with the Natural Language Processing book, but right in the first chapter I’m coming across some issues. After import
ing everything from nltk.book
, my first thought was to try text3.generate()
as was demonstrated in one of the examples. Of course, I got a lovely AttributeError
because the Text class apparently doesn’t have that method in the NLTK that I installed.
Furthermore, even running nltk.text.demo()
tries to do generated text - and returns the same error.
Of course, I couldn’t find any documentation for the generate()
method, so I’m assuming it was removed; if that’s the case, you should remove references to it from nltk.text.demo()
and from the textbook.
I’m using Python 2.7.8 with NLTK 3.0.0b1 (which was the version available via Windows installer package from PyPI at the time of this writing). The text3.generate()
example is in both the old and current versions of the textbook.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 3
- Comments: 28 (8 by maintainers)
This is still referred to in Chapter one of the book: http://www.nltk.org/book/ch01.html
It’s no biggy, but I’m probably typical in spending a few minutes googling this as an issue. Those few minutes times however many people are working their way through the book… 😃
Bump, generate() references are still there.
In my opinion, I totally agree with you guys to remove (generate() references).
I see two issues with the current code (besides the fact that it does not work), user-experience-wise:
In the book, the method does not take any parameters (at least when it first appears in the book), but the current signature requires a
words
parameter. So when you follow the book, what you get is the following:This is not very user-friendly. I suggest giving words a default value in the signature (e.g.
words=None
) to avoid this issue.Using the regular Python console following the book instructions I do not see the
DeprecationWarning
that the code logs. This is what I did from the beginning:Since the
generate()
is not simply deprecated as in “it will be removed”, but also as in “it does not work anymore”, I suggest raising aNotImplementedError
instead of logging a warning. Doing so would both make existing code fail (which is what I, as a developer, would like it to do instead of apparently succeeding without actually doing what it used to do) and show up in the console for book readers.If you agree with these changes but do not have the time or motivation to implement them, just let me know and I will send a merge request.
It’s still there now.
Could also build your own generate, if ya want: http://www.cyber-omelette.com/2017/01/markov.html¶
Hi, what are possible current alternatives to auto generate text, in replacement to this function? I am reading the generated text from the Chapter 1 of the book, and I too would like to produce marvelous sentences such as “In the beginning of his brother is a hairy man” or this fundamental question : “so shall thy wages be?”.
The
generate
method should be present as of NLTK 3.4. Check out thenltk.lm
package!I also wonder if we could remove the references to
generate()
from the book. At least in chapter 1, they do not seem to be required by other sections of the chapter.