nitinbhayana commited on
Commit
4ea6b57
1 Parent(s): b6aa4bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -3,17 +3,27 @@ from transformers import pipeline
3
 
4
  pipeline = pipeline("feature-extraction", model="WhereIsAI/UAE-Large-V1")
5
 
 
6
  def predict(text):
7
- title_embedding = pipeline(text)
8
- term_embedding = pipeline('multivitamin for men')
 
 
 
 
 
 
 
 
9
  semantic_score = cosine_similarity(title_embedding.flatten(), term_embedding.flatten()) * 100
10
  return str(format(semantic_score,'.2f'))
11
 
 
12
  gradio_app = gr.Interface(
13
  predict,
14
  inputs='text',
15
  outputs='text',
16
- title="Yes Or No?",
17
  )
18
 
19
  if __name__ == "__main__":
 
3
 
4
  pipeline = pipeline("feature-extraction", model="WhereIsAI/UAE-Large-V1")
5
 
6
+
7
  def predict(text):
8
+ title_outputs = pipeline(text)
9
+ title_outputs = torch.tensor(title_outputs)
10
+
11
+ # Mean pooling
12
+ title_embedding = title_outputs.mean(dim=1)
13
+ #title_embedding = title_outputs.last_hidden_state.mean(dim=1)
14
+ term_outputs = pipeline('multivitamin for men')
15
+ term_outputs = torch.tensor(term_outputs)
16
+ term_embedding = term_outputs.mean(dim=1)
17
+ #term_embedding = term_outputs.last_hidden_state.mean(dim=1)
18
  semantic_score = cosine_similarity(title_embedding.flatten(), term_embedding.flatten()) * 100
19
  return str(format(semantic_score,'.2f'))
20
 
21
+
22
  gradio_app = gr.Interface(
23
  predict,
24
  inputs='text',
25
  outputs='text',
26
+ title="Keyword Score",
27
  )
28
 
29
  if __name__ == "__main__":