ag2435 commited on
Commit
19a4c0f
·
1 Parent(s): da21b0d

added subfield distributions figures

Browse files
README.md CHANGED
@@ -33,14 +33,16 @@ Old terminology to standardized terminology translation:
33
 
34
  Original data: https://www.dropbox.com/scl/fo/wwu0ifghw4sco09g67frb/h?rlkey=6ddg3yab9la3zeddvmnsfktxq&e=1&dl=0
35
 
36
- Configurations:
37
-
38
  **Minor (default)**: Dataset of papers between 2010 and 2020 (with some pre-2010 papers) with balanced primary subfields.
39
 
40
  **Major**: Dataset of papers between 2010 and 2020 (with some pre-2010 papers) with unbalanced primary subfields to better represent the true distribution of primary categories, which is dominated by a few subfields. Note that the distribution of major subfields is still truncated.
41
 
42
  **All 2023**: All papers published in 2023.
43
 
 
 
 
 
44
  ## Set up dependencies
45
 
46
  Get subfields to ignore and subfield aliases:
 
33
 
34
  Original data: https://www.dropbox.com/scl/fo/wwu0ifghw4sco09g67frb/h?rlkey=6ddg3yab9la3zeddvmnsfktxq&e=1&dl=0
35
 
 
 
36
  **Minor (default)**: Dataset of papers between 2010 and 2020 (with some pre-2010 papers) with balanced primary subfields.
37
 
38
  **Major**: Dataset of papers between 2010 and 2020 (with some pre-2010 papers) with unbalanced primary subfields to better represent the true distribution of primary categories, which is dominated by a few subfields. Note that the distribution of major subfields is still truncated.
39
 
40
  **All 2023**: All papers published in 2023.
41
 
42
+ ![Primary subfield distribution](figures/Primary_subfield_distribution.png)
43
+
44
+ ![Secondary subfield distribution](figures/Secondary_subfield_distribution.png)
45
+
46
  ## Set up dependencies
47
 
48
  Get subfields to ignore and subfield aliases:
figures/Primary_subfield_distribution.png ADDED

Git LFS Details

  • SHA256: 75029a73138f3eeebaccc3635c6e5cdeb928c3c29188c7302d549c3ce62084f2
  • Pointer size: 130 Bytes
  • Size of remote file: 85.1 kB
figures/Secondary_subfield_distribution.png ADDED

Git LFS Details

  • SHA256: 588ea037ccabdc38fe67e898dde2b25e231c7dd11b5c6dffc597bb2325f82a09
  • Pointer size: 130 Bytes
  • Size of remote file: 89.4 kB
plot_subfield_distributions.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Script to plot the distribution of primary and secondary subfields in the minor, major, and all2023 datasets.
2
+ # Usage:
3
+ # python plot_subfield_distributions.py --output_path <path_to_save_plots>
4
+
5
+ from argparse import ArgumentParser
6
+ parser = ArgumentParser()
7
+ # parser.add_argument("--dataset", "-d", type=str, default="minor")
8
+ # parser.add_argument("--split", "-s", type=str, default="val")
9
+ parser.add_argument("--output_path", "-op", type=str, default="./")
10
+ args = parser.parse_args()
11
+ output_path = args.output_path
12
+
13
+ #
14
+ # Remaining imports
15
+ #
16
+ import os
17
+ import plotly.graph_objects as go
18
+ from datasets import load_dataset
19
+ import itertools
20
+
21
+ # Get save path
22
+ save_path = os.path.join(
23
+ output_path,
24
+ 'figures'
25
+ )
26
+ os.makedirs(save_path, exist_ok=True)
27
+ print(f"Saving figures to {save_path}")
28
+
29
+ # Loading dataset and tokenizer as well
30
+ minor_dataset = load_dataset("mlcore/arxiv-classifier")
31
+ major_dataset = load_dataset("mlcore/arxiv-classifier", "major")
32
+ all2023_dataset = load_dataset("mlcore/arxiv-classifier", "all2023")
33
+
34
+ # Extracting the primary and secondary subfield distributions
35
+ datasets = {
36
+ "minor dataset" : minor_dataset['train'],
37
+ "major dataset": major_dataset['train'],
38
+ "all2023 dataset": all2023_dataset['val']
39
+ }
40
+ primary_subfield_distributions = {name: dataset['primary_subfield'] for name, dataset in datasets.items()}
41
+ secondary_subfield_distributions = {
42
+ name: list(itertools.chain(*dataset['secondary_subfield']))
43
+ for name, dataset in datasets.items()
44
+ }
45
+
46
+ # Plotting the two distributions
47
+ hists = []
48
+ n = min([len(i) for i in primary_subfield_distributions.values()])
49
+ for name, primary_subfield_distribution in primary_subfield_distributions.items():
50
+ # primary_subfield_distribution = random.sample(primary_subfield_distribution, n)
51
+ hists.append(go.Histogram(x=primary_subfield_distribution, name=name, opacity=0.75, histnorm='probability'))
52
+
53
+ fig = go.Figure(data=hists)
54
+
55
+ # Update layout for better readability
56
+ fig.update_layout(
57
+ height=700,
58
+ width=1000,
59
+ title="Primary subfield distribution",
60
+ xaxis_title="Primary subfields",
61
+ yaxis_title="Relative frequency",
62
+ bargap=0.2,
63
+ bargroupgap=0.05,
64
+ barmode='overlay',
65
+ legend=dict(
66
+ # x=0.84,
67
+ # y=0.96,
68
+ title='Distributions',
69
+ bgcolor='rgba(255, 255, 255, 0.5)', # Background color with some transparency
70
+ bordercolor='Black',
71
+ borderwidth=1
72
+ )
73
+ )
74
+
75
+ # Show the figure
76
+ # fig.show()
77
+ fig.write_image(os.path.join(save_path,"Primary_subfield_distribution.png"))
78
+
79
+ # Plotting the two distributions
80
+ hists = []
81
+ n = min([len(i) for i in secondary_subfield_distributions.values() if len(i) > 0])
82
+ for name, secondary_subfield_distribution in secondary_subfield_distributions.items():
83
+ # secondary_subfield_distribution = random.sample(secondary_subfield_distribution, min(n, len(secondary_subfield_distribution)))
84
+ hists.append(go.Histogram(x=secondary_subfield_distribution, name=name, opacity=0.75, histnorm='probability'))
85
+
86
+ fig = go.Figure(data=hists)
87
+
88
+ # Update layout for better readability
89
+ fig.update_layout(
90
+ height=700,
91
+ width=1000,
92
+ title="Secondary subfield distribution",
93
+ xaxis_title="Secondary subfields",
94
+ yaxis_title="Relative frequency",
95
+ bargap=0.2,
96
+ bargroupgap=0.05,
97
+ barmode='overlay',
98
+ legend=dict(
99
+ # x=0.84,
100
+ # y=0.96,
101
+ title='Distributions',
102
+ bgcolor='rgba(255, 255, 255, 0.5)', # Background color with some transparency
103
+ bordercolor='Black',
104
+ borderwidth=1
105
+ )
106
+ )
107
+
108
+ # Show the figure
109
+ # fig.show()
110
+ fig.write_image(os.path.join(save_path,"Secondary_subfield_distribution.png"))