galtimur commited on
Commit
c6ea8f8
·
verified ·
1 Parent(s): 5a74ac0

Update dataset/dataset.py

Browse files
Files changed (1) hide show
  1. dataset/dataset.py +52 -21
dataset/dataset.py CHANGED
@@ -18,26 +18,57 @@ class BugLocalizationConfig(datasets.BuilderConfig):
18
  class BugLocalization(datasets.GeneratorBasedBuilder):
19
  """BugLocalization dataset"""
20
  BUILDER_CONFIGS = [
21
- BugLocalizationConfig(name=lang, description=f"My dataset for {lang}.")
22
  for lang in _LANGUAGES
23
  ]
24
- def _info(self):
25
- pass
26
-
27
- def _split_generators(self, dl_manager):
28
- urls = {
29
- "python": "python.jsonl",
30
- "java": "java.jsonl",
31
- "kotlin": "kotlin.jsonl",
32
- }
33
- downloaded_files = dl_manager.download_and_extract(urls)
34
- return [datasets.SplitGenerator(
35
- name=datasets.Split.TRAIN,
36
- gen_kwargs={"filepath": downloaded_files[self.config.name]}
37
- )]
38
-
39
- def _generate_examples(self, filepath):
40
- with open(filepath, encoding="utf-8") as f:
41
- for id_, line in enumerate(f):
42
- data = json.loads(line)
43
- yield data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  class BugLocalization(datasets.GeneratorBasedBuilder):
19
  """BugLocalization dataset"""
20
  BUILDER_CONFIGS = [
21
+ BugLocalizationConfig(name=lang, description=f"BugLocalization dataset for {lang}.")
22
  for lang in _LANGUAGES
23
  ]
24
+ def _info(self):
25
+ sample_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), f"{self.config.name}.jsonl")
26
+
27
+ # Infer schema from a sample
28
+ schema = self._infer_schema(sample_file)
29
+
30
+ return datasets.DatasetInfo(
31
+ features=datasets.Features(schema),
32
+ )
33
+
34
+ def _infer_schema(self, sample_file, num_samples=100):
35
+ """Infer schema from a sample of JSONL data."""
36
+ schema = {}
37
+ with open(sample_file, encoding="utf-8") as f:
38
+ for _ in range(num_samples):
39
+ line = f.readline()
40
+ if not line:
41
+ break
42
+ data = json.loads(line)
43
+ for key, value in data.items():
44
+ if key not in schema:
45
+ schema[key] = datasets.Value('string') # Assuming all values are strings, tweak as needed
46
+ return schema
47
+
48
+ def _split_generators(self, dl_manager):
49
+ # Path where the dataset files are located
50
+ data_dir = os.path.abspath(os.path.dirname(__file__))
51
+
52
+ # Define path to each of the JSONL files
53
+ paths = {
54
+ "python": os.path.join(data_dir, "python.jsonl"),
55
+ "java": os.path.join(data_dir, "java.jsonl"),
56
+ "kt": os.path.join(data_dir, "kotlin.jsonl"),
57
+ }
58
+
59
+ # Return the split with the appropriate file path
60
+ return [
61
+ datasets.SplitGenerator(
62
+ name=datasets.Split.TRAIN,
63
+ gen_kwargs={
64
+ "filepath": paths[self.config.name]
65
+ },
66
+ )
67
+ ]
68
+
69
+ def _generate_examples(self, filepath):
70
+ """Generate examples from a JSONL file."""
71
+ with open(filepath, encoding="utf-8") as f:
72
+ for id_, line in enumerate(f):
73
+ data = json.loads(line)
74
+ yield id_, data