罗杰斯 commited on
Commit
b94e562
1 Parent(s): 49219df

Update build.py

Browse files
Files changed (1) hide show
  1. build.py +28 -16
build.py CHANGED
@@ -1,5 +1,7 @@
1
  import json
 
2
 
 
3
  from pydantic import BaseModel
4
 
5
 
@@ -23,14 +25,14 @@ def is_chinese(text: str):
23
  if is_chinese_char(char):
24
  cn_count += 1
25
 
26
- return cn_count * 5 > len(text)
27
 
28
 
29
- with open("train.jsonl", "wb") as cn:
30
- with open("/Users/diegorojas/Desktop/markdown.jsonl", "r") as samples:
31
- for sample in samples:
32
  try:
33
- data = json.loads(sample)
34
  except json.JSONDecodeError as e:
35
  print(f"Error: {e}")
36
  continue
@@ -41,16 +43,26 @@ with open("train.jsonl", "wb") as cn:
41
  data["license"],
42
  )
43
 
44
- if license not in ["", "MIT", "Apache-2.0"]:
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  continue
46
 
47
- encoded = Sample(
48
- code=code,
49
- size=size,
50
- license=license,
51
- ).model_dump_json()
52
-
53
- language = is_chinese(code)
54
-
55
- if language == "cn":
56
- cn.write(encoded.encode("utf-8") + b"\n")
 
1
  import json
2
+ import sys
3
 
4
+ import tqdm
5
  from pydantic import BaseModel
6
 
7
 
 
25
  if is_chinese_char(char):
26
  cn_count += 1
27
 
28
+ return True if cn_count * 50 > len(text) else False
29
 
30
 
31
+ with open(sys.argv[1], "r") as inp:
32
+ with open(sys.argv[2], "wb") as out:
33
+ for line in tqdm.tqdm(inp):
34
  try:
35
+ data = json.loads(line)
36
  except json.JSONDecodeError as e:
37
  print(f"Error: {e}")
38
  continue
 
43
  data["license"],
44
  )
45
 
46
+ if license not in [
47
+ "",
48
+ "MIT",
49
+ "Apache-2.0",
50
+ "CC-BY-4.0",
51
+ "CC-BY-3.0",
52
+ "MIT-0",
53
+ "CC0-1.0",
54
+ "BSD-3-Clause",
55
+ "BSD-2-Clause",
56
+ "BSD-Source-Code",
57
+ "EC",
58
+ "Unlicense",
59
+ ]:
60
  continue
61
 
62
+ if is_chinese(code):
63
+ encoded = Sample(
64
+ code=code,
65
+ size=size,
66
+ license=license,
67
+ ).model_dump_json()
68
+ out.write(encoded.encode("utf-8") + b"\n")