Elise-hf's picture
Update app.py
074d8a6
import gradio as gr
from sentence_transformers import SentenceTransformer, util
import torch
import pandas as pd
import faiss
import numpy as np
import os
os.environ['CURL_CA_BUNDLE'] = ''
def search_faiss_single(index, inst_embeddings, top_k):
# faiss.normalize_L2(inst_embeddings)
D, I = index.search(inst_embeddings, top_k)
return D, I
def find_similar_papers_tasks_methods(title, abstract, k=100):
# Load the pre-trained model
model = SentenceTransformer("Elise-hf/distilbert-base-pwc-multi-task")
# Load the Faiss indexes and data files
index = faiss.read_index("all_inst_index")
tasks_index = faiss.read_index("tasks_index")
methods_index = faiss.read_index("methods_index")
labels = pd.read_json('lbl_gpt3_davinci_clean_with_counts.json')
methods = pd.read_json('methods.json')
papers = pd.read_json('title_url_clean.json')
tasks_embeddings = np.load('tasks_embeddings.npy')
methods_embeddings = np.load('methods_embeddings.npy')
# Add the title and the abstract together
query = title + '</s>' + abstract
# Encode the query sentence into an embedding
query_embedding = model.encode([query], convert_to_numpy=True)
# Search for the top k most similar papers
D, I = search_faiss_single(index, query_embedding, k)
# Search for the top k most similar tasks
D_tasks, I_tasks = search_faiss_single(tasks_index, query_embedding, k)
norm = np.linalg.norm(tasks_embeddings[I_tasks[0]], axis=1) * np.linalg.norm(query_embedding, axis=1)[:, None]
D_tasks /= norm
# Search for the top k most similar methods
D_methods, I_methods = search_faiss_single(methods_index, query_embedding, k)
norm = np.linalg.norm(methods_embeddings[I_methods[0]], axis=1) * np.linalg.norm(query_embedding, axis=1)[:, None]
D_methods /= norm
# Create a dictionary of the top k similar tasks and their cosine similarities
tasks_results = dict(zip(labels.loc[I_tasks[0]].title, D_tasks[0].tolist()))
# Create a dictionary of the top k similar methods and their cosine similarities
methods_results = dict(zip(methods.loc[I_methods[0]].title, D_methods[0].tolist()))
# Return the dictionaries of the top k similar tasks and methods, and the dataframe of the top k similar papers
return tasks_results, methods_results,papers.loc[I[0]]
# examples =[[r"CascadER: Cross-Modal Cascading for Knowledge Graph Link Prediction",r"Knowledge graph (KG) link prediction is a fundamental task in artificial intelligence, with applications in natural language processing, information retrieval, and biomedicine. Recently, promising results have been achieved by leveraging cross-modal information in KGs, using ensembles that combine knowledge graph embeddings (KGEs) and contextual language models (LMs). However, existing ensembles are either (1) not consistently effective in terms of ranking accuracy gains or (2) impractically inefficient on larger datasets due to the combinatorial explosion problem of pairwise ranking with deep language models. In this paper, we propose a novel tiered ranking architecture CascadER to maintain the ranking accuracy of full ensembling while improving efficiency considerably. CascadER uses LMs to rerank the outputs of more efficient base KGEs, relying on an adaptive subset selection scheme aimed at invoking the LMs minimally while maximizing accuracy gain over the KGE. Extensive experiments demonstrate that CascadER improves MRR by up to 9 points over KGE baselines, setting new state-of-the-art performance on four benchmarks while improving efficiency by one or more orders of magnitude over competitive cross-modal baselines. Our empirical analyses reveal that diversity of models across modalities and preservation of individual models' confidence signals help explain the effectiveness of CascadER, and suggest promising directions for cross-modal cascaded architectures. Code and pretrained models are available at https://github.com/tsafavi/cascader.",100],
# [r"Consistency Models",r"Diffusion models have made significant breakthroughs in image, audio, and video generation, but they depend on an iterative generation process that causes slow sampling speed and caps their potential for real-time applications. To overcome this limitation, we propose consistency models, a new family of generative models that achieve high sample quality without adversarial training. They support fast one-step generation by design, while still allowing for few-step sampling to trade compute for sample quality. They also support zero-shot data editing, like image inpainting, colorization, and super-resolution, without requiring explicit training on these tasks. Consistency models can be trained either as a way to distill pre-trained diffusion models, or as standalone generative models. Through extensive experiments, we demonstrate that they outperform existing distillation techniques for diffusion models in one- and few-step generation. For example, we achieve the new state-of-the-art FID of 3.55 on CIFAR-10 and 6.20 on ImageNet 64x64 for one-step generation. When trained as standalone generative models, consistency models also outperform single-step, non-adversarial generative models on standard benchmarks like CIFAR-10, ImageNet 64x64 and LSUN 256x256."
# ,100],
# [r"Leveraging Pre-trained Checkpoints for Sequence Generation Tasks",r"Unsupervised pre-training of large neural models has recently revolutionized Natural Language Processing. By warm-starting from the publicly released checkpoints, NLP practitioners have pushed the state-of-the-art on multiple benchmarks while saving significant amounts of compute time. So far the focus has been mainly on the Natural Language Understanding tasks. In this paper, we demonstrate the efficacy of pre-trained checkpoints for Sequence Generation. We developed a Transformer-based sequence-to-sequence model that is compatible with publicly available pre-trained BERT, GPT-2 and RoBERTa checkpoints and conducted an extensive empirical study on the utility of initializing our model, both encoder and decoder, with these checkpoints. Our models result in new state-of-the-art results on Machine Translation, Text Summarization, Sentence Splitting, and Sentence Fusion."
# ,100],[r"Increasing Textual Context Size Boosts Medical Image-Text Matching",r"This short technical report demonstrates a simple technique that yields state of the art results in medical image-text matching tasks. We analyze the use of OpenAI's CLIP, a general image-text matching model, and observe that CLIP's limited textual input size has negative impact on downstream performance in the medical domain where encoding longer textual contexts is often required. We thus train and release ClipMD, which is trained with a simple sliding window technique to encode textual captions. ClipMD was tested on two medical image-text datasets and compared with other image-text matching models. The results show that ClipMD outperforms other models on both datasets by a large margin. We make our code and pretrained model publicly available.",100]]
examples =[[r"Increasing Textual Context Size Boosts Medical Image-Text Matching",r"This short technical report demonstrates a simple technique that yields state of the art results in medical image-text matching tasks. We analyze the use of OpenAI's CLIP, a general image-text matching model, and observe that CLIP's limited textual input size has negative impact on downstream performance in the medical domain where encoding longer textual contexts is often required. We thus train and release ClipMD, which is trained with a simple sliding window technique to encode textual captions. ClipMD was tested on two medical image-text datasets and compared with other image-text matching models. The results show that ClipMD outperforms other models on both datasets by a large margin. We make our code and pretrained model publicly available.",100]]
with gr.Blocks() as demo:
with gr.TabItem("Task Search"):
gr.Markdown(
"""
# Identify Relevant Tasks from Abstracts
"""
)
title = gr.components.Textbox(label="Enter an paper's title")
abstract = gr.components.Textbox(label="Enter an abstract to discover relevant tasks from it")
btn = gr.Button("Submit")
with gr.Row():
tasks_table = gr.components.Label(label="Relevant Tasks from PapersWithCode")
methods_table = gr.components.Label(label="Relevant Methods from PapersWithCode")
output_df = gr.Dataframe(
headers=["title", "paper_url"],
datatype=["str", "str"],
row_count=10,
col_count=(2, "fixed"), label="Relevant papers from PapersWithCode"
)
btn.click(fn=find_similar_papers_tasks_methods,
inputs=[title, abstract],
outputs=[tasks_table, methods_table,output_df])
gr.Examples(examples, inputs=[title, abstract], cache_examples=True, fn=find_similar_papers_tasks_methods,
outputs=[tasks_table, methods_table,output_df])
demo.launch()