add tests for JGLUE.py
Browse files- tests/JGLUE_test.py +50 -0
- tests/__init__.py +0 -0
tests/JGLUE_test.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets as ds
|
2 |
+
import pytest
|
3 |
+
|
4 |
+
|
5 |
+
@pytest.fixture
|
6 |
+
def dataset_path() -> str:
|
7 |
+
return "JGLUE.py"
|
8 |
+
|
9 |
+
|
10 |
+
@pytest.mark.parametrize(
|
11 |
+
argnames="dataset_name, expected_num_train, expected_num_valid,",
|
12 |
+
argvalues=(
|
13 |
+
("JSTS", 12451, 1457),
|
14 |
+
("JNLI", 20073, 2434),
|
15 |
+
("JCommonsenseQA", 8939, 1119),
|
16 |
+
),
|
17 |
+
)
|
18 |
+
def test_load_dataset(
|
19 |
+
dataset_path: str,
|
20 |
+
dataset_name: str,
|
21 |
+
expected_num_train: int,
|
22 |
+
expected_num_valid: int,
|
23 |
+
):
|
24 |
+
dataset = ds.load_dataset(path=dataset_path, name=dataset_name)
|
25 |
+
|
26 |
+
assert dataset["train"].num_rows == expected_num_train
|
27 |
+
assert dataset["validation"].num_rows == expected_num_valid
|
28 |
+
|
29 |
+
|
30 |
+
def test_load_jsquad(
|
31 |
+
dataset_path: str,
|
32 |
+
dataset_name: str = "JSQuAD",
|
33 |
+
expected_num_train: int = 62859,
|
34 |
+
expected_num_valid: int = 4442,
|
35 |
+
):
|
36 |
+
dataset = ds.load_dataset(path=dataset_path, name=dataset_name)
|
37 |
+
|
38 |
+
def count_num_data(split: str) -> int:
|
39 |
+
data = dataset[split]["data"]
|
40 |
+
assert len(data) == 1
|
41 |
+
data = data[0]
|
42 |
+
|
43 |
+
num_data = 0
|
44 |
+
for paragraphs in data["paragraphs"]:
|
45 |
+
for qas in paragraphs["qas"]:
|
46 |
+
num_data += len(qas["answers"])
|
47 |
+
return num_data
|
48 |
+
|
49 |
+
assert count_num_data("train") == expected_num_train
|
50 |
+
assert count_num_data("validation") == expected_num_valid
|
tests/__init__.py
ADDED
File without changes
|