kernelmachine commited on
Commit
47f7c92
1 Parent(s): 7bcc487
Files changed (1) hide show
  1. open-license-corpus.py +19 -23
open-license-corpus.py CHANGED
@@ -60,17 +60,16 @@ N_SHARDS_PER_SPLIT = {
60
  DATA_URL = 'https://huggingface.co/datasets/kernelmachine/open-license-corpus/resolve/main/data/{name}/{split}-{index:05d}-of-{n_shards:05d}.jsonl.gz'
61
 
62
  class OpenLicenseCorpusConfig(datasets.BuilderConfig):
63
- def __init__(self, *args, subsets, **kwargs):
64
- super(OpenLicenseCorpusConfig, self).__init__(**kwargs)
65
- self.subsets = subsets
66
 
67
 
68
  class OpenLicenseCorpus(datasets.GeneratorBasedBuilder):
69
 
70
  BUILDER_CONFIGS = [
71
- OpenLicenseCorpusConfig(name=name, subsets=[name], version=datasets.Version("1.0.0", ""), description=f"OpenLicenseCorpus {name} subset")
72
  for name in OLC_SUBSET_NAMES
73
- ]
74
 
75
  def _info(self):
76
  return datasets.DatasetInfo(
@@ -88,27 +87,24 @@ class OpenLicenseCorpus(datasets.GeneratorBasedBuilder):
88
  def _split_generators(self, dl_manager):
89
  data_urls = {}
90
  for split in ["train"]:
91
- for subset in self.config.subsets:
92
- n_shards = N_SHARDS_PER_SPLIT[subset][split] - 1
93
- data_urls[split] = {subset: [
94
- DATA_URL.format(name=self.config.name, split=split, index=index, n_shards=n_shards)
95
- for index in range(n_shards)
96
- ]
97
- }
98
 
99
- train_downloaded_files = {subset: dl_manager.download(data_urls["train"]) for subset in self.config.subsets}
100
 
101
- return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": { subset : train_downloaded_files[subset] for subset in self.config.subsets}})]
102
 
103
  def _generate_examples(self, filepaths):
104
  """This function returns the examples in the raw (text) form by iterating on all the files."""
105
  id_ = 0
106
- for subset in filepaths:
107
- for path in filepaths[subset]:
108
- logger.info("generating examples from = %s", path)
109
- with gzip.open(open(path, "rb"), "rt", encoding="utf-8") as f:
110
- for line in f:
111
- if line:
112
- example = json.loads(line)
113
- yield id_, example
114
- id_ += 1
 
60
  DATA_URL = 'https://huggingface.co/datasets/kernelmachine/open-license-corpus/resolve/main/data/{name}/{split}-{index:05d}-of-{n_shards:05d}.jsonl.gz'
61
 
62
  class OpenLicenseCorpusConfig(datasets.BuilderConfig):
63
+ def __init__(self, features, citation, **kwargs):
64
+ super().__init__(**kwargs)
 
65
 
66
 
67
  class OpenLicenseCorpus(datasets.GeneratorBasedBuilder):
68
 
69
  BUILDER_CONFIGS = [
70
+ datasets.BuilderConfig(name=name)
71
  for name in OLC_SUBSET_NAMES
72
+ ]
73
 
74
  def _info(self):
75
  return datasets.DatasetInfo(
 
87
  def _split_generators(self, dl_manager):
88
  data_urls = {}
89
  for split in ["train"]:
90
+ n_shards = N_SHARDS_PER_SPLIT[self.config.name][split] - 1
91
+ data_urls[split] = [
92
+ DATA_URL.format(name=self.config.name, split=split, index=index, n_shards=n_shards)
93
+ for index in range(n_shards)
94
+ ]
 
 
95
 
96
+ train_downloaded_files = dl_manager.download(data_urls["train"])
97
 
98
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": train_downloaded_files})]
99
 
100
  def _generate_examples(self, filepaths):
101
  """This function returns the examples in the raw (text) form by iterating on all the files."""
102
  id_ = 0
103
+ for filepath in filepaths:
104
+ logger.info("generating examples from = %s", filepath)
105
+ with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
106
+ for line in f:
107
+ if line:
108
+ example = json.loads(line)
109
+ yield id_, example
110
+ id_ += 1