Update ccnews_split.py
Browse files- ccnews_split.py +34 -14
ccnews_split.py
CHANGED
@@ -93,6 +93,10 @@ class CCNews(datasets.GeneratorBasedBuilder):
|
|
93 |
CCNewsConfig(
|
94 |
name="plain_text",
|
95 |
description="Plain text",
|
|
|
|
|
|
|
|
|
96 |
)
|
97 |
]
|
98 |
|
@@ -121,26 +125,42 @@ class CCNews(datasets.GeneratorBasedBuilder):
|
|
121 |
train_filter = lambda x : (x%10) < 8
|
122 |
val_filter = lambda x: (x%10) == 8
|
123 |
test_filter = lambda x: (x%10) == 9
|
|
|
|
|
124 |
|
125 |
return [
|
126 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": custom_iter_archive(archive, train_filter)}),
|
127 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"files": custom_iter_archive(archive, val_filter)}),
|
128 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"files": custom_iter_archive(archive, test_filter)}),
|
129 |
]
|
130 |
|
131 |
-
def _generate_examples(self, files):
|
132 |
id_ = 0
|
133 |
for article_file_path, f in files:
|
134 |
if fnmatch(os.path.basename(article_file_path), "*.json"):
|
135 |
article = json.load(f)
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
|
|
93 |
CCNewsConfig(
|
94 |
name="plain_text",
|
95 |
description="Plain text",
|
96 |
+
),
|
97 |
+
CCNewsConfig(
|
98 |
+
name="plain_text_sentences",
|
99 |
+
description="Plain text (sentence level)",
|
100 |
)
|
101 |
]
|
102 |
|
|
|
125 |
train_filter = lambda x : (x%10) < 8
|
126 |
val_filter = lambda x: (x%10) == 8
|
127 |
test_filter = lambda x: (x%10) == 9
|
128 |
+
|
129 |
+
level = "doc" if self.config.name == "plain_text" else "sentence"
|
130 |
|
131 |
return [
|
132 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": custom_iter_archive(archive, train_filter), "level": level}),
|
133 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"files": custom_iter_archive(archive, val_filter), "level": level}),
|
134 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"files": custom_iter_archive(archive, test_filter)}, "level": level),
|
135 |
]
|
136 |
|
137 |
+
def _generate_examples(self, files, level):
|
138 |
id_ = 0
|
139 |
for article_file_path, f in files:
|
140 |
if fnmatch(os.path.basename(article_file_path), "*.json"):
|
141 |
article = json.load(f)
|
142 |
+
if level == "sentence":
|
143 |
+
full_article = article["maintext"].strip() if article["maintext"] is not None else ""
|
144 |
+
for sent in full_article.split("\n"):
|
145 |
+
yield id_, {
|
146 |
+
"title": article["title"].strip() if article["title"] is not None else "",
|
147 |
+
"text": sent,
|
148 |
+
"domain": article["source_domain"].strip() if article["source_domain"] is not None else "",
|
149 |
+
"date": article["date_publish"].strip() if article["date_publish"] is not None else "",
|
150 |
+
"description": article["description"].strip() if article["description"] is not None else "",
|
151 |
+
"url": article["url"].strip() if article["url"] is not None else "",
|
152 |
+
"image_url": article["image_url"].strip() if article["image_url"] is not None else "",
|
153 |
+
}
|
154 |
+
id_ += 1
|
155 |
+
else:
|
156 |
+
yield id_, {
|
157 |
+
"title": article["title"].strip() if article["title"] is not None else "",
|
158 |
+
"text": article["maintext"].strip() if article["maintext"] is not None else "",
|
159 |
+
"domain": article["source_domain"].strip() if article["source_domain"] is not None else "",
|
160 |
+
"date": article["date_publish"].strip() if article["date_publish"] is not None else "",
|
161 |
+
"description": article["description"].strip() if article["description"] is not None else "",
|
162 |
+
"url": article["url"].strip() if article["url"] is not None else "",
|
163 |
+
"image_url": article["image_url"].strip() if article["image_url"] is not None else "",
|
164 |
+
}
|
165 |
+
id_ += 1
|
166 |
|