diff --git a/docs/source/creating_and_sharing.mdx b/docs/source/creating_and_sharing.mdx index f09a3417..745bf656 100644 --- a/docs/source/creating_and_sharing.mdx +++ b/docs/source/creating_and_sharing.mdx @@ -58,8 +58,12 @@ Or if you need to download the NLTK `"punkt_tab"` resources: ```py def _download_and_prepare(self, dl_manager): + import io + from contextlib import redirect_stdout import nltk - nltk.download("punkt_tab") + + with redirect_stdout(io.StringIO()): + nltk.download("punkt_tab", quiet=True) ``` Next, we need to define how the computation of the evaluation module works. diff --git a/measurements/word_length/word_length.py b/measurements/word_length/word_length.py index 46a84087..68b011e2 100644 --- a/measurements/word_length/word_length.py +++ b/measurements/word_length/word_length.py @@ -82,12 +82,19 @@ def _info(self): ) def _download_and_prepare(self, dl_manager): + import io + from contextlib import redirect_stdout + import nltk + def _silent_download(pkg: str) -> None: + with redirect_stdout(io.StringIO()): + nltk.download(pkg, quiet=True) + if NLTK_VERSION >= version.Version("3.9.0"): - nltk.download("punkt_tab") + _silent_download("punkt_tab") else: - nltk.download("punkt") + _silent_download("punkt") def _compute(self, data, tokenizer=word_tokenize): """Returns the average word length of the input data""" diff --git a/metrics/meteor/meteor.py b/metrics/meteor/meteor.py index bc023a8e..d85a4e75 100644 --- a/metrics/meteor/meteor.py +++ b/metrics/meteor/meteor.py @@ -117,15 +117,22 @@ def _info(self): ) def _download_and_prepare(self, dl_manager): + import io + from contextlib import redirect_stdout + import nltk - nltk.download("wordnet") + def _silent_download(pkg: str) -> None: + with redirect_stdout(io.StringIO()): + nltk.download(pkg, quiet=True) + + _silent_download("wordnet") if NLTK_VERSION >= version.Version("3.9.0"): - nltk.download("punkt_tab") + _silent_download("punkt_tab") elif NLTK_VERSION >= version.Version("3.6.5"): - nltk.download("punkt") + _silent_download("punkt") if NLTK_VERSION >= version.Version("3.6.6"): - nltk.download("omw-1.4") + _silent_download("omw-1.4") def _compute(self, predictions, references, alpha=0.9, beta=3, gamma=0.5): multiple_refs = isinstance(references[0], list)