ktagowski commited on
Commit
c9b575e
1 Parent(s): d567003

Fix loader name

Browse files
Files changed (1) hide show
  1. cst-wikinews.py +85 -0
cst-wikinews.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """CST Wikinews classification dataset."""
2
+
3
+ import csv
4
+ from pathlib import Path
5
+ from typing import List, Tuple, Dict, Generator
6
+
7
+ import datasets
8
+
9
+
10
+ _DESCRIPTION = """CST Wikinews dataset."""
11
+
12
+ _URLS = {
13
+ "train": "https://huggingface.co/datasets/clarin-pl/cst-wikinews/resolve/main/train.csv",
14
+ "test": "https://huggingface.co/datasets/clarin-pl/cst-wikinews/resolve/main/test.csv",
15
+ }
16
+
17
+
18
+ _LABELS = [
19
+ "Brak_relacji",
20
+ "Dalsze_informacje",
21
+ "Krzy偶owanie_si臋",
22
+ "Opis",
23
+ "Parafraza",
24
+ "Spe艂nienie",
25
+ "Streszczenie",
26
+ "To偶samo艣膰",
27
+ "T艂o_historyczne",
28
+ "Uszczeg贸艂owienie",
29
+ "Zawieranie",
30
+ "殴r贸d艂o",
31
+ ]
32
+
33
+
34
+ class CSTWikinews(datasets.GeneratorBasedBuilder):
35
+ """AG News topic classification dataset."""
36
+
37
+ def _info(self) -> datasets.DatasetInfo:
38
+ return datasets.DatasetInfo(
39
+ description=_DESCRIPTION,
40
+ features=datasets.Features(
41
+ {
42
+ "sentence_1": datasets.Value("string"),
43
+ "sentence_2": datasets.Value("string"),
44
+ "label": datasets.features.ClassLabel(
45
+ names=_LABELS, num_classes=len(_LABELS)
46
+ ),
47
+ }
48
+ ),
49
+ )
50
+
51
+ def _split_generators(
52
+ self, dl_manager: datasets.DownloadManager
53
+ ) -> List[datasets.SplitGenerator]:
54
+ urls_to_download = _URLS
55
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
56
+ return [
57
+ datasets.SplitGenerator(
58
+ name=datasets.Split.TRAIN,
59
+ gen_kwargs={"filepath": downloaded_files["train"]},
60
+ ),
61
+ datasets.SplitGenerator(
62
+ name=datasets.Split.TEST,
63
+ gen_kwargs={"filepath": downloaded_files["test"]},
64
+ ),
65
+ ]
66
+
67
+ def _generate_examples(
68
+ self, filepath: str
69
+ ) -> Generator[Tuple[int, Dict[str, str]], None, None]:
70
+ """Generate AG News examples."""
71
+ with Path(filepath, encoding="utf-8").open() as csv_file:
72
+ csv_reader = csv.reader(
73
+ csv_file,
74
+ delimiter=",",
75
+ quoting=csv.QUOTE_ALL,
76
+ skipinitialspace=True,
77
+ )
78
+ next(csv_reader, None) # skip the headers
79
+ for row_id, (s1, s2, label) in enumerate(csv_reader):
80
+ label = int(label)
81
+ yield row_id, {
82
+ "sentence_1": s1,
83
+ "sentence_2": s2,
84
+ "label": label,
85
+ }