root commited on
Commit
b8c07f5
1 Parent(s): d9f7ff9

add dataset script

Browse files
Files changed (1) hide show
  1. the-stack-smol-xs.py +79 -0
the-stack-smol-xs.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Odex dataset."""
2
+
3
+ import json
4
+ import datasets
5
+
6
+
7
+ _CITATION = """\
8
+
9
+ """
10
+
11
+ _DESCRIPTION = """\
12
+
13
+ """
14
+
15
+ _HOMEPAGE = " "
16
+ LIST_LANG = ['ada', 'agda', 'alloy', 'antlr', 'applescript', 'assembly', 'augeas', 'awk', 'batchfile', 'bison',
17
+ 'bluespec', 'c', 'c++', 'c-sharp', 'clojure', 'cmake', 'coffeescript', 'common-lisp', 'css', 'cuda', 'dart', 'dockerfile', 'elixir',
18
+ 'elm', 'emacs-lisp','erlang', 'f-sharp', 'fortran', 'glsl', 'go', 'groovy', 'haskell','html', 'idris', 'isabelle', 'java',
19
+ 'java-server-pages', 'javascript', 'julia', 'kotlin', 'lean', 'literate-agda', 'literate-coffeescript', 'literate-haskell',
20
+ 'lua', 'makefile', 'maple', 'markdown', 'mathematica', 'matlab', 'ocaml', 'pascal', 'perl', 'php', 'powershell', 'prolog',
21
+ 'protocol-buffer', 'python', 'r', 'racket', 'restructuredtext', 'rmarkdown', 'ruby', 'rust', 'sas', 'scala', 'scheme',
22
+ 'shell', 'smalltalk', 'solidity', 'sparql', 'sql', 'stan', 'standard-ml', 'stata', 'systemverilog', 'tcl', 'tcsh', 'tex',
23
+ 'thrift', 'typescript', 'verilog', 'vhdl', 'visual-basic', 'xslt', 'yacc', 'zig']
24
+
25
+ _URLs = {lang: f"data/{lang}/data.json" for lang in LIST_LANG}
26
+
27
+
28
+ class Stack(datasets.GeneratorBasedBuilder):
29
+ """Stack Code dataset."""
30
+
31
+ VERSION = datasets.Version("1.0.0")
32
+
33
+
34
+ BUILDER_CONFIGS = [
35
+ datasets.BuilderConfig(
36
+ name=lang,
37
+ version=datasets.Version("1.0.0"),
38
+ description=_DESCRIPTION,
39
+ ) for lang in _URLs.keys()
40
+ ]
41
+
42
+ DEFAULT_CONFIG_NAME = "python"
43
+
44
+
45
+ def _info(self):
46
+ features = datasets.Features({"content": datasets.Value("string"),
47
+ "lang": datasets.Value("string"),
48
+ "size": datasets.Value("int64"),
49
+ "ext": datasets.Value("string"),
50
+ "max_stars_count": datasets.Value("int64"),
51
+ "avg_line_length": datasets.Value("float64"),
52
+ "max_line_length": datasets.Value("int64"),
53
+ "alphanum_fraction": datasets.Value("float64"),
54
+ })
55
+ return datasets.DatasetInfo(
56
+ description=_DESCRIPTION,
57
+ features=features,
58
+ supervised_keys=None,
59
+ citation=_CITATION,
60
+ homepage=_HOMEPAGE)
61
+
62
+ def _split_generators(self, dl_manager):
63
+ """Returns SplitGenerators."""
64
+ config_urls = _URLs[self.config.name]
65
+ data_dir = dl_manager.download_and_extract(config_urls)
66
+ return [
67
+ datasets.SplitGenerator(
68
+ name=datasets.Split.TRAIN,
69
+ gen_kwargs={"filepath": data_dir, "split": "train"},
70
+ ),
71
+ ]
72
+
73
+
74
+ def _generate_examples(self, filepath, split):
75
+ key = 0
76
+ for line in open(filepath, encoding="utf-8"):
77
+ line = json.loads(line)
78
+ yield key, line
79
+ key += 1