paper-rec / app.py
bluebalam's picture
remove share=True
b4a2d50
import gradio as gr
import torch
from paper_rec import recommender, etl
from gradio.inputs import Textbox
def recommend(txt):
if len(txt.strip()) <= 0:
return {"msg": "no recommendations available for the input text."}
top_n = 10
# model user preferences:
cleaned_txt = etl.clean_text(txt)
sentences = etl.get_sentences_from_txt(txt)
rec = recommender.Recommender()
# loading data and model from HF
rec.load_data()
rec.load_model()
# compute user embedding
user_embedding = torch.from_numpy(rec.embedding(sentences))
# get recommendations based on user preferences
recs = rec.recommend(user_embedding, top_k=100)
# deduplicate
recs_output = []
seen_paper = set()
for p in recs:
if p["id"] not in seen_paper:
recs_output.append({"id": p["id"],
"title": p["title"],
"abstract": p["authors"],
"abstract": p["abstract"]
})
seen_paper.add(p["id"])
if len(recs_output) >= top_n:
break
# report top-n
return recs_output
title = "Interactive demo: paper-rec"
description = """What paper in ML/AI should I read next? It is difficult to choose from all great research publications
published daily. This demo gives you a personalized selection of papers from the latest scientific contributions
available in arXiv – https://arxiv.org/.
You just input the title or abstract (or both) of paper(s) you liked in the past or you can also use keywords of topics
of interest and get the top-10 article recommendations tailored to your taste.
Enjoy!"""
examples = ["""Attention Is All You Need – The dominant sequence transduction models are based on complex recurrent or
convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder
and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely
on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation
tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time
to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing
best results, including ensembles by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model
establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small
fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to
other tasks by applying it successfully to English constituency parsing both with large and limited training data.""",
"GANs, Diffusion Models, Art"]
iface = gr.Interface(fn=recommend,
inputs=[Textbox(lines=10, placeholder="Titles and abstracts from papers you like", default="",
label="""Sample of what I like: title(s) or abstract(s) of papers you love or a set
of keywords about your interests (e.g., Transformers, GANs, Recommender Systems):
""")],
outputs="json",
layout='vertical',
title=title,
description=description,
examples=examples
)
iface.launch()