IlyaGusev commited on
Commit
bf76870
1 Parent(s): bce7b6c

Script fix

Browse files
Files changed (1) hide show
  1. rulm.py +12 -15
rulm.py CHANGED
@@ -16,31 +16,28 @@
16
  # Lint as: python3
17
  """RuLM: a dataset for Russian language modeling"""
18
 
19
-
20
  import os
21
  import io
 
22
  import zstandard
23
  import jsonlines
24
-
25
  import datasets
26
 
27
  try:
28
- import simdjson as json
 
 
 
 
 
 
29
  except ImportError:
30
- print('Installing simdjson library')
31
- os.system('pip install -q pysimdjson')
32
- import simdjson as json
33
 
34
- parser = json.Parser()
35
 
36
- def json_parser(x):
37
- try:
38
- line = parser.parse(x).as_dict()
39
- return line
40
- except ValueError:
41
- return
42
 
43
- _DATASET_MODES = ["lm"]
44
  _TRAIN_SPLITS = 10
45
  _DESCRIPTION = "Dataset for Russian language modeling"
46
  _URLS = {
@@ -90,6 +87,6 @@ class RuLMDataset(datasets.GeneratorBasedBuilder):
90
  print(filename)
91
  cctx = zstandard.ZstdDecompressor()
92
  reader_stream = io.BufferedReader(cctx.stream_reader(f))
93
- reader = jsonlines.Reader(reader_stream, loads=json_parser)
94
  for id_, item in enumerate(reader):
95
  yield id_, {"text": item["text"]}
 
16
  # Lint as: python3
17
  """RuLM: a dataset for Russian language modeling"""
18
 
 
19
  import os
20
  import io
21
+
22
  import zstandard
23
  import jsonlines
 
24
  import datasets
25
 
26
  try:
27
+ import simdjson
28
+ parser = simdjson.Parser()
29
+ def parse_json(x):
30
+ try:
31
+ return parser.parse(x).as_dict()
32
+ except ValueError:
33
+ return
34
  except ImportError:
35
+ import json
36
+ def parse_json(x):
37
+ return json.loads(x)
38
 
 
39
 
 
 
 
 
 
 
40
 
 
41
  _TRAIN_SPLITS = 10
42
  _DESCRIPTION = "Dataset for Russian language modeling"
43
  _URLS = {
 
87
  print(filename)
88
  cctx = zstandard.ZstdDecompressor()
89
  reader_stream = io.BufferedReader(cctx.stream_reader(f))
90
+ reader = jsonlines.Reader(reader_stream, loads=parse_json)
91
  for id_, item in enumerate(reader):
92
  yield id_, {"text": item["text"]}