ag2435 commited on
Commit
f7685b7
·
1 Parent(s): b1e8bb0

removed restriction on paper versions for major, minor, all2023

Browse files
README.md CHANGED
@@ -35,6 +35,16 @@ Original data: https://www.dropbox.com/scl/fo/wwu0ifghw4sco09g67frb/h?rlkey=6ddg
35
 
36
  <!-- Working doc: https://docs.google.com/document/d/1ZTiR5M7NBpsfYbJdlP6qcIldBJVzJI1Hm8srgI8hfnI/edit?usp=sharing -->
37
 
 
 
 
 
 
 
 
 
 
 
38
  ## Preprocessing
39
 
40
  Transform raw data into JSON format:
 
35
 
36
  <!-- Working doc: https://docs.google.com/document/d/1ZTiR5M7NBpsfYbJdlP6qcIldBJVzJI1Hm8srgI8hfnI/edit?usp=sharing -->
37
 
38
+ ## Set up dependencies
39
+
40
+ Get subfields to ignore and subfield aliases:
41
+ ```
42
+ # in your conda env
43
+ git clone https://github.com/ag2435/arxiv-classifier-next
44
+ cd arxiv-classifier-next
45
+ conda develop .
46
+ ```
47
+
48
  ## Preprocessing
49
 
50
  Transform raw data into JSON format:
all2023/val.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9e6c4607bdb7d64e7a7e39d24fe2585d45c392d80707f3b8cb935fee68fe524f
3
- size 285350475
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:728f5ae7ff4f3907c9a5e6f3b35d1a2968a02cd825f50dc575efe94c7d4e4ffa
3
+ size 409838242
major/test.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f479ccd1901ebd967a64a17b6ec9934501629f5caa7bc88b9fb8ca512f54011a
3
- size 216694822
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c7849149e5f504fd8f99efa3b5f1c2d65b541b2b76640d563bababa4b4f6d395
3
+ size 406464012
major/train.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:258b7304c47a12f0c035657831926953207399fccbcfa9018817b514a2cbff7b
3
- size 863033790
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37aa1843751273b4e27633b1ec1a0fad6256a9143ed48d81bbf34ffae03116c4
3
+ size 1639035113
minor/test.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fb4a6091612f356e4c6184bae2468d4ac5f5fc41729d947b1eaec82017b06ed5
3
- size 860652299
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:667308dc5ddfa3cf17869673427e5ce85abf054fee301e8a1cf58ee04e6d9d3a
3
+ size 1453222079
minor/train.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:93e6352bf9f03225a256f0e44a83b4de3b608b4024ac78ba3b808e9b0db223b3
3
- size 3410271223
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8834e6cfa89d589cffcc5335a3bc2371ce91f6627c4a653ec689b3e370582b8e
3
+ size 5823161950
preprocess_all2023.py CHANGED
@@ -37,23 +37,9 @@ import pandas as pd
37
  import numpy as np
38
  import os
39
  from tqdm import tqdm
40
-
41
- # %%
42
- IGNORED_CATEGOREIES = set([
43
- "atom-ph", "bayes-an", "chao-dyn", "chem-ph", "cmp-lg", "comp-gas", "cond-mat", "dg-ga", "funct-an",
44
- "mtrl-th", "patt-sol", "plasm-ph", "q-alg", "q-bio", "solv-int", "supr-con", "test", "test.dis-nn",
45
- "test.mes-hall", "test.mtrl-sci", "test.soft", "test.stat-mech", "test.str-el", "test.supr-con"
46
- ])
47
- print("number of ignored categories: ", len(IGNORED_CATEGOREIES))
48
- CATEGORY_ALIASES = {
49
- 'math.MP': 'math-ph',
50
- 'stat.TH': 'math.ST',
51
- 'math.IT': 'cs.IT',
52
- 'q-fin.EC': 'econ.GN',
53
- 'cs.SY': 'eess.SY',
54
- 'cs.NA': 'math.NA'
55
- }
56
- print("number of category aliases: ", len(CATEGORY_ALIASES))
57
 
58
  # %% [markdown]
59
  # Rename columns to reflect standarized terminology:
