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

bug fix related to subfield/category aliases

Browse files
all2023/val.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d695efd145ac745cf81aab5073fc6938b7562b4330f1aed2cb029e3aae958627
3
- size 412108395
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:016f8e4a4fe37bb0f1ff9f71d842e1d500db965ba6428d0a4124adfa47ce0f48
3
+ size 409838372
major/test.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:94c2a729e10b65e46a530ee56fe1f17ecf588ffbf978a9a15166a385134e48a6
3
- size 406488121
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77359a2c1fe3cbeeba38694398b94ce4d97047d5b77f06e8e50996044e896f9e
3
+ size 434108093
major/train.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9ceb77a8b2c6fd61decbc05c5c469341637638dfe513e4238c994b79c8edc2fc
3
- size 1639130854
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68979fe29cbae77e4bca24d6b892a959192385b1a5dd9a32d96acb549fbc1759
3
+ size 1741063444
minor/train.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1640a3c3cbf951940ed0edab35eac1c5d7c638c7e97f06d12fdd1902f7cb3e71
3
- size 5823472832
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21ee95f10cd102f2ca8a8fdbb390cb59df3a37ca2f1010a1c0407ffcb7dbaed0
3
+ size 560901682
preprocess.sh CHANGED
@@ -1,13 +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
 
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 -ip $1
10
+ # done
11
+ # done
12
  # all 2023 corpus
13
+ python preprocess_all2023.py -ip $1
preprocess_all2023.py CHANGED
@@ -23,11 +23,14 @@ parser = ArgumentParser()
23
  # parser.add_argument("--dataset", "-d", type=str, default="minor")
24
  # parser.add_argument("--split", "-s", type=str, default="val")
25
  parser.add_argument("--output_path", "-op", type=str, default="./")
 
 
26
  args, opt = parser.parse_known_args()
27
 
28
  dataset = 'all2023' # args.dataset
29
  split = 'val' # args.split
30
  output_path = args.output_path
 
31
 
32
  # %%
33
  #
@@ -52,7 +55,12 @@ from util_preprocess import preprocess_primary_secondary
52
 
53
  # %%
54
  # file_path = os.path.join('data', 'raw', dataset, f"{split}_{dataset}_cats_full.json")
55
- file_path = 'data/raw/all2023/all-2023-new-reps.tsv'
 
 
 
 
 
56
  save_dir = os.path.join(output_path, dataset)
57
  os.makedirs(save_dir, exist_ok=True)
58
  save_path = os.path.join(save_dir, f"{split}.json")
 
23
  # parser.add_argument("--dataset", "-d", type=str, default="minor")
24
  # parser.add_argument("--split", "-s", type=str, default="val")
25
  parser.add_argument("--output_path", "-op", type=str, default="./")
26
+ parser.add_argument("--input_path", "-ip", type=str, default="./",
27
+ help="Path to the input data files")
28
  args, opt = parser.parse_known_args()
29
 
30
  dataset = 'all2023' # args.dataset
31
  split = 'val' # args.split
32
  output_path = args.output_path
33
+ input_path = args.input_path
34
 
35
  # %%
36
  #
 
55
 
56
  # %%
57
  # file_path = os.path.join('data', 'raw', dataset, f"{split}_{dataset}_cats_full.json")
58
+ file_path = os.path.join(
59
+ input_path,
60
+ 'raw',
61
+ 'all2023',
62
+ 'all-2023-new-reps.tsv'
63
+ )
64
  save_dir = os.path.join(output_path, dataset)
65
  os.makedirs(save_dir, exist_ok=True)
66
  save_path = os.path.join(save_dir, f"{split}.json")
preprocess_major_minor.py CHANGED
@@ -23,11 +23,14 @@ parser = ArgumentParser()
23
  parser.add_argument("--dataset", "-d", type=str, default="minor")
24
  parser.add_argument("--split", "-s", type=str, default="train")
25
  parser.add_argument("--output_path", "-op", type=str, default="./")
 
 
26
  args, opt = parser.parse_known_args()
27
 
28
  dataset = args.dataset
29
  split = args.split
30
  output_path = args.output_path
 
31
 
32
  # %%
33
  #
@@ -51,7 +54,12 @@ from util_preprocess import preprocess_primary_secondary
51
  # - Major category = field
52
 
53
  # %%
54
- file_path = os.path.join('data', 'raw', dataset, f"{split}_{dataset}_cats_full.json")
 
 
 
 
 
55
  save_dir = os.path.join(output_path, dataset)
56
  os.makedirs(save_dir, exist_ok=True)
57
  save_path = os.path.join(save_dir, f"{split}.json")
 
23
  parser.add_argument("--dataset", "-d", type=str, default="minor")
24
  parser.add_argument("--split", "-s", type=str, default="train")
25
  parser.add_argument("--output_path", "-op", type=str, default="./")
26
+ parser.add_argument("--input_path", "-ip", type=str, default="./",
27
+ help="Path to the input data files")
28
  args, opt = parser.parse_known_args()
29
 
30
  dataset = args.dataset
31
  split = args.split
32
  output_path = args.output_path
33
+ input_path = args.input_path
34
 
35
  # %%
36
  #
 
54
  # - Major category = field
55
 
56
  # %%
57
+ file_path = os.path.join(
58
+ input_path,
59
+ 'raw',
60
+ dataset,
61
+ f"{split}_{dataset}_cats_full.json"
62
+ )
63
  save_dir = os.path.join(output_path, dataset)
64
  os.makedirs(save_dir, exist_ok=True)
65
  save_path = os.path.join(save_dir, f"{split}.json")
util_preprocess.py CHANGED
@@ -1,24 +1,40 @@
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
 
1
  from arxiv_classifier.utils import (CATEGORY_ALIASES,
2
  GENERAL_CATEGORIES,
3
+ IGNORED_CATEGOREIES,
4
+ SUBFIELD_MAP)
5
 
6
  IGNORE = GENERAL_CATEGORIES | IGNORED_CATEGOREIES
7
 
8
+ def preprocess_primary_secondary(df):
9
+ def substitute_aliases(s):
10
+ if s in CATEGORY_ALIASES:
11
+ return CATEGORY_ALIASES[s]
12
+ return s
13
+ # substitute aliases for primary subfield
14
+ df.loc[:, 'primary_subfield'] = df['primary_subfield'].apply(substitute_aliases)
15
+ # ignore row if primary subfield is one of the ignored categories
16
+ df = df[~df['primary_subfield'].isin(IGNORE)]
17
 
18
  def preprocess_secondary(s):
19
+ subfields = []
20
+ # split string to list by space
21
+ for subfield in s.split():
22
+ # substitute aliases
23
+ subfield = substitute_aliases(subfield)
24
+ # ignore secondary subfield if one of the ignored categories
25
+ if subfield in IGNORE:
26
+ continue
27
+ subfields.append(subfield)
28
+ # return list of subfields
29
  return subfields
30
 
31
  # Preprocess secondary subfields
32
  df.loc[:, 'secondary_subfield'] = df['secondary_subfield'].apply(preprocess_secondary)
33
+
34
+ # tests
35
+ # assert that each primary subfield is in SUBFIELD_MAP
36
+ assert all(df['primary_subfield'].isin(SUBFIELD_MAP.keys()))
37
+ # assert that each secondary subfield is in SUBFIELD_MAP
38
+ assert all(df['secondary_subfield'].apply(lambda x: all(subfield in SUBFIELD_MAP.keys() for subfield in x)))
39
+ # return preprocessed dataframe
40
  return df