Spaces:
Running
Running
liujch1998
commited on
Commit
•
26b368d
1
Parent(s):
4641d03
Sync Q6 updates
Browse files- app.py +118 -32
- constants.py +12 -11
app.py
CHANGED
@@ -15,23 +15,53 @@ def process(corpus_desc, query_desc, query):
|
|
15 |
corpus = CORPUS_BY_DESC[corpus_desc]
|
16 |
query_type = QUERY_TYPE_BY_DESC[query_desc]
|
17 |
timestamp = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
|
18 |
-
print(json.dumps({'timestamp': timestamp, 'corpus': corpus, 'query_type': query_type, 'query': query}))
|
19 |
data = {
|
|
|
20 |
'corpus': corpus,
|
21 |
'query_type': query_type,
|
22 |
'query': query,
|
23 |
}
|
|
|
24 |
if API_IPADDR is None:
|
25 |
raise ValueError(f'API_IPADDR envvar is not set!')
|
26 |
response = requests.post(f'http://{API_IPADDR}:5000/', json=data)
|
27 |
if response.status_code == 200:
|
28 |
result = response.json()
|
29 |
else:
|
30 |
-
raise ValueError(f'
|
31 |
if debug:
|
32 |
print(result)
|
33 |
return result
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
with gr.Blocks() as demo:
|
36 |
with gr.Column():
|
37 |
gr.HTML(
|
@@ -88,13 +118,13 @@ with gr.Blocks() as demo:
|
|
88 |
gr.HTML(f'<p style="font-size: 16px;">Note: The (n-1)-gram needs to exist in the corpus. If the (n-1)-gram is not found in the corpus, an error message will appear. If the (n-1)-gram appears more than {MAX_CNT_FOR_NTD} times in the corpus, the result will be approximate.</p>')
|
89 |
with gr.Row():
|
90 |
with gr.Column(scale=1):
|
91 |
-
|
92 |
with gr.Row():
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
with gr.Column(scale=1):
|
97 |
-
|
98 |
|
99 |
with gr.Row(visible=False) as row_4:
|
100 |
with gr.Column():
|
@@ -120,46 +150,98 @@ with gr.Blocks() as demo:
|
|
120 |
gr.HTML('<p style="font-size: 16px;">Example query: <b>I love natural language</b> (the output is P(* | natural language), for the top-10 tokens *)</p>')
|
121 |
with gr.Row():
|
122 |
with gr.Column(scale=1):
|
123 |
-
|
124 |
with gr.Row():
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
with gr.Column(scale=1):
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
-
with gr.Row(visible=False) as
|
133 |
with gr.Column():
|
134 |
-
gr.HTML(f'''<h2>6. Searching for
|
135 |
-
<p style="font-size: 16px;">This displays a random
|
136 |
<p style="font-size: 16px;">Example queries:</p>
|
137 |
<ul style="font-size: 16px;">
|
138 |
<li><b>natural language processing</b> (the displayed document would contain "natural language processing")</li>
|
139 |
<li><b>natural language processing AND deep learning</b> (the displayed document would contain both "natural language processing" and "deep learning")</li>
|
140 |
<li><b>natural language processing OR artificial intelligence AND deep learning OR machine learning</b> (the displayed document would contain at least one of "natural language processing" / "artificial intelligence", and also at least one of "deep learning" / "machine learning")</li>
|
141 |
</ul>
|
142 |
-
<p style="font-size: 16px;">If you want another random
|
143 |
<p style="font-size: 16px;">A few notes:</p>
|
144 |
<ul style="font-size: 16px;">
|
145 |
<li>When you write a query in CNF, note that <b>OR has higher precedence than AND</b> (which is contrary to conventions in boolean algebra).</li>
|
146 |
<li>If the document is too long, it will be truncated to {MAX_OUTPUT_DOC_TOKENS} tokens.</li>
|
147 |
<li>We can only include documents where all terms (or clauses) are separated by no more than {MAX_DIFF_TOKENS} tokens.</li>
|
148 |
-
<li>If you query for two or more clauses, and a clause has more than {MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD} matches (per shard), we will
|
149 |
<li>The number of found documents may contain duplicates (e.g., if a document contains your query term twice, it may be counted twice).</li>
|
150 |
</ul>
|
151 |
<p style="font-size: 16px;">❗️WARNING: Corpus may contain problematic contents such as PII, toxicity, hate speech, and NSFW text. This tool is merely presenting selected text from the corpus, without any post-hoc safety filtering. It is NOT creating new text. This is a research prototype through which we can expose and examine existing problems with massive text corpora. Please use with caution. Don't be evil :)</p>
|
152 |
''')
|
153 |
with gr.Row():
|
154 |
with gr.Column(scale=1):
|
155 |
-
|
|
|
156 |
with gr.Row():
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
with gr.Column(scale=1):
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
with gr.Row(visible=False) as row_7:
|
165 |
with gr.Column():
|
@@ -185,18 +267,20 @@ If you find this tool useful, please kindly cite our paper:
|
|
185 |
|
186 |
count_clear.add([count_input, count_output, count_output_tokens])
|
187 |
ngram_clear.add([ngram_input, ngram_output, ngram_output_tokens])
|
188 |
-
|
189 |
infgram_clear.add([infgram_input, infgram_output, infgram_output_tokens])
|
190 |
-
|
191 |
-
|
|
|
192 |
doc_analysis_clear.add([doc_analysis_input, doc_analysis_output])
|
193 |
|
194 |
count_submit.click(process, inputs=[corpus_desc, query_desc, count_input], outputs=[count_output, count_output_tokens])
|
195 |
ngram_submit.click(process, inputs=[corpus_desc, query_desc, ngram_input], outputs=[ngram_output, ngram_output_tokens])
|
196 |
-
|
197 |
infgram_submit.click(process, inputs=[corpus_desc, query_desc, infgram_input], outputs=[infgram_output, infgram_output_tokens, infgram_longest_suffix])
|
198 |
-
|
199 |
-
|
|
|
200 |
doc_analysis_submit.click(process, inputs=[corpus_desc, query_desc, doc_analysis_input], outputs=[doc_analysis_output])
|
201 |
|
202 |
def update_query_desc(selection):
|
@@ -206,7 +290,8 @@ If you find this tool useful, please kindly cite our paper:
|
|
206 |
row_3: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_next_token_distribution_approx'])),
|
207 |
row_4: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['compute_infgram_prob'])),
|
208 |
row_5: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_infgram_next_token_distribution_approx'])),
|
209 |
-
row_6: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_a_random_document_from_cnf_query_fast_approx'])),
|
|
|
210 |
# row_7: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['analyze_document'])),
|
211 |
}
|
212 |
query_desc.change(fn=update_query_desc, inputs=query_desc, outputs=[
|
@@ -215,7 +300,8 @@ If you find this tool useful, please kindly cite our paper:
|
|
215 |
row_3,
|
216 |
row_4,
|
217 |
row_5,
|
218 |
-
row_6,
|
|
|
219 |
# row_7,
|
220 |
])
|
221 |
|
|
|
15 |
corpus = CORPUS_BY_DESC[corpus_desc]
|
16 |
query_type = QUERY_TYPE_BY_DESC[query_desc]
|
17 |
timestamp = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
|
|
|
18 |
data = {
|
19 |
+
'timestamp': timestamp,
|
20 |
'corpus': corpus,
|
21 |
'query_type': query_type,
|
22 |
'query': query,
|
23 |
}
|
24 |
+
print(json.dumps(data))
|
25 |
if API_IPADDR is None:
|
26 |
raise ValueError(f'API_IPADDR envvar is not set!')
|
27 |
response = requests.post(f'http://{API_IPADDR}:5000/', json=data)
|
28 |
if response.status_code == 200:
|
29 |
result = response.json()
|
30 |
else:
|
31 |
+
raise ValueError(f'HTTP error {response.status_code}: {response.json()}')
|
32 |
if debug:
|
33 |
print(result)
|
34 |
return result
|
35 |
|
36 |
+
def process_ard_cnf_multi(corpus_desc, query_desc, query, maxnum):
|
37 |
+
corpus = CORPUS_BY_DESC[corpus_desc]
|
38 |
+
query_type = QUERY_TYPE_BY_DESC[query_desc]
|
39 |
+
timestamp = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
|
40 |
+
data = {
|
41 |
+
'timestamp': timestamp,
|
42 |
+
'corpus': corpus,
|
43 |
+
'query_type': query_type,
|
44 |
+
'query': query,
|
45 |
+
'maxnum': maxnum,
|
46 |
+
}
|
47 |
+
print(json.dumps(data))
|
48 |
+
if API_IPADDR is None:
|
49 |
+
raise ValueError(f'API_IPADDR envvar is not set!')
|
50 |
+
response = requests.post(f'http://{API_IPADDR}:5000/', json=data)
|
51 |
+
if response.status_code == 200:
|
52 |
+
result = response.json()
|
53 |
+
else:
|
54 |
+
raise ValueError(f'HTTP error {response.status_code}: {response.json()}')
|
55 |
+
if debug:
|
56 |
+
print(result)
|
57 |
+
if len(result) != 3:
|
58 |
+
raise ValueError(f'Invalid result: {result}')
|
59 |
+
outputs, output_tokens, message = result[0], result[1], result[2]
|
60 |
+
outputs = outputs[:maxnum]
|
61 |
+
while len(outputs) < 10:
|
62 |
+
outputs.append([])
|
63 |
+
return output_tokens, message, outputs[0], outputs[1], outputs[2], outputs[3], outputs[4], outputs[5], outputs[6], outputs[7], outputs[8], outputs[9]
|
64 |
+
|
65 |
with gr.Blocks() as demo:
|
66 |
with gr.Column():
|
67 |
gr.HTML(
|
|
|
118 |
gr.HTML(f'<p style="font-size: 16px;">Note: The (n-1)-gram needs to exist in the corpus. If the (n-1)-gram is not found in the corpus, an error message will appear. If the (n-1)-gram appears more than {MAX_CNT_FOR_NTD} times in the corpus, the result will be approximate.</p>')
|
119 |
with gr.Row():
|
120 |
with gr.Column(scale=1):
|
121 |
+
ntd_input = gr.Textbox(placeholder='Enter a string (an (n-1)-gram) here', label='Query', interactive=True)
|
122 |
with gr.Row():
|
123 |
+
ntd_clear = gr.ClearButton(value='Clear', variant='secondary', visible=True)
|
124 |
+
ntd_submit = gr.Button(value='Submit', variant='primary', visible=True)
|
125 |
+
ntd_output_tokens = gr.Textbox(label='Tokenized', lines=2, interactive=False)
|
126 |
with gr.Column(scale=1):
|
127 |
+
ntd_output = gr.Label(label='Distribution', num_top_classes=10)
|
128 |
|
129 |
with gr.Row(visible=False) as row_4:
|
130 |
with gr.Column():
|
|
|
150 |
gr.HTML('<p style="font-size: 16px;">Example query: <b>I love natural language</b> (the output is P(* | natural language), for the top-10 tokens *)</p>')
|
151 |
with gr.Row():
|
152 |
with gr.Column(scale=1):
|
153 |
+
infntd_input = gr.Textbox(placeholder='Enter a string here', label='Query', interactive=True)
|
154 |
with gr.Row():
|
155 |
+
infntd_clear = gr.ClearButton(value='Clear', variant='secondary', visible=True)
|
156 |
+
infntd_submit = gr.Button(value='Submit', variant='primary', visible=True)
|
157 |
+
infntd_output_tokens = gr.Textbox(label='Tokenized', lines=2, interactive=False)
|
158 |
+
infntd_longest_suffix = gr.Textbox(label='Longest Found Suffix', interactive=False)
|
159 |
with gr.Column(scale=1):
|
160 |
+
infntd_output = gr.Label(label='Distribution', num_top_classes=10)
|
161 |
+
|
162 |
+
# with gr.Row(visible=False) as row_6:
|
163 |
+
# with gr.Column():
|
164 |
+
# gr.HTML(f'''<h2>6. Searching for document containing n-gram(s)</h2>
|
165 |
+
# <p style="font-size: 16px;">This displays a random document in the corpus that satisfies your query. You can simply enter an n-gram, in which case the document displayed would contain your n-gram. You can also connect multiple n-gram terms with the AND/OR operators, in the <a href="https://en.wikipedia.org/wiki/Conjunctive_normal_form">CNF format</a>, in which case the displayed document contains n-grams such that it satisfies this logical constraint.</p>
|
166 |
+
# <p style="font-size: 16px;">Example queries:</p>
|
167 |
+
# <ul style="font-size: 16px;">
|
168 |
+
# <li><b>natural language processing</b> (the displayed document would contain "natural language processing")</li>
|
169 |
+
# <li><b>natural language processing AND deep learning</b> (the displayed document would contain both "natural language processing" and "deep learning")</li>
|
170 |
+
# <li><b>natural language processing OR artificial intelligence AND deep learning OR machine learning</b> (the displayed document would contain at least one of "natural language processing" / "artificial intelligence", and also at least one of "deep learning" / "machine learning")</li>
|
171 |
+
# </ul>
|
172 |
+
# <p style="font-size: 16px;">If you want another random document, simply hit the Submit button again :)</p>
|
173 |
+
# <p style="font-size: 16px;">A few notes:</p>
|
174 |
+
# <ul style="font-size: 16px;">
|
175 |
+
# <li>When you write a query in CNF, note that <b>OR has higher precedence than AND</b> (which is contrary to conventions in boolean algebra).</li>
|
176 |
+
# <li>If the document is too long, it will be truncated to {MAX_OUTPUT_DOC_TOKENS} tokens.</li>
|
177 |
+
# <li>We can only include documents where all terms (or clauses) are separated by no more than {MAX_DIFF_TOKENS} tokens.</li>
|
178 |
+
# <li>If you query for two or more clauses, and a clause has more than {MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD} matches (per shard), we will estimate the count from a random subset of all documents containing that clause. This might cause a zero count on conjuction of some simple n-grams (e.g., <b>birds AND oil</b>).</li>
|
179 |
+
# <li>The number of found documents may contain duplicates (e.g., if a document contains your query term twice, it may be counted twice).</li>
|
180 |
+
# </ul>
|
181 |
+
# <p style="font-size: 16px;">❗️WARNING: Corpus may contain problematic contents such as PII, toxicity, hate speech, and NSFW text. This tool is merely presenting selected text from the corpus, without any post-hoc safety filtering. It is NOT creating new text. This is a research prototype through which we can expose and examine existing problems with massive text corpora. Please use with caution. Don't be evil :)</p>
|
182 |
+
# ''')
|
183 |
+
# with gr.Row():
|
184 |
+
# with gr.Column(scale=1):
|
185 |
+
# ard_cnf_input = gr.Textbox(placeholder='Enter a query here', label='Query', interactive=True)
|
186 |
+
# with gr.Row():
|
187 |
+
# ard_cnf_clear = gr.ClearButton(value='Clear', variant='secondary', visible=True)
|
188 |
+
# ard_cnf_submit = gr.Button(value='Submit', variant='primary', visible=True)
|
189 |
+
# ard_cnf_output_tokens = gr.Textbox(label='Tokenized', lines=2, interactive=False)
|
190 |
+
# with gr.Column(scale=1):
|
191 |
+
# ard_cnf_output_message = gr.Label(label='Message', num_top_classes=0)
|
192 |
+
# ard_cnf_output = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
193 |
|
194 |
+
with gr.Row(visible=False) as row_6a:
|
195 |
with gr.Column():
|
196 |
+
gr.HTML(f'''<h2>6. Searching for documents containing n-gram(s)</h2>
|
197 |
+
<p style="font-size: 16px;">This displays a few random documents in the corpus that satisfies your query. You can simply enter an n-gram, in which case the document displayed would contain your n-gram. You can also connect multiple n-gram terms with the AND/OR operators, in the <a href="https://en.wikipedia.org/wiki/Conjunctive_normal_form">CNF format</a>, in which case the displayed document contains n-grams such that it satisfies this logical constraint.</p>
|
198 |
<p style="font-size: 16px;">Example queries:</p>
|
199 |
<ul style="font-size: 16px;">
|
200 |
<li><b>natural language processing</b> (the displayed document would contain "natural language processing")</li>
|
201 |
<li><b>natural language processing AND deep learning</b> (the displayed document would contain both "natural language processing" and "deep learning")</li>
|
202 |
<li><b>natural language processing OR artificial intelligence AND deep learning OR machine learning</b> (the displayed document would contain at least one of "natural language processing" / "artificial intelligence", and also at least one of "deep learning" / "machine learning")</li>
|
203 |
</ul>
|
204 |
+
<p style="font-size: 16px;">If you want another batch of random documents, simply hit the Submit button again :)</p>
|
205 |
<p style="font-size: 16px;">A few notes:</p>
|
206 |
<ul style="font-size: 16px;">
|
207 |
<li>When you write a query in CNF, note that <b>OR has higher precedence than AND</b> (which is contrary to conventions in boolean algebra).</li>
|
208 |
<li>If the document is too long, it will be truncated to {MAX_OUTPUT_DOC_TOKENS} tokens.</li>
|
209 |
<li>We can only include documents where all terms (or clauses) are separated by no more than {MAX_DIFF_TOKENS} tokens.</li>
|
210 |
+
<li>If you query for two or more clauses, and a clause has more than {MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD} matches (per shard), we will estimate the count from a random subset of all documents containing that clause. This might cause a zero count on conjuction of some simple n-grams (e.g., <b>birds AND oil</b>).</li>
|
211 |
<li>The number of found documents may contain duplicates (e.g., if a document contains your query term twice, it may be counted twice).</li>
|
212 |
</ul>
|
213 |
<p style="font-size: 16px;">❗️WARNING: Corpus may contain problematic contents such as PII, toxicity, hate speech, and NSFW text. This tool is merely presenting selected text from the corpus, without any post-hoc safety filtering. It is NOT creating new text. This is a research prototype through which we can expose and examine existing problems with massive text corpora. Please use with caution. Don't be evil :)</p>
|
214 |
''')
|
215 |
with gr.Row():
|
216 |
with gr.Column(scale=1):
|
217 |
+
ard_cnf_multi_input = gr.Textbox(placeholder='Enter a query here', label='Query', interactive=True)
|
218 |
+
ard_cnf_multi_maxnum = gr.Slider(minimum=1, maximum=10, value=1, step=1, label='Number of documents to Display')
|
219 |
with gr.Row():
|
220 |
+
ard_cnf_multi_clear = gr.ClearButton(value='Clear', variant='secondary', visible=True)
|
221 |
+
ard_cnf_multi_submit = gr.Button(value='Submit', variant='primary', visible=True)
|
222 |
+
ard_cnf_multi_output_tokens = gr.Textbox(label='Tokenized', lines=2, interactive=False)
|
223 |
with gr.Column(scale=1):
|
224 |
+
ard_cnf_multi_output_message = gr.Label(label='Message', num_top_classes=0)
|
225 |
+
with gr.Tab(label='1'):
|
226 |
+
ard_cnf_multi_output_0 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
227 |
+
with gr.Tab(label='2'):
|
228 |
+
ard_cnf_multi_output_1 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
229 |
+
with gr.Tab(label='3'):
|
230 |
+
ard_cnf_multi_output_2 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
231 |
+
with gr.Tab(label='4'):
|
232 |
+
ard_cnf_multi_output_3 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
233 |
+
with gr.Tab(label='5'):
|
234 |
+
ard_cnf_multi_output_4 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
235 |
+
with gr.Tab(label='6'):
|
236 |
+
ard_cnf_multi_output_5 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
237 |
+
with gr.Tab(label='7'):
|
238 |
+
ard_cnf_multi_output_6 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
239 |
+
with gr.Tab(label='8'):
|
240 |
+
ard_cnf_multi_output_7 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
241 |
+
with gr.Tab(label='9'):
|
242 |
+
ard_cnf_multi_output_8 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
243 |
+
with gr.Tab(label='10'):
|
244 |
+
ard_cnf_multi_output_9 = gr.HighlightedText(label='Document', show_legend=False, color_map={"-": "red", "0": "green", "1": "cyan", "2": "blue", "3": "magenta"})
|
245 |
|
246 |
with gr.Row(visible=False) as row_7:
|
247 |
with gr.Column():
|
|
|
267 |
|
268 |
count_clear.add([count_input, count_output, count_output_tokens])
|
269 |
ngram_clear.add([ngram_input, ngram_output, ngram_output_tokens])
|
270 |
+
ntd_clear.add([ntd_input, ntd_output, ntd_output_tokens])
|
271 |
infgram_clear.add([infgram_input, infgram_output, infgram_output_tokens])
|
272 |
+
infntd_clear.add([infntd_input, infntd_output, infntd_output_tokens, infntd_longest_suffix])
|
273 |
+
# ard_cnf_clear.add([ard_cnf_input, ard_cnf_output, ard_cnf_output_tokens, ard_cnf_output_message])
|
274 |
+
ard_cnf_multi_clear.add([ard_cnf_multi_input, ard_cnf_multi_output_tokens, ard_cnf_multi_output_message, ard_cnf_multi_output_0, ard_cnf_multi_output_1, ard_cnf_multi_output_2, ard_cnf_multi_output_3, ard_cnf_multi_output_4, ard_cnf_multi_output_5, ard_cnf_multi_output_6, ard_cnf_multi_output_7, ard_cnf_multi_output_8, ard_cnf_multi_output_9])
|
275 |
doc_analysis_clear.add([doc_analysis_input, doc_analysis_output])
|
276 |
|
277 |
count_submit.click(process, inputs=[corpus_desc, query_desc, count_input], outputs=[count_output, count_output_tokens])
|
278 |
ngram_submit.click(process, inputs=[corpus_desc, query_desc, ngram_input], outputs=[ngram_output, ngram_output_tokens])
|
279 |
+
ntd_submit.click(process, inputs=[corpus_desc, query_desc, ntd_input], outputs=[ntd_output, ntd_output_tokens])
|
280 |
infgram_submit.click(process, inputs=[corpus_desc, query_desc, infgram_input], outputs=[infgram_output, infgram_output_tokens, infgram_longest_suffix])
|
281 |
+
infntd_submit.click(process, inputs=[corpus_desc, query_desc, infntd_input], outputs=[infntd_output, infntd_output_tokens, infntd_longest_suffix])
|
282 |
+
# ard_cnf_submit.click(process, inputs=[corpus_desc, query_desc, ard_cnf_input], outputs=[ard_cnf_output, ard_cnf_output_tokens, ard_cnf_output_message])
|
283 |
+
ard_cnf_multi_submit.click(process_ard_cnf_multi, inputs=[corpus_desc, query_desc, ard_cnf_multi_input, ard_cnf_multi_maxnum], outputs=[ard_cnf_multi_output_tokens, ard_cnf_multi_output_message, ard_cnf_multi_output_0, ard_cnf_multi_output_1, ard_cnf_multi_output_2, ard_cnf_multi_output_3, ard_cnf_multi_output_4, ard_cnf_multi_output_5, ard_cnf_multi_output_6, ard_cnf_multi_output_7, ard_cnf_multi_output_8, ard_cnf_multi_output_9])
|
284 |
doc_analysis_submit.click(process, inputs=[corpus_desc, query_desc, doc_analysis_input], outputs=[doc_analysis_output])
|
285 |
|
286 |
def update_query_desc(selection):
|
|
|
290 |
row_3: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_next_token_distribution_approx'])),
|
291 |
row_4: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['compute_infgram_prob'])),
|
292 |
row_5: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_infgram_next_token_distribution_approx'])),
|
293 |
+
# row_6: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_a_random_document_from_cnf_query_fast_approx'])),
|
294 |
+
row_6a: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['get_random_documents_from_cnf_query_fast_approx'])),
|
295 |
# row_7: gr.Row(visible=(selection == QUERY_DESC_BY_TYPE['analyze_document'])),
|
296 |
}
|
297 |
query_desc.change(fn=update_query_desc, inputs=query_desc, outputs=[
|
|
|
300 |
row_3,
|
301 |
row_4,
|
302 |
row_5,
|
303 |
+
# row_6,
|
304 |
+
row_6a,
|
305 |
# row_7,
|
306 |
])
|
307 |
|
constants.py
CHANGED
@@ -12,20 +12,21 @@ QUERY_TYPE_BY_DESC = {
|
|
12 |
'3. Compute the next-token distribution of an (n-1)-gram': 'get_next_token_distribution_approx',
|
13 |
'4. Compute the ∞-gram probability of the last token': 'compute_infgram_prob',
|
14 |
'5. Compute the ∞-gram next-token distribution': 'get_infgram_next_token_distribution_approx',
|
15 |
-
'6. Searching for document containing n-gram(s)': 'get_a_random_document_from_cnf_query_fast_approx',
|
|
|
16 |
# '7. Analyze an (AI-generated) document using ∞-gram': 'analyze_document',
|
17 |
}
|
18 |
QUERY_DESC_BY_TYPE = {v: k for k, v in QUERY_TYPE_BY_DESC.items()}
|
19 |
QUERY_DESCS = list(QUERY_TYPE_BY_DESC.keys())
|
20 |
|
21 |
-
MAX_QUERY_CHARS = os.environ.get('MAX_QUERY_CHARS', 1000)
|
22 |
-
MAX_INPUT_DOC_TOKENS = os.environ.get('MAX_INPUT_DOC_TOKENS', 1000)
|
23 |
-
MAX_OUTPUT_DOC_TOKENS = os.environ.get('MAX_OUTPUT_DOC_TOKENS', 5000)
|
24 |
-
MAX_CNT_FOR_NTD = os.environ.get('MAX_CNT_FOR_NTD', 1000)
|
25 |
-
MAX_CLAUSE_FREQ = os.environ.get('MAX_CLAUSE_FREQ', 10000)
|
26 |
-
MAX_CLAUSE_FREQ_FAST = os.environ.get('MAX_CLAUSE_FREQ_FAST', 1000000)
|
27 |
-
MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD = os.environ.get('MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD', 50000)
|
28 |
-
MAX_DIFF_TOKENS = os.environ.get('MAX_DIFF_TOKENS', 100)
|
29 |
MAX_DIFF_BYTES = 2 * MAX_DIFF_TOKENS
|
30 |
-
MAX_CLAUSES_IN_CNF = os.environ.get('MAX_CLAUSES_IN_CNF', 4)
|
31 |
-
MAX_TERMS_IN_DISJ_CLAUSE = os.environ.get('MAX_TERMS_IN_DISJ_CLAUSE', 4)
|
|
|
12 |
'3. Compute the next-token distribution of an (n-1)-gram': 'get_next_token_distribution_approx',
|
13 |
'4. Compute the ∞-gram probability of the last token': 'compute_infgram_prob',
|
14 |
'5. Compute the ∞-gram next-token distribution': 'get_infgram_next_token_distribution_approx',
|
15 |
+
# '6. Searching for document containing n-gram(s)': 'get_a_random_document_from_cnf_query_fast_approx',
|
16 |
+
'6. Searching for documents containing n-gram(s)': 'get_random_documents_from_cnf_query_fast_approx',
|
17 |
# '7. Analyze an (AI-generated) document using ∞-gram': 'analyze_document',
|
18 |
}
|
19 |
QUERY_DESC_BY_TYPE = {v: k for k, v in QUERY_TYPE_BY_DESC.items()}
|
20 |
QUERY_DESCS = list(QUERY_TYPE_BY_DESC.keys())
|
21 |
|
22 |
+
MAX_QUERY_CHARS = int(os.environ.get('MAX_QUERY_CHARS', 1000))
|
23 |
+
MAX_INPUT_DOC_TOKENS = int(os.environ.get('MAX_INPUT_DOC_TOKENS', 1000))
|
24 |
+
MAX_OUTPUT_DOC_TOKENS = int(os.environ.get('MAX_OUTPUT_DOC_TOKENS', 5000))
|
25 |
+
MAX_CNT_FOR_NTD = int(os.environ.get('MAX_CNT_FOR_NTD', 1000))
|
26 |
+
MAX_CLAUSE_FREQ = int(os.environ.get('MAX_CLAUSE_FREQ', 10000))
|
27 |
+
MAX_CLAUSE_FREQ_FAST = int(os.environ.get('MAX_CLAUSE_FREQ_FAST', 1000000))
|
28 |
+
MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD = int(os.environ.get('MAX_CLAUSE_FREQ_FAST_APPROX_PER_SHARD', 50000))
|
29 |
+
MAX_DIFF_TOKENS = int(os.environ.get('MAX_DIFF_TOKENS', 100))
|
30 |
MAX_DIFF_BYTES = 2 * MAX_DIFF_TOKENS
|
31 |
+
MAX_CLAUSES_IN_CNF = int(os.environ.get('MAX_CLAUSES_IN_CNF', 4))
|
32 |
+
MAX_TERMS_IN_DISJ_CLAUSE = int(os.environ.get('MAX_TERMS_IN_DISJ_CLAUSE', 4))
|