Datasets:

Languages:
Japanese
License:
Kosuke-Yamada commited on
Commit
3a6b34c
1 Parent(s): 9d30a18

modify file

Browse files
Files changed (1) hide show
  1. ner-wikipedia-dataset.py +33 -5
ner-wikipedia-dataset.py CHANGED
@@ -4,6 +4,7 @@ from typing import Generator
4
 
5
  from datasets import (
6
  BuilderConfig,
 
7
  DatasetInfo,
8
  DownloadManager,
9
  Features,
@@ -30,9 +31,35 @@ _LICENSE = "CC-BY-SA 3.0"
30
  _URL = "https://raw.githubusercontent.com/stockmarkteam/ner-wikipedia-dataset/main/ner.json"
31
 
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  class NerWikipediaDataset(GeneratorBasedBuilder):
34
  BUILDER_CONFIGS = [
35
- BuilderConfig(
36
  name="ner-wikipedia-dataset",
37
  version=Version("2.0.0"),
38
  description=_DESCRIPTION,
@@ -67,12 +94,13 @@ class NerWikipediaDataset(GeneratorBasedBuilder):
67
  with open(dataset_dir, "r", encoding="utf-8") as f:
68
  data = json.load(f)
69
 
70
- random.seed(42)
71
- random.shuffle(data)
 
72
 
73
  num_data = len(data)
74
- num_train_data = int(num_data * 0.8)
75
- num_validation_data = (num_data - num_train_data) // 2
76
  train_data = data[:num_train_data]
77
  validation_data = data[
78
  num_train_data : num_train_data + num_validation_data
 
4
 
5
  from datasets import (
6
  BuilderConfig,
7
+ DataFilesDict,
8
  DatasetInfo,
9
  DownloadManager,
10
  Features,
 
31
  _URL = "https://raw.githubusercontent.com/stockmarkteam/ner-wikipedia-dataset/main/ner.json"
32
 
33
 
34
+ class NerWikipediaDatasetConfig(BuilderConfig):
35
+ def __init__(
36
+ self,
37
+ name: str = "default",
38
+ version: Version | str | None = Version("0.0.0"),
39
+ data_dir: str | None = None,
40
+ data_files: DataFilesDict | None = None,
41
+ description: str | None = None,
42
+ shuffle: bool = True,
43
+ seed: int = 42,
44
+ train_ratio: float = 0.8,
45
+ validation_ratio: float = 0.1,
46
+ ) -> None:
47
+ super().__init__(
48
+ name=name,
49
+ version=version,
50
+ data_dir=data_dir,
51
+ data_files=data_files,
52
+ description=description,
53
+ )
54
+ self.shuffle = shuffle
55
+ self.seed = seed
56
+ self.train_ratio = train_ratio
57
+ self.validation_ratio = validation_ratio
58
+
59
+
60
  class NerWikipediaDataset(GeneratorBasedBuilder):
61
  BUILDER_CONFIGS = [
62
+ NerWikipediaDatasetConfig(
63
  name="ner-wikipedia-dataset",
64
  version=Version("2.0.0"),
65
  description=_DESCRIPTION,
 
94
  with open(dataset_dir, "r", encoding="utf-8") as f:
95
  data = json.load(f)
96
 
97
+ if self.config.shuffle == True:
98
+ random.seed(self.config.seed)
99
+ random.shuffle(data)
100
 
101
  num_data = len(data)
102
+ num_train_data = int(num_data * self.config.train_ratio)
103
+ num_validation_data = int(num_data * self.config.validation_ratio)
104
  train_data = data[:num_train_data]
105
  validation_data = data[
106
  num_train_data : num_train_data + num_validation_data