Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from sentence_transformers import SentenceTransformer, util, CrossEncoder
|
2 |
from datasets import load_dataset
|
3 |
import pandas as pd
|
4 |
-
from IPython.display import display
|
5 |
|
6 |
#Get the netflix dataset
|
7 |
netflix = load_dataset('hugginglearners/netflix-shows',use_auth_token=True)
|
@@ -20,6 +19,15 @@ dataset_embeddings = torch.from_numpy(flix_ds["train"].to_pandas().to_numpy()).t
|
|
20 |
#load cross-encoder for reranking
|
21 |
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
#function for generating similarity of query and netflix shows
|
24 |
def semantic_search(query,embeddings,top_k=top_k):
|
25 |
'''Encode query and check similarity with embeddings'''
|
|
|
1 |
from sentence_transformers import SentenceTransformer, util, CrossEncoder
|
2 |
from datasets import load_dataset
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
#Get the netflix dataset
|
6 |
netflix = load_dataset('hugginglearners/netflix-shows',use_auth_token=True)
|
|
|
19 |
#load cross-encoder for reranking
|
20 |
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
|
21 |
|
22 |
+
def display_df_as_table(model,top_k,score='score'):
|
23 |
+
# Display the df with text and scores as a table
|
24 |
+
df = pd.DataFrame([(hit[score],passages[hit['corpus_id']]) for hit in model[0:top_k]],columns=['Score','Text'])
|
25 |
+
df['Score'] = round(df['Score'],2)
|
26 |
+
df = df.merge(netflix_df,how='inner',left_on='Text',right_on='description')
|
27 |
+
df.drop('Text',inplace=True,axis=1)
|
28 |
+
|
29 |
+
return df
|
30 |
+
|
31 |
#function for generating similarity of query and netflix shows
|
32 |
def semantic_search(query,embeddings,top_k=top_k):
|
33 |
'''Encode query and check similarity with embeddings'''
|