-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpolicy_ie_a.py
42 lines (30 loc) · 1.23 KB
/
policy_ie_a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from typing import Dict, cast
import datasets
def file_mapping(directory: str, filename: str) -> Dict[str, str]:
# define patterns for file loading
files = {}
files["train"] = os.path.join(directory, "train", filename)
files["validation"] = os.path.join(directory, "valid", filename)
files["test"] = os.path.join(directory, "test", filename)
return files
def load_policy_ie_a(directory: str) -> datasets.DatasetDict:
# initialize DatasetDict object
combined = datasets.DatasetDict()
# load tokens which are common for all sub-tasks
tokens = datasets.load_dataset("text", data_files=file_mapping(directory, "seq.in"))
# since this is task A, only load labels
labels = datasets.load_dataset(
"text", data_files=file_mapping(directory, "label")
).rename_column("text", "label")
# mypy-related specification to sub-type
tokens = cast(datasets.DatasetDict, tokens)
labels = cast(datasets.DatasetDict, labels)
# zip together data
for split in ["train", "validation", "test"]:
combined[split] = datasets.concatenate_datasets(
[tokens[split], labels[split]], axis=1
)
return combined