Datasets:

Languages:
Japanese
License:
Kosuke-Yamada commited on
Commit
6c07a79
1 Parent(s): 75895e7

modify how to import

Browse files
Files changed (1) hide show
  1. ner-wikipedia-dataset.py +25 -45
ner-wikipedia-dataset.py CHANGED
@@ -4,19 +4,7 @@ import json
4
  import random
5
  from typing import Generator
6
 
7
- from datasets import (
8
- BuilderConfig,
9
- DatasetInfo,
10
- DownloadManager,
11
- Features,
12
- GeneratorBasedBuilder,
13
- Sequence,
14
- Split,
15
- SplitGenerator,
16
- Value,
17
- Version,
18
- )
19
- from datasets.data_files import DataFilesDict
20
 
21
  _CITATION = """
22
  @inproceedings{omi-2021-wikipedia,
@@ -33,14 +21,14 @@ _LICENSE = "CC-BY-SA 3.0"
33
  _URL = "https://raw.githubusercontent.com/stockmarkteam/ner-wikipedia-dataset/main/ner.json"
34
 
35
 
36
- class NerWikipediaDatasetConfig(BuilderConfig):
37
  def __init__(
38
  self,
39
  name: str = "default",
40
- version: Version | str | None = Version("0.0.0"),
41
  data_dir: str | None = None,
42
- data_files: DataFilesDict | None = None,
43
- description: str | None = None,
44
  shuffle: bool = True,
45
  seed: int = 42,
46
  train_ratio: float = 0.8,
@@ -59,29 +47,23 @@ class NerWikipediaDatasetConfig(BuilderConfig):
59
  self.validation_ratio = validation_ratio
60
 
61
 
62
- class NerWikipediaDataset(GeneratorBasedBuilder):
63
  BUILDER_CONFIG_CLASS = NerWikipediaDatasetConfig
64
 
65
- BUILDER_CONFIGS = [
66
- NerWikipediaDatasetConfig(
67
- name="ner-wikipedia-dataset",
68
- version=Version("2.0.0"),
69
  description=_DESCRIPTION,
70
- ),
71
- ]
72
-
73
- def _info(self) -> DatasetInfo:
74
- return DatasetInfo(
75
- description=_DESCRIPTION,
76
- features=Features(
77
  {
78
- "curid": Value("string"),
79
- "text": Value("string"),
80
  "entities": [
81
  {
82
- "name": Value("string"),
83
- "span": Sequence(Value("int64"), length=2),
84
- "type": Value("string"),
 
 
85
  }
86
  ],
87
  }
@@ -92,8 +74,8 @@ class NerWikipediaDataset(GeneratorBasedBuilder):
92
  )
93
 
94
  def _split_generators(
95
- self, dl_manager: DownloadManager
96
- ) -> list[SplitGenerator]:
97
  dataset_dir = str(dl_manager.download_and_extract(_URL))
98
  with open(dataset_dir, "r", encoding="utf-8") as f:
99
  data = json.load(f)
@@ -106,21 +88,19 @@ class NerWikipediaDataset(GeneratorBasedBuilder):
106
  num_train_data = int(num_data * self.config.train_ratio)
107
  num_validation_data = int(num_data * self.config.validation_ratio)
108
  train_data = data[:num_train_data]
109
- validation_data = data[
110
- num_train_data : num_train_data + num_validation_data
111
- ]
112
  test_data = data[num_train_data + num_validation_data :]
113
  return [
114
- SplitGenerator(
115
- name=Split.TRAIN,
116
  gen_kwargs={"data": train_data},
117
  ),
118
- SplitGenerator(
119
- name=Split.VALIDATION,
120
  gen_kwargs={"data": validation_data},
121
  ),
122
- SplitGenerator(
123
- name=Split.TEST,
124
  gen_kwargs={"data": test_data},
125
  ),
126
  ]
 
4
  import random
5
  from typing import Generator
6
 
7
+ import datasets
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  _CITATION = """
10
  @inproceedings{omi-2021-wikipedia,
 
21
  _URL = "https://raw.githubusercontent.com/stockmarkteam/ner-wikipedia-dataset/main/ner.json"
22
 
23
 
24
+ class NerWikipediaDatasetConfig(datasets.BuilderConfig):
25
  def __init__(
26
  self,
27
  name: str = "default",
28
+ version: datasets.Version | str | None = datasets.Version("0.0.0"),
29
  data_dir: str | None = None,
30
+ data_files: datasets.data_files.DataFilesDict | None = None,
31
+ description: str | None = _DESCRIPTION,
32
  shuffle: bool = True,
33
  seed: int = 42,
34
  train_ratio: float = 0.8,
 
47
  self.validation_ratio = validation_ratio
48
 
49
 
50
+ class NerWikipediaDataset(datasets.GeneratorBasedBuilder):
51
  BUILDER_CONFIG_CLASS = NerWikipediaDatasetConfig
52
 
53
+ def _info(self) -> datasets.DatasetInfo:
54
+ return datasets.DatasetInfo(
 
 
55
  description=_DESCRIPTION,
56
+ features=datasets.Features(
 
 
 
 
 
 
57
  {
58
+ "curid": datasets.Value("string"),
59
+ "text": datasets.Value("string"),
60
  "entities": [
61
  {
62
+ "name": datasets.Value("string"),
63
+ "span": datasets.Sequence(
64
+ datasets.Value("int64"), length=2
65
+ ),
66
+ "type": datasets.Value("string"),
67
  }
68
  ],
69
  }
 
74
  )
75
 
76
  def _split_generators(
77
+ self, dl_manager: datasets.DownloadManager
78
+ ) -> list[datasets.SplitGenerator]:
79
  dataset_dir = str(dl_manager.download_and_extract(_URL))
80
  with open(dataset_dir, "r", encoding="utf-8") as f:
81
  data = json.load(f)
 
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,
96
  gen_kwargs={"data": train_data},
97
  ),
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.VALIDATION,
100
  gen_kwargs={"data": validation_data},
101
  ),
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.TEST,
104
  gen_kwargs={"data": test_data},
105
  ),
106
  ]