Spaces:
Build error
Build error
Abhay Mishra
commited on
Commit
·
8cca354
1
Parent(s):
63b413a
add initial implementation
Browse files- .gitignore +3 -0
- app.py +26 -0
- dep_course_title_to_content_embed.pickle +3 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
venv/
|
2 |
+
flagged/
|
3 |
+
**/__pycache__/**
|
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
import pickle
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
8 |
+
|
9 |
+
with open("dep_course_title_to_content_embed.pickle", "rb") as handle:
|
10 |
+
loaded_map = pickle.load(handle)
|
11 |
+
|
12 |
+
dep_name_course_name = list(loaded_map.keys())
|
13 |
+
dep_name = [x for (x,y) in dep_name_course_name]
|
14 |
+
course_titles = [y for (x,y) in dep_name_course_name]
|
15 |
+
course_content_embeddings = np.array(list(loaded_map.values()), dtype=np.float32)
|
16 |
+
|
17 |
+
cos = torch.nn.CosineSimilarity(dim=1, eps=1e-6)
|
18 |
+
def give_best_match(query):
|
19 |
+
embed = model.encode(query)
|
20 |
+
result = cos(torch.from_numpy(course_content_embeddings),torch.from_numpy(embed))
|
21 |
+
indices = reversed(np.argsort(result))
|
22 |
+
predictions = {course_titles[i] : float(result[i]) for i in indices}
|
23 |
+
return predictions
|
24 |
+
|
25 |
+
demo = gr.Interface(fn = give_best_match, inputs="text",outputs=gr.Label(num_top_classes=5))
|
26 |
+
demo.launch()
|
dep_course_title_to_content_embed.pickle
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7c7d2991aa7d9ddc6cfeb6ebb7e0d37edec497f94a533ad74d8297a9c387cc89
|
3 |
+
size 1220492
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.4.1
|
2 |
+
numpy==1.23.3
|
3 |
+
sentence-transformers==2.2.2
|
4 |
+
torch==1.12.1
|