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

implemented preprocessing for secondary subfields

Browse files
all2023/val.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:728f5ae7ff4f3907c9a5e6f3b35d1a2968a02cd825f50dc575efe94c7d4e4ffa
3
- size 409838242
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d695efd145ac745cf81aab5073fc6938b7562b4330f1aed2cb029e3aae958627
3
+ size 412108395
major/test.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c7849149e5f504fd8f99efa3b5f1c2d65b541b2b76640d563bababa4b4f6d395
3
- size 406464012
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94c2a729e10b65e46a530ee56fe1f17ecf588ffbf978a9a15166a385134e48a6
3
+ size 406488121
major/train.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:37aa1843751273b4e27633b1ec1a0fad6256a9143ed48d81bbf34ffae03116c4
3
- size 1639035113
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ceb77a8b2c6fd61decbc05c5c469341637638dfe513e4238c994b79c8edc2fc
3
+ size 1639130854
minor/test.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:667308dc5ddfa3cf17869673427e5ce85abf054fee301e8a1cf58ee04e6d9d3a
3
- size 1453222079
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fab45ae4a61a692399a62538566ae755750592529ad21135a03946192e420fcf
3
+ size 1453299801
minor/train.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8834e6cfa89d589cffcc5335a3bc2371ce91f6627c4a653ec689b3e370582b8e
3
- size 5823161950
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1640a3c3cbf951940ed0edab35eac1c5d7c638c7e97f06d12fdd1902f7cb3e71
3
+ size 5823472832
preprocess.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # test
2
+ # python preprocess_major_minor.py -d major -s test
3
+
4
+ # major/minor cats
5
+ for dataset in major minor
6
+ do
7
+ for split in train test
8
+ do
9
+ python preprocess_major_minor.py -d $dataset -s $split
10
+ done
11
+ done
12
+ # all 2023 corpus
13
+ python preprocess_all2023.py
preprocess_all2023.py CHANGED
@@ -34,12 +34,9 @@ output_path = args.output_path
34
  # Remaining imports
35
  #
36
  import pandas as pd
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:
@@ -89,10 +86,8 @@ for i, original_df in tqdm(enumerate(pd.read_csv(file_path, sep='\t', chunksize=
89
  if feature not in original_df.columns:
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:
 
34
  # Remaining imports
35
  #
36
  import pandas as pd
 
37
  import os
38
  from tqdm import tqdm
39
+ from util_preprocess import preprocess_primary_secondary
 
 
40
 
41
  # %% [markdown]
42
  # Rename columns to reflect standarized terminology:
 
86
  if feature not in original_df.columns:
87
  original_df[feature] = ""
88
 
89
+ # Apply preprocessing rules
90
+ df = preprocess_primary_secondary(original_df)
 
 
91
 
92
  # convert all columns to string per huggingface requirements
93
  if i == 0:
preprocess_major_minor.py CHANGED
@@ -34,12 +34,9 @@ output_path = args.output_path
34
  # Remaining imports
35
  #
36
  import pandas as pd
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:
@@ -67,14 +64,14 @@ for i, original_df in tqdm(enumerate(pd.read_json(file_path, lines=True, chunksi
67
  'prime_category': 'primary_subfield',
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
  # %%
 
34
  # Remaining imports
35
  #
36
  import pandas as pd
 
37
  import os
38
  from tqdm import tqdm
39
+ from util_preprocess import preprocess_primary_secondary
 
 
40
 
41
  # %% [markdown]
42
  # Rename columns to reflect standarized terminology:
 
64
  'prime_category': 'primary_subfield',
65
  'abs_categories': 'secondary_subfield'
66
  }, inplace=True)
 
 
 
 
67
 
68
+ # Apply preprocessing rules
69
+ df = preprocess_primary_secondary(original_df)
70
+
71
+ # Save to file
72
  if i == 0:
73
  df.to_json(save_path, lines=True, orient="records")
74
  else:
75
  df.to_json(save_path, lines=True, orient="records", mode='a')
76
+ print("Saved to file: ", save_path)
77
  # %%
util_preprocess.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from arxiv_classifier.utils import (CATEGORY_ALIASES,
2
+ GENERAL_CATEGORIES,
3
+ IGNORED_CATEGOREIES)
4
+
5
+ IGNORE = GENERAL_CATEGORIES | IGNORED_CATEGOREIES
6
+
7
+ def preprocess_primary_secondary(original_df):
8
+ df = original_df[~original_df['field'].isin(IGNORE)]
9
+ if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
10
+ ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
11
+
12
+ def preprocess_secondary(s):
13
+ # split string to list by space
14
+ subfields = s.split()
15
+ # ignore entries from ignored categories (i.e., primary subfield)
16
+ subfields = [subfield for subfield in subfields if subfield not in IGNORE]
17
+ # substitute subfield aliases
18
+ if set(subfields) & set(CATEGORY_ALIASES.keys()):
19
+ ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
20
+ return subfields
21
+
22
+ # Preprocess secondary subfields
23
+ df.loc[:, 'secondary_subfield'] = df['secondary_subfield'].apply(preprocess_secondary)
24
+ return df