Spaces:
Runtime error
Runtime error
Commit
·
3bfefbb
1
Parent(s):
d996a74
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ def mean_pooling(model_output, attention_mask):
|
|
42 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
43 |
return tf.reduce_sum(token_embeddings * input_mask_expanded, 1) / tf.clip_by_value(input_mask_expanded.sum(1), clip_value_min=1e-9, clip_value_max=math.inf)
|
44 |
|
45 |
-
def broad_scope_class_predictor(class_embeddings, abstract_embedding, N=5, Sensitivity='Medium'):
|
46 |
predictions = pd.DataFrame(columns=['Class Name', 'Score'])
|
47 |
for i in range(len(class_embeddings)):
|
48 |
class_name = class_embeddings.iloc[i, 0]
|
@@ -62,6 +62,13 @@ def broad_scope_class_predictor(class_embeddings, abstract_embedding, N=5, Sensi
|
|
62 |
Threshold = 0.35
|
63 |
GreenLikelihood = 'False'
|
64 |
HighestSimilarity = predictions.nlargest(N, ['Score'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
return HighestSimilarity
|
66 |
|
67 |
|
@@ -89,7 +96,7 @@ def convert_saved_embeddings(embedding_string):
|
|
89 |
Preparing pre-computed embeddings for use for comparison with new abstract embeddings .
|
90 |
Pre-computed embeddings are saved as tensors in string format so need to be converted back to numpy arrays in order to calculate cosine similarity.
|
91 |
:param embedding_string:
|
92 |
-
:return: Should be a single tensor with dims (,384) in string
|
93 |
"""
|
94 |
embedding = embedding_string.replace('(', '')
|
95 |
embedding = embedding.replace(')', '')
|
@@ -322,7 +329,7 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
|
|
322 |
gr.Markdown("""
|
323 |
Use this tool to expand your idea into the technical language of a patent claim. You can specify the type of claim you want using the dropdown menu.
|
324 |
""")
|
325 |
-
|
326 |
|
327 |
with gr.Row(scale=1, min_width=600):
|
328 |
text1 = gr.Textbox(label="Input",
|
@@ -330,13 +337,13 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
|
|
330 |
text2 = gr.Textbox(label="Output")
|
331 |
with gr.Row():
|
332 |
btn = gr.Button("submit")
|
333 |
-
btn.click(fn=claim_selector, inputs=[text1,
|
334 |
|
335 |
with gr.Tab("Description Generator"):
|
336 |
gr.Markdown("""
|
337 |
Use this tool to expand your patent claim into a description. You can also use this tool to generate abstracts and give you ideas about the benefit of an invention by changing the settings in the dropdown menu.
|
338 |
""")
|
339 |
-
gr.Dropdown(["Generate Description", "Generate Abstract", "Benefits of the invention"], label='Choose Generation Type Here')
|
340 |
with gr.Row(scale=1, min_width=600):
|
341 |
|
342 |
text1 = gr.Textbox(label="Input",
|
@@ -344,7 +351,7 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
|
|
344 |
text2 = gr.Textbox(label="Output")
|
345 |
with gr.Row():
|
346 |
btn = gr.Button("submit")
|
347 |
-
btn.click(fn=desc_selector, inputs=[text1,
|
348 |
|
349 |
# with gr.Tab("Knowledge Graph"):
|
350 |
# gr.Markdown("""
|
@@ -385,14 +392,14 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
|
|
385 |
Click on the link to initiate either an Espacenet or Google Patents classification search using the generated classifications. You can specify which you would like using the dropdown menu.
|
386 |
""")
|
387 |
|
388 |
-
gr.Dropdown(["Google Patent Search", "Espacenet Patent Search"], label='Choose Search Type Here')
|
389 |
with gr.Row(scale=1, min_width=600):
|
390 |
userin = gr.Textbox(label="Input",
|
391 |
placeholder='Type in your Claim/Description/Abstract Here')
|
392 |
output = gr.Textbox(label="Output")
|
393 |
with gr.Row():
|
394 |
classify_btn = gr.Button("Classify")
|
395 |
-
classify_btn.click(fn=classifier, inputs=[userin] , outputs=output)
|
396 |
|
397 |
|
398 |
gr.Markdown("""
|
|
|
42 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
43 |
return tf.reduce_sum(token_embeddings * input_mask_expanded, 1) / tf.clip_by_value(input_mask_expanded.sum(1), clip_value_min=1e-9, clip_value_max=math.inf)
|
44 |
|
45 |
+
def broad_scope_class_predictor(class_embeddings, abstract_embedding, SearchType, N=5, Sensitivity='Medium'):
|
46 |
predictions = pd.DataFrame(columns=['Class Name', 'Score'])
|
47 |
for i in range(len(class_embeddings)):
|
48 |
class_name = class_embeddings.iloc[i, 0]
|
|
|
62 |
Threshold = 0.35
|
63 |
GreenLikelihood = 'False'
|
64 |
HighestSimilarity = predictions.nlargest(N, ['Score'])
|
65 |
+
HighestSimilarity = HighestSimilarity['Class Name'].tolist()
|
66 |
+
HighestSimilarityClass = [x.split('/')[0] for x in HighestSimilarity]
|
67 |
+
if SearchType == 'Google Patent Search':
|
68 |
+
Links = [f'https://patents.google.com/?q=({x}%2f00)&oq={x}%2f00' for x in HighestSimilarityClass]
|
69 |
+
elif SearchType == 'Espacenet Patent Search':
|
70 |
+
Links = [f'https://worldwide.espacenet.com/patent/search?q=cpc%3D{x}%2F00%2Flow' for x in HighestSimilarityClass]
|
71 |
+
HighestSimilarity = pd.DataFrame({'Class':HighestSimilarity, 'Link':Links})
|
72 |
return HighestSimilarity
|
73 |
|
74 |
|
|
|
96 |
Preparing pre-computed embeddings for use for comparison with new abstract embeddings .
|
97 |
Pre-computed embeddings are saved as tensors in string format so need to be converted back to numpy arrays in order to calculate cosine similarity.
|
98 |
:param embedding_string:
|
99 |
+
:return: Should be a single tensor with dims (,384) in string format
|
100 |
"""
|
101 |
embedding = embedding_string.replace('(', '')
|
102 |
embedding = embedding.replace(')', '')
|
|
|
329 |
gr.Markdown("""
|
330 |
Use this tool to expand your idea into the technical language of a patent claim. You can specify the type of claim you want using the dropdown menu.
|
331 |
""")
|
332 |
+
Claimchoices = gr.Dropdown(["Apparatus Claim", "Method of Use Claim", "Method Claim", ], label='Choose Claim Type Here')
|
333 |
|
334 |
with gr.Row(scale=1, min_width=600):
|
335 |
text1 = gr.Textbox(label="Input",
|
|
|
337 |
text2 = gr.Textbox(label="Output")
|
338 |
with gr.Row():
|
339 |
btn = gr.Button("submit")
|
340 |
+
btn.click(fn=claim_selector, inputs=[text1, Claimchoices]).then(run_model, inputs=[text1, Claimchoices], outputs=text2)
|
341 |
|
342 |
with gr.Tab("Description Generator"):
|
343 |
gr.Markdown("""
|
344 |
Use this tool to expand your patent claim into a description. You can also use this tool to generate abstracts and give you ideas about the benefit of an invention by changing the settings in the dropdown menu.
|
345 |
""")
|
346 |
+
Descriptionchoices = gr.Dropdown(["Generate Description", "Generate Abstract", "Benefits of the invention"], label='Choose Generation Type Here')
|
347 |
with gr.Row(scale=1, min_width=600):
|
348 |
|
349 |
text1 = gr.Textbox(label="Input",
|
|
|
351 |
text2 = gr.Textbox(label="Output")
|
352 |
with gr.Row():
|
353 |
btn = gr.Button("submit")
|
354 |
+
btn.click(fn=desc_selector, inputs=[text1, Descriptionchoices]).then(run_model, inputs=[text1, Descriptionchoices], outputs=text2)
|
355 |
|
356 |
# with gr.Tab("Knowledge Graph"):
|
357 |
# gr.Markdown("""
|
|
|
392 |
Click on the link to initiate either an Espacenet or Google Patents classification search using the generated classifications. You can specify which you would like using the dropdown menu.
|
393 |
""")
|
394 |
|
395 |
+
ClassifyChoices = gr.Dropdown(["Google Patent Search", "Espacenet Patent Search"], label='Choose Search Type Here')
|
396 |
with gr.Row(scale=1, min_width=600):
|
397 |
userin = gr.Textbox(label="Input",
|
398 |
placeholder='Type in your Claim/Description/Abstract Here')
|
399 |
output = gr.Textbox(label="Output")
|
400 |
with gr.Row():
|
401 |
classify_btn = gr.Button("Classify")
|
402 |
+
classify_btn.click(fn=classifier, inputs=[userin, ClassifyChoices] , outputs=output)
|
403 |
|
404 |
|
405 |
gr.Markdown("""
|