MCPcopy Create free account
hub / github.com/MachineLP/TextMatch / SemanticMatch

Class SemanticMatch

textmatch/core/qa_match.py:104–123  ·  view source on GitHub ↗

用于语意匹配 input: words, ['id0', 'id1'] output: {'id0':0.2, 'id1':0.5, ...}

Source from the content-addressed store, hash-verified

102
103
104class SemanticMatch(QAMatchBase):
105 '''用于语意匹配
106 input: words, ['id0', 'id1']
107 output: {'id0':0.2, 'id1':0.5, ...}
108 '''
109 def __init__(self, words_dict, model_factory=ModelFactory, match_models=['bow', 'tfidf', 'ngram_tfidf'] ):
110 super().__init__(model_factory)
111 #with open(words_path,'r', encoding='UTF-8') as f:
112 # self.words_dict = json.load(f)
113 self._init_model( words_dict, match_models=match_models )
114
115
116 def predict(self, words, id_list, match_strategy='vote', vote_threshold=0.75, key_weight = {'bow': 1, 'tfidf': 1, 'ngram_tfidf': 1}):
117 res = self._predict( words )
118 if match_strategy == 'vote':
119 a_res_dic = self.vote(res, vote_threshold, key_weight)[1]
120 return dict(zip( id_list, [a_res_dic[i] for i in id_list] ))
121 if match_strategy == 'score':
122 a_res_dic = self.score(res, vote_threshold, key_weight)[1]
123 return dict(zip( id_list, [a_res_dic[i] for i in id_list] ))
124

Callers 1

test_semantic_matchFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_semantic_matchFunction · 0.72