Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/source/creating_and_sharing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions measurements/word_length/word_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
15 changes: 11 additions & 4 deletions metrics/meteor/meteor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down