Update Space (evaluate main: b3f3c02c)
Browse files- requirements.txt +1 -1
- word_length.py +13 -1
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
git+https://github.com/huggingface/evaluate.git@
|
| 2 |
nltk~=3.7
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/evaluate.git@b3f3c02ce2d972bc0e59e346b3318ca2f537e060
|
| 2 |
nltk~=3.7
|
word_length.py
CHANGED
|
@@ -16,10 +16,19 @@ from statistics import mean
|
|
| 16 |
|
| 17 |
import datasets
|
| 18 |
from nltk import word_tokenize
|
|
|
|
| 19 |
|
| 20 |
import evaluate
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
_DESCRIPTION = """
|
| 24 |
Returns the average length (in terms of the number of words) of the input data.
|
| 25 |
"""
|
|
@@ -75,7 +84,10 @@ class WordLength(evaluate.Measurement):
|
|
| 75 |
def _download_and_prepare(self, dl_manager):
|
| 76 |
import nltk
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
def _compute(self, data, tokenizer=word_tokenize):
|
| 81 |
"""Returns the average word length of the input data"""
|
|
|
|
| 16 |
|
| 17 |
import datasets
|
| 18 |
from nltk import word_tokenize
|
| 19 |
+
from packaging import version
|
| 20 |
|
| 21 |
import evaluate
|
| 22 |
|
| 23 |
|
| 24 |
+
if evaluate.config.PY_VERSION < version.parse("3.8"):
|
| 25 |
+
import importlib_metadata
|
| 26 |
+
else:
|
| 27 |
+
import importlib.metadata as importlib_metadata
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
NLTK_VERSION = version.parse(importlib_metadata.version("nltk"))
|
| 31 |
+
|
| 32 |
_DESCRIPTION = """
|
| 33 |
Returns the average length (in terms of the number of words) of the input data.
|
| 34 |
"""
|
|
|
|
| 84 |
def _download_and_prepare(self, dl_manager):
|
| 85 |
import nltk
|
| 86 |
|
| 87 |
+
if NLTK_VERSION >= version.Version("3.9.0"):
|
| 88 |
+
nltk.download("punkt_tab")
|
| 89 |
+
else:
|
| 90 |
+
nltk.download("punkt")
|
| 91 |
|
| 92 |
def _compute(self, data, tokenizer=word_tokenize):
|
| 93 |
"""Returns the average word length of the input data"""
|