Spaces:
Running
on
T4
Running
on
T4
mvectors
Browse files- pages/Semantic_Search.py +0 -20
- semantic_search/all_search_execute.py +0 -11
- utilities/mvectors.py +0 -2
pages/Semantic_Search.py
CHANGED
@@ -801,42 +801,22 @@ def render_answer(answer,index):
|
|
801 |
final_desc_ = "<p></p><p>"
|
802 |
for word_ in desc___:
|
803 |
str_=re.sub('[^A-Za-z0-9]+', '', word_).lower()
|
804 |
-
###### stemming and highlighting
|
805 |
-
|
806 |
-
# ans_text = ans['desc']
|
807 |
-
# query_text = st.session_state.input_text
|
808 |
-
|
809 |
stemmed_word = next(iter(set(stem_(str_))))
|
810 |
-
# print("stemmed_word-------------------")
|
811 |
-
# print(stemmed_word)
|
812 |
-
|
813 |
-
|
814 |
-
# common = ans_text_stemmed.intersection( query_text_stemmed)
|
815 |
-
# #unique = set(document_1_words).symmetric_difference( )
|
816 |
-
|
817 |
-
# desc__stemmed = stem_(desc__)
|
818 |
-
|
819 |
-
#print(str_)
|
820 |
if(stemmed_word in res___ or str_ in res___):
|
821 |
if(stemmed_word in res___):
|
822 |
mod_word = stemmed_word
|
823 |
else:
|
824 |
mod_word = str_
|
825 |
-
#print(str_)
|
826 |
if(res___.index(mod_word)==0):
|
827 |
-
#print(str_)
|
828 |
final_desc_ += "<span style='color:#ffffff;background-color:#8B0001;font-weight:bold'>"+word_+"</span> "
|
829 |
elif(res___.index(mod_word)==1):
|
830 |
-
#print(str_)
|
831 |
final_desc_ += "<span style='color:#ffffff;background-color:#C34632;font-weight:bold'>"+word_+"</span> "
|
832 |
else:
|
833 |
-
#print(str_)
|
834 |
final_desc_ += "<span style='color:#ffffff;background-color:#E97452;font-weight:bold'>"+word_+"</span> "
|
835 |
else:
|
836 |
final_desc_ += word_ + " "
|
837 |
|
838 |
final_desc_ += "</p><br>"
|
839 |
-
#print(final_desc_)
|
840 |
st.markdown(final_desc_,unsafe_allow_html = True)
|
841 |
elif("highlight" in ans and 'Keyword Search' in st.session_state.input_searchType):
|
842 |
test_strs = ans["highlight"]
|
|
|
801 |
final_desc_ = "<p></p><p>"
|
802 |
for word_ in desc___:
|
803 |
str_=re.sub('[^A-Za-z0-9]+', '', word_).lower()
|
|
|
|
|
|
|
|
|
|
|
804 |
stemmed_word = next(iter(set(stem_(str_))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
805 |
if(stemmed_word in res___ or str_ in res___):
|
806 |
if(stemmed_word in res___):
|
807 |
mod_word = stemmed_word
|
808 |
else:
|
809 |
mod_word = str_
|
|
|
810 |
if(res___.index(mod_word)==0):
|
|
|
811 |
final_desc_ += "<span style='color:#ffffff;background-color:#8B0001;font-weight:bold'>"+word_+"</span> "
|
812 |
elif(res___.index(mod_word)==1):
|
|
|
813 |
final_desc_ += "<span style='color:#ffffff;background-color:#C34632;font-weight:bold'>"+word_+"</span> "
|
814 |
else:
|
|
|
815 |
final_desc_ += "<span style='color:#ffffff;background-color:#E97452;font-weight:bold'>"+word_+"</span> "
|
816 |
else:
|
817 |
final_desc_ += word_ + " "
|
818 |
|
819 |
final_desc_ += "</p><br>"
|
|
|
820 |
st.markdown(final_desc_,unsafe_allow_html = True)
|
821 |
elif("highlight" in ans and 'Keyword Search' in st.session_state.input_searchType):
|
822 |
test_strs = ans["highlight"]
|
semantic_search/all_search_execute.py
CHANGED
@@ -274,10 +274,6 @@ def handler(input_,session_id):
|
|
274 |
vector_payload['neural']['product_description_vector']['filter']["bool"]["must"].append({"term": {"gender_affinity": st.session_state.input_gender}})
|
275 |
if(st.session_state.input_price!=(0,0)):
|
276 |
vector_payload['neural']['product_description_vector']['filter']["bool"]["must"].append({"range": {"price": {"gte": st.session_state.input_price[0],"lte": st.session_state.input_price[1] }}})
|
277 |
-
|
278 |
-
# print("vector_payload**************")
|
279 |
-
# print(vector_payload)
|
280 |
-
|
281 |
###### end of efficient filter applying #####
|
282 |
|
283 |
hybrid_payload["query"]["hybrid"]["queries"].append(vector_payload)
|
@@ -310,7 +306,6 @@ def handler(input_,session_id):
|
|
310 |
multimodal_payload['neural']['product_multimodal_vector']['filter'] = filter_['filter']
|
311 |
|
312 |
if(st.session_state.input_manual_filter == "True"):
|
313 |
-
print("presence of filters------------")
|
314 |
multimodal_payload['neural']['product_multimodal_vector']['filter'] = {"bool":{"must":[]}}
|
315 |
if(st.session_state.input_category!=None):
|
316 |
multimodal_payload['neural']['product_multimodal_vector']['filter']["bool"]["must"].append({"term": {"category": st.session_state.input_category}})
|
@@ -409,14 +404,9 @@ def handler(input_,session_id):
|
|
409 |
path = "retail-search-colbert-description/_search"
|
410 |
url = host + path
|
411 |
r = requests.get(url, auth=awsauth, json=hybrid_payload, headers=headers)
|
412 |
-
print(r.status_code)
|
413 |
-
#print(r.text)
|
414 |
response_ = json.loads(r.text)
|
415 |
-
print("-------------colbert ---- 3-----------")
|
416 |
-
#print(response_)
|
417 |
docs = response_['hits']['hits']
|
418 |
docs = cb.search(docs)
|
419 |
-
print("-------------COLBERT------------5------------------------------------------")
|
420 |
else:
|
421 |
single_query = hybrid_payload["query"]["hybrid"]["queries"][0]
|
422 |
del hybrid_payload["query"]["hybrid"]
|
@@ -525,7 +515,6 @@ def handler(input_,session_id):
|
|
525 |
arr.append(res_)
|
526 |
dup.append(doc['_source']['image_url'])
|
527 |
|
528 |
-
#print(arr)
|
529 |
return arr[0:k_]
|
530 |
|
531 |
|
|
|
274 |
vector_payload['neural']['product_description_vector']['filter']["bool"]["must"].append({"term": {"gender_affinity": st.session_state.input_gender}})
|
275 |
if(st.session_state.input_price!=(0,0)):
|
276 |
vector_payload['neural']['product_description_vector']['filter']["bool"]["must"].append({"range": {"price": {"gte": st.session_state.input_price[0],"lte": st.session_state.input_price[1] }}})
|
|
|
|
|
|
|
|
|
277 |
###### end of efficient filter applying #####
|
278 |
|
279 |
hybrid_payload["query"]["hybrid"]["queries"].append(vector_payload)
|
|
|
306 |
multimodal_payload['neural']['product_multimodal_vector']['filter'] = filter_['filter']
|
307 |
|
308 |
if(st.session_state.input_manual_filter == "True"):
|
|
|
309 |
multimodal_payload['neural']['product_multimodal_vector']['filter'] = {"bool":{"must":[]}}
|
310 |
if(st.session_state.input_category!=None):
|
311 |
multimodal_payload['neural']['product_multimodal_vector']['filter']["bool"]["must"].append({"term": {"category": st.session_state.input_category}})
|
|
|
404 |
path = "retail-search-colbert-description/_search"
|
405 |
url = host + path
|
406 |
r = requests.get(url, auth=awsauth, json=hybrid_payload, headers=headers)
|
|
|
|
|
407 |
response_ = json.loads(r.text)
|
|
|
|
|
408 |
docs = response_['hits']['hits']
|
409 |
docs = cb.search(docs)
|
|
|
410 |
else:
|
411 |
single_query = hybrid_payload["query"]["hybrid"]["queries"][0]
|
412 |
del hybrid_payload["query"]["hybrid"]
|
|
|
515 |
arr.append(res_)
|
516 |
dup.append(doc['_source']['image_url'])
|
517 |
|
|
|
518 |
return arr[0:k_]
|
519 |
|
520 |
|
utilities/mvectors.py
CHANGED
@@ -70,8 +70,6 @@ def search(hits):
|
|
70 |
token = tokens[index]
|
71 |
if(token!='[SEP]' and token!='[CLS]'):
|
72 |
query_token_vector = np.array(i)
|
73 |
-
print("query token: "+token)
|
74 |
-
print("-----------------")
|
75 |
scores = []
|
76 |
for m in with_s:
|
77 |
m_arr = m.split("-")
|
|
|
70 |
token = tokens[index]
|
71 |
if(token!='[SEP]' and token!='[CLS]'):
|
72 |
query_token_vector = np.array(i)
|
|
|
|
|
73 |
scores = []
|
74 |
for m in with_s:
|
75 |
m_arr = m.split("-")
|