|
@@ -43,7 +43,7 @@ class NLPFunction(object):
|
|
|
score_tensor = score_function(text_emb1, text_emb2)
|
|
|
return score_tensor
|
|
|
|
|
|
- def base_string_similarity(self, text_dict):
|
|
|
+ def base_string_similarity(self, text_dict, use_cache=True):
|
|
|
"""
|
|
|
基础功能,计算两个字符串的相似度
|
|
|
:param text_dict:
|
|
@@ -51,20 +51,26 @@ class NLPFunction(object):
|
|
|
"""
|
|
|
text_a = text_dict['text_a']
|
|
|
text_b = text_dict['text_b']
|
|
|
- score_tensor = self.cached_similarity(text_a, text_b)
|
|
|
+ if use_cache:
|
|
|
+ score_tensor = self.cached_similarity(text_a, text_b)
|
|
|
+ else:
|
|
|
+ score_tensor = self.direct_similarity(text_a, text_b)
|
|
|
response = {
|
|
|
"score": score_tensor.squeeze().tolist()
|
|
|
}
|
|
|
return response
|
|
|
|
|
|
- def base_list_similarity(self, pair_list_dict):
|
|
|
+ def base_list_similarity(self, pair_list_dict, use_cache=True):
|
|
|
"""
|
|
|
计算两个list的相似度
|
|
|
:return:
|
|
|
"""
|
|
|
text_a = pair_list_dict['text_list_a']
|
|
|
text_b = pair_list_dict['text_list_b']
|
|
|
- score_tensor = self.cached_similarity(text_a, text_b)
|
|
|
+ if use_cache:
|
|
|
+ score_tensor = self.cached_similarity(text_a, text_b)
|
|
|
+ else:
|
|
|
+ score_tensor = self.direct_similarity(text_a, text_b)
|
|
|
response = {
|
|
|
"score_list_list": score_tensor.tolist()
|
|
|
}
|