File size: 10,059 Bytes
82935d8
4c20fbb
 
cf5eed6
82935d8
4c20fbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82935d8
4c20fbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82935d8
cf5eed6
 
 
 
4c20fbb
 
 
 
cf5eed6
 
4c20fbb
 
cf5eed6
 
 
4c20fbb
 
cf5eed6
 
4c20fbb
 
 
cf5eed6
 
4c20fbb
 
 
 
 
 
cf5eed6
 
4c20fbb
 
 
 
 
cf5eed6
 
4c20fbb
 
 
 
 
cf5eed6
 
82935d8
 
4c20fbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import gradio as gr
import matplotlib.pyplot as plt
import numpy as np
from functools import partial

# ai4code_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/AI4Code")
# amps_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/AMPS")
# apache_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/ASFPublicMail")
# books3_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/Books3")
# cp_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/CPDataset")
# dmmath_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/DMMath")
# discourse_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/Discourse")
# wiki_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/Enwiki")
# euro_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/EuroParliamentProceedings")
# freelaw_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/FreeLaw_Options")
# ghdiffs_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/GitHubDiff")
# ghissues_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/GitHubIssues")
# gutenberg_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/Gutenberg")
# leet_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/LeetCode")
# pileoflaw_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/PileOfLaw")
# pubmed_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/PubMed")
# s2orc_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/S2ORC")
# se_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/StackExchange")
# usenet_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/USENET")
# uspto_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/USPTO")
# ubuntuirc_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/UbuntuIRC")
# arxiv_ds = load_dataset("CarperAI/pile-v2-small", data_dir="data/arXiv")

dataset_data = {
    "AI4Code": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "AMPS": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "ASFPublicMail": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "Books3": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "CPDataset": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "DMMath": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "Discourse": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "Enwiki": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "EuroParliamentProceedings": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "FreeLaw_Options": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "GitHubDiff": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    }, 
    "GitHubIssues": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "Gutenberg": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "LeetCode": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "PileOfLaw": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "PubMed": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "S2ORC": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "StackExchange": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "USENET": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "USPTO": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "UbuntuIRC": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
    "arXiv": {
        # create fake data for the different ratios
        "word_rep_ratios": np.random.randn(1000),
        "char_rep_ratios": np.random.randn(1000),
        "flagged_word_ratios": np.random.randn(1000),
        "num_words": np.random.randint(0, 1000, 1000),
    },
}

def plt_plot(ratio, dataset, threshold):
    x = dataset_data[dataset][ratio]
    # calculate percentage of data that will be removed given threshold
    perc = np.sum(x < threshold) / len(x)
    # create a figure
    fig = plt.figure()
    # add a subplot
    ax = fig.add_subplot(111)
    # plot some data using black
    ax.hist(x, bins=50, color="black")
    # plot red dashed line at threshold
    ax.axvline(threshold, color='r', linestyle='dashed', linewidth=2)
    # set title
    # add percentage of data removed
    ax.set_title(f"{dataset} (removed {perc:.2%})")
    plt.xlabel("Value")
    plt.ylabel("Frequency")
    # make it look nice
    plt.tight_layout()
    return fig

with gr.Blocks() as demo:
    dataset = gr.Radio(list(dataset_data.keys()), label="Dataset", value="arXiv")
    print(dataset.value)

    with gr.Tab("Character Repetition Ratio"):
        # plot some random data
        plot = gr.Plot()
        threshold = gr.Slider(minimum=0, maximum=100, label="Threshold")
        calculate = gr.Button("Calculate")
        plot_fn = partial(plt_plot, "word_rep_ratios")
        calculate.click(plot_fn, [dataset, threshold], plot)
    
    with gr.Tab("Word Repetition Ratio"):# plot some random data
        plot = gr.Plot()
        threshold = gr.Slider(minimum=0, maximum=1, label="Threshold")
        calculate = gr.Button("Calculate")
        plot_fn = partial(plt_plot, "char_rep_ratios")
        calculate.click(plot_fn, [dataset, threshold], plot)
    
    with gr.Tab("Flagged Word Ratio"):# plot some random data
        plot = gr.Plot()
        threshold = gr.Slider(minimum=0, maximum=1, label="Threshold")
        calculate = gr.Button("Calculate")
        plot_fn = partial(plt_plot, "flagged_word_ratios")
        calculate.click(plot_fn, [dataset, threshold], plot)

if __name__ == "__main__":
    demo.launch(share=True)