OleehyO commited on
Commit
3df5e66
1 Parent(s): 9cae0ba

Upload 24 files

Browse files
.gitattributes CHANGED
@@ -54,3 +54,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
  raw_formulas.jsonl filter=lfs diff=lfs merge=lfs -text
 
 
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
  raw_formulas.jsonl filter=lfs diff=lfs merge=lfs -text
57
+ common_formulas.jsonl filter=lfs diff=lfs merge=lfs -text
common_formulas.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:faa3cc98fb959a7dfd21d80393b32c45cea3f29811db2e231405aa70b538252c
3
+ size 272368766
common_formulas.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from io import BytesIO
2
+ from PIL import Image
3
+ from pathlib import Path
4
+ import datasets
5
+ import json
6
+
7
+
8
+ RAW_METADATA_URL = r'/home/lhy/arxiv_crawler/common_formulas/raw_formulas.jsonl'
9
+
10
+ DIR_URL = r'/home/lhy/arxiv_crawler/common_formulas'
11
+
12
+
13
+ class LatexFormulasConfig(datasets.BuilderConfig):
14
+ def __init__(self, data_url, **kwargs):
15
+ super().__init__(**kwargs)
16
+ self.data_url = data_url
17
+
18
+
19
+ class LatexFormulas(datasets.GeneratorBasedBuilder):
20
+ BUILDER_CONFIGS = [
21
+ LatexFormulasConfig(
22
+ name="raw_formulas",
23
+ data_url=RAW_METADATA_URL
24
+ ),
25
+ LatexFormulasConfig(
26
+ name="tokenized_formulas",
27
+ data_url=DIR_URL
28
+ )
29
+ ]
30
+
31
+ def _info(self):
32
+ if self.config.name == "raw_formulas":
33
+ return datasets.DatasetInfo(
34
+ features=datasets.Features({
35
+ "latex_formula": datasets.Value("string")
36
+ })
37
+ )
38
+ if self.config.name == "tokenized_formulas":
39
+ return datasets.DatasetInfo(
40
+ features=datasets.Features({
41
+ "image": datasets.Image(),
42
+ "latex_formula": datasets.Value("string")
43
+ })
44
+ )
45
+
46
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
47
+ data_path = dl_manager.download(self.config.data_url)
48
+ if self.config.name == 'raw_formulas':
49
+ return [
50
+ datasets.SplitGenerator(
51
+ name=datasets.Split.TRAIN,
52
+ gen_kwargs={
53
+ "data_path": data_path
54
+ }
55
+ )
56
+ ]
57
+
58
+ if self.config.name == "tokenized_formulas":
59
+ dir_path = Path(data_path)
60
+ assert dir_path.is_dir()
61
+
62
+ return [
63
+ datasets.SplitGenerator(
64
+ name=datasets.Split.TRAIN,
65
+ gen_kwargs={
66
+ 'dir_path': dir_path,
67
+ 'dl_manager': dl_manager
68
+ }
69
+ )
70
+ ]
71
+
72
+ def _generate_examples(self, data_path=None, dir_path: Path=None, dl_manager=None):
73
+ if self.config.name == 'tokenized_formulas':
74
+ idx = 0
75
+ for directory in dir_path.iterdir():
76
+ if not directory.is_dir():
77
+ continue
78
+ if not directory.name.startswith('process'):
79
+ continue
80
+ image_path = str(directory / "compressed_img.tar.gz")
81
+ metadata_path = str(directory / "tokenized_finally.jsonl")
82
+ images = dl_manager.iter_archive(image_path)
83
+
84
+ img_formula_pair = {}
85
+ with open(metadata_path, 'r', encoding='utf-8') as f:
86
+ for line in f:
87
+ single_json = json.loads(line)
88
+ img_formula_pair[single_json['id']] = single_json['formula']
89
+
90
+ for img_path, img_obj in images:
91
+ img_name = img_path.split('/')[-1]
92
+
93
+ if img_name in img_formula_pair:
94
+ idx += 1
95
+ # yield idx, {
96
+ yield str(directory) + img_path, {
97
+ "image": {"path": img_path, "bytes": img_obj.read()},
98
+ "latex_formula": img_formula_pair[img_name]
99
+ }
100
+
101
+ if self.config.name == 'raw_formulas':
102
+ assert data_path is not None
103
+ with open(data_path, 'r', encoding="utf-8") as f:
104
+ for idx, line in enumerate(f):
105
+ yield idx, {
106
+ "latex_formula": json.loads(line)["formula"]
107
+ }
process_0/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:185be79b4f026b632a9fce1b81e88f22161a976ab3d9cd3afb73e0f8d87f02d0
3
+ size 53983976
process_0/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_1/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22a245654a111fda7e5aa4c9dcb5159cce14a5b63546108d3a495090ac41536f
3
+ size 52342371
process_1/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_10/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a41e085c6d5d1ae2f8a0fa3f512625c296ed096cea99e0761d3eaca2634ebc9f
3
+ size 50238992
process_10/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_2/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0275ca8c31b022d8fe2eaa64cc0e8888602a3b1f2ea1b7d5cc27a2a06367255
3
+ size 52900128
process_2/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_3/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef8dc76f9dc4d65940b34ac036f7de4f3309130a75c6215de940d7d771c4e038
3
+ size 52075192
process_3/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_4/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02334da7d15d332b00996f13fc64c231a97875fe3a3ba5920da02955a850fc2d
3
+ size 51571590
process_4/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_5/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a44e0e2e076173980b83262936de3991cce9aaad6d46e23a1a22e403cb6d7418
3
+ size 56831857
process_5/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_6/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d0027e397695ee323c75605ead793c01d1d87272c6301d449ac5fd88925db37
3
+ size 53207690
process_6/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_7/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90fb64dac7d7aef644d9e2d59da32570a64edcc3b835a79eb91edfb8ad0f800a
3
+ size 51257160
process_7/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_8/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:024382d797d380905dfab9b2fbc79eaca2dcae45bd7b7bc9eebf4beb544f3700
3
+ size 55655655
process_8/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
process_9/compressed_img.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9a710e61de385d4cb48be97f8918560c70d25b477e2f3f5fa147a4c0d396cee
3
+ size 46466109
process_9/tokenized_finally.jsonl ADDED
The diff for this file is too large to render. See raw diff