gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
14.08k stars 4.44k forks source link

How to disable nltk_data command line output? #1618

Open Ligh7bringer opened 5 years ago

Ligh7bringer commented 5 years ago

Hi. I'm developing a chatbot with this library. I was wondering if there's any way to suppress the output to the command line related to nltk_data every time I run my program. I am talking about this:

[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data]     /home/sgeor/nltk_data...
[nltk_data]   Package averaged_perceptron_tagger is already up-to-
[nltk_data]       date!
[nltk_data] Downloading package punkt to /home/sgeor/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to /home/sgeor/nltk_data...
[nltk_data]   Package stopwords is already up-to-date!

I am using flask for the frontend of my app and every time the server is restarted (or I run any of the flask do_something commands I have implemented) this appears in the console.

Thanks.

pylobot commented 5 years ago

Maybe something in NLTK docs?

Ligh7bringer commented 5 years ago

I did find something. Apparently

import nltk
nltk.download('wordnet', quiet=True)

disables it but I don't know where nltk.download() is used in chatterbot. Furthermore, even if I did find out, that would mean I would have to modify the library files and it will only work for me. I can't really come up with a solution. Thanks for the suggestion though.

gunthercox commented 5 years ago

In an upcoming release, I'd be happy to add an option that makes it possible to disable this output.

Dulce06 commented 5 years ago

I did find something. Apparently

import nltk
nltk.download('wordnet', quiet=True)

disables it but I don't know where nltk.download() is used in chatterbot. Furthermore, even if I did find out, that would mean I would have to modify the library files and it will only work for me. I can't really come up with a solution. Thanks for the suggestion though.

Hi @gunthercox @Ligh7bringer

I have tried adding these two lines in the python file (code for chatbot) but did not work for me. May I know to which file this needs to be added.

Many thanks

Dulce06 commented 5 years ago

I have seen all these lines in downloader.py which resides inside nltk folder. Below is an example.

class UpToDateMessage(DownloaderMessage): """The package download file is already up-to-date""" def init(self, package): self.package = package

I did not understand what """The package download file is already up-to-date""" is doing.

Is it something like a print statement? I have removed this sort of lines but did not work. It still prints this in command line output.

geekyAbhijeetSr commented 5 years ago

https://www.youtube.com/watch?v=POKSIoePv3Q&t=15s I hope this will help you guys... and sorry for bad video quality

corberan commented 5 years ago
  1. cd to C:\Users\YOUR_USER_NAME\AppData\Roaming\nltk_data or venv/nltk_data or where nltk_data is downloaded..
  2. copy nltk_data/corpora/stopwords to nltk_data/stopwords
  3. copy nltk_data/taggers/averaged_perceptron_tagger to nltk_data/averaged_perceptron_tagger

Before: image

After: image

In version 1.0.5, chatterbot/utils.py has four download_nltk_xxx functions:

def download_nltk_stopwords():
    """
    Download required NLTK stopwords corpus if it has not already been downloaded.
    """
    nltk_download_corpus('stopwords') # should be 'corpora/stopwords'

def download_nltk_wordnet():
    """
    Download required NLTK corpora if they have not already been downloaded.
    """
    nltk_download_corpus('corpora/wordnet')

def download_nltk_averaged_perceptron_tagger():
    """
    Download the NLTK averaged perceptron tagger that is required for this algorithm
    to run only if the corpora has not already been downloaded.
    """
    nltk_download_corpus('averaged_perceptron_tagger') # should be 'taggers/averaged_perceptron_tagger'

def download_nltk_vader_lexicon():
    """
    Download the NLTK vader lexicon for sentiment analysis
    that is required for this algorithm to run.
    """
    nltk_download_corpus('vader_lexicon')

They all call the function nltk_download_corpus, whose parameter resource_path represents the path to check if the data exists.

AnupriyaPurwar29 commented 3 years ago

[nltk_data] Downloading package averaged_perceptron_tagger to [nltk_data] C:\Users\smart\AppData\Roaming\nltk_data... [nltk_data] Package averaged_perceptron_tagger is already up-to- [nltk_data] date! [nltk_data] Downloading package punkt to [nltk_data] C:\Users\smart\AppData\Roaming\nltk_data... [nltk_data] Package punkt is already up-to-date!

How to remove it from pycharm????

RathiAaditya commented 2 years ago

https://www.youtube.com/watch?v=POKSIoePv3Q&t=15s I hope this will help you guys... and sorry for bad video quality

Please add this video again I am also facing this issue. It would be really great help dude.

RathiAaditya commented 2 years ago

[nltk_data] Downloading package averaged_perceptron_tagger to [nltk_data] C:\Users\smart\AppData\Roaming\nltk_data... [nltk_data] Package averaged_perceptron_tagger is already up-to- [nltk_data] date! [nltk_data] Downloading package punkt to [nltk_data] C:\Users\smart\AppData\Roaming\nltk_data... [nltk_data] Package punkt is already up-to-date!

How to remove it from pycharm????

Did you get the solution for this? I am also facing the same issue. Can someone please help !!

Shivam623 commented 2 years ago

didn't find solution by far... using ntlk.download('wordnet', quite=True) does stop for the first time but if you are running while True it will show up again.. so doesn't solve it. :|

seriously needed this.