Kosuke-Yamada
commited on
Commit
•
88e430c
1
Parent(s):
95ed196
modify file
Browse files- livedoor-news-corpus.py +36 -6
livedoor-news-corpus.py
CHANGED
@@ -13,6 +13,7 @@ from datasets import (
|
|
13 |
Value,
|
14 |
Version,
|
15 |
)
|
|
|
16 |
|
17 |
_CITATION = ""
|
18 |
_DESCRIPTION = "This is a dataset of livedoor news articles."
|
@@ -21,9 +22,37 @@ _LICENSE = "This work is license under CC BY-ND 2.1 JP"
|
|
21 |
_URL = "https://www.rondhuit.com/download/ldcc-20140209.tar.gz"
|
22 |
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
|
|
|
|
25 |
BUILDER_CONFIGS = [
|
26 |
-
|
27 |
name="livedoor-news-corpus",
|
28 |
version=Version("1.1.0"),
|
29 |
description=_DESCRIPTION,
|
@@ -53,7 +82,7 @@ class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
|
53 |
dataset_dir = Path(dl_manager.download_and_extract(_URL))
|
54 |
|
55 |
data = []
|
56 |
-
for file_name in dataset_dir.glob("*/*/*"):
|
57 |
if "LICENSE.txt" in str(file_name):
|
58 |
continue
|
59 |
with open(file_name, "r") as f:
|
@@ -68,12 +97,13 @@ class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
|
68 |
}
|
69 |
)
|
70 |
|
71 |
-
|
72 |
-
|
|
|
73 |
|
74 |
num_data = len(data)
|
75 |
-
num_train_data = int(num_data *
|
76 |
-
num_validation_data = (num_data
|
77 |
train_data = data[:num_train_data]
|
78 |
validation_data = data[
|
79 |
num_train_data : num_train_data + num_validation_data
|
|
|
13 |
Value,
|
14 |
Version,
|
15 |
)
|
16 |
+
from datasets.data_files import DataFilesDict
|
17 |
|
18 |
_CITATION = ""
|
19 |
_DESCRIPTION = "This is a dataset of livedoor news articles."
|
|
|
22 |
_URL = "https://www.rondhuit.com/download/ldcc-20140209.tar.gz"
|
23 |
|
24 |
|
25 |
+
class LivedoorNewsCorpusConfig(BuilderConfig):
|
26 |
+
def __init__(
|
27 |
+
self,
|
28 |
+
name: str = "default",
|
29 |
+
version: Version | str | None = Version("0.0.0"),
|
30 |
+
data_dir: str | None = None,
|
31 |
+
data_files: DataFilesDict | None = None,
|
32 |
+
description: str | None = None,
|
33 |
+
shuffle: bool = True,
|
34 |
+
seed: int = 42,
|
35 |
+
train_ratio: float = 0.8,
|
36 |
+
validation_ratio: float = 0.1,
|
37 |
+
) -> None:
|
38 |
+
super().__init__(
|
39 |
+
name=name,
|
40 |
+
version=version,
|
41 |
+
data_dir=data_dir,
|
42 |
+
data_files=data_files,
|
43 |
+
description=description,
|
44 |
+
)
|
45 |
+
self.shuffle = shuffle
|
46 |
+
self.seed = seed
|
47 |
+
self.train_ratio = train_ratio
|
48 |
+
self.validation_ratio = validation_ratio
|
49 |
+
|
50 |
+
|
51 |
class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
52 |
+
BUILDER_CONFIG_CLASS = LivedoorNewsCorpusConfig
|
53 |
+
|
54 |
BUILDER_CONFIGS = [
|
55 |
+
LivedoorNewsCorpusConfig(
|
56 |
name="livedoor-news-corpus",
|
57 |
version=Version("1.1.0"),
|
58 |
description=_DESCRIPTION,
|
|
|
82 |
dataset_dir = Path(dl_manager.download_and_extract(_URL))
|
83 |
|
84 |
data = []
|
85 |
+
for file_name in sorted(dataset_dir.glob("*/*/*")):
|
86 |
if "LICENSE.txt" in str(file_name):
|
87 |
continue
|
88 |
with open(file_name, "r") as f:
|
|
|
97 |
}
|
98 |
)
|
99 |
|
100 |
+
if self.config.shuffle == True:
|
101 |
+
random.seed(self.config.seed)
|
102 |
+
random.shuffle(data)
|
103 |
|
104 |
num_data = len(data)
|
105 |
+
num_train_data = int(num_data * self.config.train_ratio)
|
106 |
+
num_validation_data = int(num_data * self.config.validation_ratio)
|
107 |
train_data = data[:num_train_data]
|
108 |
validation_data = data[
|
109 |
num_train_data : num_train_data + num_validation_data
|