EgorDan commited on
Commit
4f4712b
1 Parent(s): fa24701

slight changes to algorithm

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -14,14 +14,14 @@ from faiss_file import model, tokenizer, embeddings_dataset, embed_bert_cls, rec
14
 
15
  device = 'cpu'
16
 
17
- tokenizer_k = AutoTokenizer.from_pretrained("cointegrated/rubert-tiny")
18
- model_k = AutoModel.from_pretrained("cointegrated/rubert-tiny")
19
  kmeans = load('kmeans.joblib')
20
  emb = load('final_emb.joblib')
21
 
22
  def recomendation(input):
23
 
24
- user_input = embed_bert_cls(input, model_k, tokenizer_k)
25
  label = kmeans.predict(user_input.reshape(1, -1))[0]
26
  sample_df = emb[emb['labels'] == label].copy()
27
  sample_df['cosine'] = sample_df['embeddings'].apply(lambda x: np.dot(x, user_input) / (np.linalg.norm(x) * np.linalg.norm(user_input)))
@@ -71,7 +71,7 @@ with tab1:
71
 
72
  with tab2:
73
 
74
- book_recs = recommend(user_prompt, books_per_page)
75
  if button and len(user_prompt) > 1:
76
 
77
  book_recs = recomendation(user_prompt)
 
14
 
15
  device = 'cpu'
16
 
17
+ #tokenizer_k = AutoTokenizer.from_pretrained("cointegrated/rubert-tiny")
18
+ #model_k = AutoModel.from_pretrained("cointegrated/rubert-tiny")
19
  kmeans = load('kmeans.joblib')
20
  emb = load('final_emb.joblib')
21
 
22
  def recomendation(input):
23
 
24
+ user_input = embed_bert_cls(input, model, tokenizer)#embed_bert_cls(input, model_k, tokenizer_k)
25
  label = kmeans.predict(user_input.reshape(1, -1))[0]
26
  sample_df = emb[emb['labels'] == label].copy()
27
  sample_df['cosine'] = sample_df['embeddings'].apply(lambda x: np.dot(x, user_input) / (np.linalg.norm(x) * np.linalg.norm(user_input)))
 
71
 
72
  with tab2:
73
 
74
+ #book_recs = recommend(user_prompt, books_per_page)
75
  if button and len(user_prompt) > 1:
76
 
77
  book_recs = recomendation(user_prompt)