@@ -104,16 +90,15 @@ for i, original_df in tqdm(enumerate(pd.read_csv(file_path, sep='\t', chunksize=
104
  original_df[feature] = ""
105
 
106
  # ignore entries from ignored categories (i.e., primary subfield)
107
- df = original_df[~original_df['primary_subfield'].isin(IGNORED_CATEGOREIES)]
108
- df = df[(df['version'] == 1)]
109
  if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
110
  ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
111
 
112
  # convert all columns to string per huggingface requirements
113
  if i == 0:
114
- df.astype(str).to_json(save_path, lines=True, orient="records")
115
  else:
116
- df.astype(str).to_json(save_path, lines=True, orient="records", mode='a')
117
 
118
  print("Saved to: ", save_path)
119
  # %%
 
37
  import numpy as np
38
  import os
39
  from tqdm import tqdm
40
+ from arxiv_classifier.utils import (CATEGORY_ALIASES,
41
+ GENERAL_CATEGORIES,
42
+ IGNORED_CATEGOREIES)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  # %% [markdown]
45
  # Rename columns to reflect standarized terminology:
 
90
  original_df[feature] = ""
91
 
92
  # ignore entries from ignored categories (i.e., primary subfield)
93
+ df = original_df[~original_df['primary_subfield'].isin(GENERAL_CATEGORIES | IGNORED_CATEGOREIES)]
 
94
  if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
95
  ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
96
 
97
  # convert all columns to string per huggingface requirements
98
  if i == 0:
99
+ df.to_json(save_path, lines=True, orient="records")
100
  else:
101
+ df.to_json(save_path, lines=True, orient="records", mode='a')
102
 
103
  print("Saved to: ", save_path)
104
  # %%
preprocess_major_minor.py CHANGED
@@ -37,23 +37,9 @@ import pandas as pd
37
  import numpy as np
38
  import os
39
  from tqdm import tqdm
40
-
41
- # %%
42
- IGNORED_CATEGOREIES = set([
43
- "atom-ph", "bayes-an", "chao-dyn", "chem-ph", "cmp-lg", "comp-gas", "cond-mat", "dg-ga", "funct-an",
44
- "mtrl-th", "patt-sol", "plasm-ph", "q-alg", "q-bio", "solv-int", "supr-con", "test", "test.dis-nn",
45
- "test.mes-hall", "test.mtrl-sci", "test.soft", "test.stat-mech", "test.str-el", "test.supr-con"
46
- ])
47
- print("number of ignored categories: ", len(IGNORED_CATEGOREIES))
48
- CATEGORY_ALIASES = {
49
- 'math.MP': 'math-ph',
50
- 'stat.TH': 'math.ST',
51
- 'math.IT': 'cs.IT',
52
- 'q-fin.EC': 'econ.GN',
53
- 'cs.SY': 'eess.SY',
54
- 'cs.NA': 'math.NA'
55
- }
56
- print("number of category aliases: ", len(CATEGORY_ALIASES))
57
 
58
  # %% [markdown]
59
  # Rename columns to reflect standarized terminology:
@@ -74,16 +60,7 @@ os.makedirs(save_dir, exist_ok=True)
74
  save_path = os.path.join(save_dir, f"{split}.json")
75
  print("Reading from file: ", file_path)
76
 
77
- # # delete file if it exists
78
- # if os.path.exists(save_path):
79
- # print("Overwriting existing file: ", save_path)
80
- # os.remove(save_path)
81
-
82
- # with open(save_path, 'a') as f:
83
- for i, original_df in tqdm(enumerate(pd.read_json(file_path, lines=True, chunksize=10**4))):
84
- # print(f"Chunk {i+1}")
85
- # print("original columns: ", original_df.columns)
86
-
87
  # Rename columns
88
  original_df.rename(columns={
89
  'major_category': 'field',
@@ -91,25 +68,13 @@ for i, original_df in tqdm(enumerate(pd.read_json(file_path, lines=True, chunksi
91
  'abs_categories': 'secondary_subfield'
92
  }, inplace=True)
93
  # ignore entries from ignored categories (i.e., primary subfield)
94
- df = original_df[~original_df['field'].isin(IGNORED_CATEGOREIES)]
95
- df = df[(df['version'] == 1)]
96
  if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
97
  ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
98
 
99
- # # preprocess the chunk here
100
- # df_chunk = df.astype(str)
101
- # # convert the DataFrame to a JSON string
102
- # json_str = df_chunk.to_json(orient='records', lines=True)
103
-
104
- # # write the JSON string to file
105
- # f.write(json_str)
106
-
107
- # # add a newline character after each chunk except the last one
108
- # # if i != num_chunks - 1:
109
- # f.write('\n')
110
  if i == 0:
111
- df.astype(str).to_json(save_path, lines=True, orient="records")
112
  else:
113
- df.astype(str).to_json(save_path, lines=True, orient="records", mode='a')
114
 
115
  # %%
 
37
  import numpy as np
38
  import os
39
  from tqdm import tqdm
40
+ from arxiv_classifier.utils import (CATEGORY_ALIASES,
41
+ GENERAL_CATEGORIES,
42
+ IGNORED_CATEGOREIES)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  # %% [markdown]
45
  # Rename columns to reflect standarized terminology:
 
60
  save_path = os.path.join(save_dir, f"{split}.json")
61
  print("Reading from file: ", file_path)
62
 
63
+ for i, original_df in tqdm(enumerate(pd.read_json(file_path, lines=True, chunksize=10**4, dtype=str))):
 
 
 
 
 
 
 
 
 
64
  # Rename columns
65
  original_df.rename(columns={
66
  'major_category': 'field',
 
68
  'abs_categories': 'secondary_subfield'
69
  }, inplace=True)
70
  # ignore entries from ignored categories (i.e., primary subfield)
71
+ df = original_df[~original_df['field'].isin(GENERAL_CATEGORIES | IGNORED_CATEGOREIES)]
 
72
  if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
73
  ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
74
 
 
 
 
 
 
 
 
 
 
 
 
75
  if i == 0:
76
+ df.to_json(save_path, lines=True, orient="records")
77
  else:
78
+ df.to_json(save_path, lines=True, orient="records", mode='a')
79
 
80
  # %%
test_paper_id.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # script to test for any paper id overlap between the training and test set
2
+ # to run:
3
+ # python test_paper_id.py
4
+
5
+ import pandas as pd
6
+ import re
7
+ from tqdm import tqdm
8
+
9
+ def test(dataset):
10
+ print(f"Checking dataset: {dataset}")
11
+ # load the training and test data
12
+ train_file = f"data/raw/{dataset}/train_{dataset}_cats_full.json"
13
+ # read json in chunks of 1000 rows, get the paper_id column and convert to list
14
+ train_ids = []
15
+ for df in tqdm(pd.read_json(train_file, lines=True, chunksize=1000, dtype=str)):
16
+ train_ids.extend(df['paper_id'].tolist())
17
+ test_file = f"data/raw/{dataset}/test_{dataset}_cats_full.json"
18
+ test_ids = []
19
+ for df in tqdm(pd.read_json(test_file, lines=True, chunksize=1000, dtype=str)):
20
+ test_ids.extend(df['paper_id'].tolist())
21
+
22
+ # check paper id formats
23
+ ARXIV_IDENTIFIER_PATTERN = r"^\d{2}(0[1-9]|1[0-2])\.\d{4,5}$"
24
+ OLD_ARXIV_IDENTIFIER_PATTERN = r"^[\w\-]+/\d{7}$"
25
+ assert not any([re.match(ARXIV_IDENTIFIER_PATTERN, pid) is None for pid in train_ids if '.' in pid])
26
+ assert not any([re.match(ARXIV_IDENTIFIER_PATTERN, pid) is None for pid in test_ids if '.' in pid])
27
+ assert not any([re.match(OLD_ARXIV_IDENTIFIER_PATTERN, pid) is None for pid in train_ids if '/' in pid])
28
+ assert not any([re.match(OLD_ARXIV_IDENTIFIER_PATTERN, pid) is None for pid in test_ids if '/' in pid])
29
+
30
+ # check for overlap
31
+ overlap = set(train_ids).intersection(set(test_ids))
32
+ assert len(overlap) == 0, f"Overlap found: {overlap}"
33
+
34
+ if __name__ == "__main__":
35
+ test("major")
36
+ test("minor")
37
+ print("All tests passed!")