用于答句匹配 input: words, ['id0', 'id1'] output: {'id0':0.2, 'id1':0.5, ...}
| 80 | |
| 81 | |
| 82 | class AMatch(QAMatchBase): |
| 83 | '''用于答句匹配 |
| 84 | input: words, ['id0', 'id1'] |
| 85 | output: {'id0':0.2, 'id1':0.5, ...} |
| 86 | ''' |
| 87 | def __init__(self, a_dict, model_factory=ModelFactory, match_models=['bow', 'tfidf', 'ngram_tfidf']): |
| 88 | super().__init__(model_factory) |
| 89 | self.a_dict = a_dict |
| 90 | self._init_model( self.a_dict, match_models=match_models ) |
| 91 | |
| 92 | |
| 93 | def predict(self, words, id_list, match_strategy='vote', vote_threshold=0.75, key_weight = {'bow': 1, 'tfidf': 1, 'ngram_tfidf': 1}): |
| 94 | res = self._predict( words ) |
| 95 | if match_strategy == 'vote': |
| 96 | a_res_dic = self.vote(res, vote_threshold, key_weight)[1] |
| 97 | return dict(zip( id_list, [a_res_dic[i] for i in id_list] )) |
| 98 | if match_strategy == 'score': |
| 99 | a_res_dic = self.score(res, vote_threshold, key_weight)[1] |
| 100 | return dict(zip( id_list, [a_res_dic[i] for i in id_list] )) |
| 101 | |
| 102 | |
| 103 |