Kosuke-Yamada
commited on
Commit
•
7fe34c2
1
Parent(s):
9869317
modify how to import
Browse files- livedoor-news-corpus.py +26 -35
livedoor-news-corpus.py
CHANGED
@@ -4,10 +4,7 @@ import random
|
|
4 |
from pathlib import Path
|
5 |
from typing import Generator
|
6 |
|
7 |
-
|
8 |
-
GeneratorBasedBuilder, Split, SplitGenerator, Value,
|
9 |
-
Version)
|
10 |
-
from datasets.data_files import DataFilesDict
|
11 |
|
12 |
_CITATION = ""
|
13 |
_DESCRIPTION = "This is a dataset of livedoor news articles."
|
@@ -16,14 +13,14 @@ _LICENSE = "This work is license under CC BY-ND 2.1 JP"
|
|
16 |
_URL = "https://www.rondhuit.com/download/ldcc-20140209.tar.gz"
|
17 |
|
18 |
|
19 |
-
class LivedoorNewsCorpusConfig(BuilderConfig):
|
20 |
def __init__(
|
21 |
self,
|
22 |
name: str = "default",
|
23 |
-
version: Version | str | None = Version("0.0.0"),
|
24 |
data_dir: str | None = None,
|
25 |
-
data_files: DataFilesDict | None = None,
|
26 |
-
description: str | None =
|
27 |
shuffle: bool = True,
|
28 |
seed: int = 42,
|
29 |
train_ratio: float = 0.8,
|
@@ -42,37 +39,29 @@ class LivedoorNewsCorpusConfig(BuilderConfig):
|
|
42 |
self.validation_ratio = validation_ratio
|
43 |
|
44 |
|
45 |
-
class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
46 |
BUILDER_CONFIG_CLASS = LivedoorNewsCorpusConfig
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
name="livedoor-news-corpus",
|
51 |
-
version=Version("1.1.0"),
|
52 |
-
description=_DESCRIPTION,
|
53 |
-
),
|
54 |
-
]
|
55 |
-
|
56 |
-
def _info(self) -> DatasetInfo:
|
57 |
-
return DatasetInfo(
|
58 |
description=_DESCRIPTION,
|
59 |
citation=_CITATION,
|
60 |
homepage=_HOMEPAGE,
|
61 |
license=_LICENSE,
|
62 |
-
features=Features(
|
63 |
{
|
64 |
-
"url": Value("string"),
|
65 |
-
"date": Value("string"),
|
66 |
-
"title": Value("string"),
|
67 |
-
"content": Value("string"),
|
68 |
-
"category": Value("string"),
|
69 |
}
|
70 |
),
|
71 |
)
|
72 |
|
73 |
def _split_generators(
|
74 |
-
self, dl_manager: DownloadManager
|
75 |
-
) -> list[SplitGenerator]:
|
76 |
dataset_dir = Path(dl_manager.download_and_extract(_URL))
|
77 |
|
78 |
data = []
|
@@ -91,7 +80,7 @@ class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
|
91 |
}
|
92 |
)
|
93 |
|
94 |
-
if self.config.shuffle
|
95 |
random.seed(self.config.seed)
|
96 |
random.shuffle(data)
|
97 |
|
@@ -99,16 +88,18 @@ class LivedoorNewsCorpus(GeneratorBasedBuilder):
|
|
99 |
num_train_data = int(num_data * self.config.train_ratio)
|
100 |
num_validation_data = int(num_data * self.config.validation_ratio)
|
101 |
train_data = data[:num_train_data]
|
102 |
-
validation_data = data[
|
103 |
-
num_train_data : num_train_data + num_validation_data
|
104 |
-
]
|
105 |
test_data = data[num_train_data + num_validation_data :]
|
106 |
return [
|
107 |
-
SplitGenerator(
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
110 |
),
|
111 |
-
SplitGenerator(name=Split.TEST, gen_kwargs={"data": test_data}),
|
112 |
]
|
113 |
|
114 |
def _generate_examples(self, data: list[dict[str, str]]) -> Generator:
|
|
|
4 |
from pathlib import Path
|
5 |
from typing import Generator
|
6 |
|
7 |
+
import datasets
|
|
|
|
|
|
|
8 |
|
9 |
_CITATION = ""
|
10 |
_DESCRIPTION = "This is a dataset of livedoor news articles."
|
|
|
13 |
_URL = "https://www.rondhuit.com/download/ldcc-20140209.tar.gz"
|
14 |
|
15 |
|
16 |
+
class LivedoorNewsCorpusConfig(datasets.BuilderConfig):
|
17 |
def __init__(
|
18 |
self,
|
19 |
name: str = "default",
|
20 |
+
version: datasets.Version | str | None = datasets.Version("0.0.0"),
|
21 |
data_dir: str | None = None,
|
22 |
+
data_files: datasets.data_files.DataFilesDict | None = None,
|
23 |
+
description: str | None = _DESCRIPTION,
|
24 |
shuffle: bool = True,
|
25 |
seed: int = 42,
|
26 |
train_ratio: float = 0.8,
|
|
|
39 |
self.validation_ratio = validation_ratio
|
40 |
|
41 |
|
42 |
+
class LivedoorNewsCorpus(datasets.GeneratorBasedBuilder):
|
43 |
BUILDER_CONFIG_CLASS = LivedoorNewsCorpusConfig
|
44 |
|
45 |
+
def _info(self) -> datasets.DatasetInfo:
|
46 |
+
return datasets.DatasetInfo(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
description=_DESCRIPTION,
|
48 |
citation=_CITATION,
|
49 |
homepage=_HOMEPAGE,
|
50 |
license=_LICENSE,
|
51 |
+
features=datasets.Features(
|
52 |
{
|
53 |
+
"url": datasets.Value("string"),
|
54 |
+
"date": datasets.Value("string"),
|
55 |
+
"title": datasets.Value("string"),
|
56 |
+
"content": datasets.Value("string"),
|
57 |
+
"category": datasets.Value("string"),
|
58 |
}
|
59 |
),
|
60 |
)
|
61 |
|
62 |
def _split_generators(
|
63 |
+
self, dl_manager: datasets.DownloadManager
|
64 |
+
) -> list[datasets.SplitGenerator]:
|
65 |
dataset_dir = Path(dl_manager.download_and_extract(_URL))
|
66 |
|
67 |
data = []
|
|
|
80 |
}
|
81 |
)
|
82 |
|
83 |
+
if self.config.shuffle:
|
84 |
random.seed(self.config.seed)
|
85 |
random.shuffle(data)
|
86 |
|
|
|
88 |
num_train_data = int(num_data * self.config.train_ratio)
|
89 |
num_validation_data = int(num_data * self.config.validation_ratio)
|
90 |
train_data = data[:num_train_data]
|
91 |
+
validation_data = data[num_train_data : num_train_data + num_validation_data]
|
|
|
|
|
92 |
test_data = data[num_train_data + num_validation_data :]
|
93 |
return [
|
94 |
+
datasets.SplitGenerator(
|
95 |
+
name=datasets.Split.TRAIN, gen_kwargs={"data": train_data}
|
96 |
+
),
|
97 |
+
datasets.SplitGenerator(
|
98 |
+
name=datasets.Split.VALIDATION, gen_kwargs={"data": validation_data}
|
99 |
+
),
|
100 |
+
datasets.SplitGenerator(
|
101 |
+
name=datasets.Split.TEST, gen_kwargs={"data": test_data}
|
102 |
),
|
|
|
103 |
]
|
104 |
|
105 |
def _generate_examples(self, data: list[dict[str, str]]) -> Generator:
|