File size: 1,905 Bytes
b1709c2
44b6718
 
b1709c2
 
 
6afa13b
 
 
 
 
 
44b6718
 
684f6cd
 
44b6718
684f6cd
44b6718
b1709c2
 
 
 
 
 
 
 
6afa13b
 
b1709c2
 
6afa13b
 
 
b1709c2
 
6afa13b
 
 
b1709c2
 
6afa13b
 
 
 
 
 
 
 
 
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
import gradio as gr
from arxiv_tool.core import SentenceEncoder
from arxiv_tool.plot import EmbeddingPlotter

TITLE = "Search tool for ArXiv papers"
DESCRIPTION = "<center>Find your most beloved ArXiv papers!</center>"
EXAMPLES = [
    "RoBERTa optimisation",
    "Permutation invariant AI models",
    "Gradient descent",
    "Black hole information theory",
]
ARTICLE = r"""<center>
              This application uses Sentence-BERT embeddings.
              Sentence Embedding is achieved via Siamese BERT-Networks from  <a href=https://arxiv.org/abs/1908.10084>this paper</a> <br>
              After embedding, encoded papers are projected into the unit sphere and a nearest neighbours search is done to extract best matching results.<br>
              Done by dr. Gabriel Lopez<br> 
              For more please visit: <a href='https://sites.google.com/view/dr-gabriel-lopez/home'>My Page</a><br>
              </center>"""

# interface function
def search_and_plot(querry):
    # search
    df, model, embeddings = SentenceEncoder().load_and_encode()
    df, result = SentenceEncoder().transform(df, querry, model, embeddings)
    # plot
    fig1, fig2 = EmbeddingPlotter().transform(df, embeddings)
    return result[["title", "similarity"]], fig1, fig2


# gradio elements
in_textbox = gr.Textbox(
    label="Search on ArXiv:", placeholder="what do you want to learn today?...", lines=1
)
out_dataframe = gr.DataFrame(label="Most similar papers on ArXiv:")
out_plot_sphere = gr.Plot(label="Embedding projection over a unit sphere")
out_plot_projected_sphere = gr.Plot(
    label="Lambert-conformal projection over a plane", visible=False
)

# launch interface
gr.Interface(
    inputs=in_textbox,
    outputs=[out_dataframe, out_plot_sphere, out_plot_projected_sphere],
    examples=EXAMPLES,
    fn=search_and_plot,
    title=TITLE,
    description=DESCRIPTION,
    article=ARTICLE,
).launch()