def test_bert(self): """测试bert结果""" bert_sim = text2vec.Similarity(embedding_type='bert') apply_bert_case(bert_sim, case_same_keywords) # q1:飞行员没钱买房怎么办?, q2:父母没钱买房子, expect a:False, actual a:0.846145250083127 # q1:聊天室都有哪些好的, q2:聊天室哪个好, expect a:True, actual a:0.9302744928458128 # q1:不锈钢上贴的膜怎么去除, q2:不锈钢上的胶怎么去除, expect a:True, actual a:0.9625103602739326 # q1:动漫人物的口头禅, q2:白羊座的动漫人物, expect a:False, actual a:0.9254731623309143 apply_bert_case(bert_sim, case_categories_corresponding_pairs)
def test_w2v(self): """测试w2v结果""" w2v_sim = text2vec.Similarity(embedding_type='w2v') apply_w2v_case(w2v_sim, case_same_keywords) # q1:飞行员没钱买房怎么办?, q2:父母没钱买房子, expect a:False, actual a:0.8113352629229633 # q1:聊天室都有哪些好的, q2:聊天室哪个好, expect a:True, actual a:0.8509278390378958 # q1:不锈钢上贴的膜怎么去除, q2:不锈钢上的胶怎么去除, expect a:True, actual a:0.9617148170317945 # q1:动漫人物的口头禅, q2:白羊座的动漫人物, expect a:False, actual a:0.8928384526487808 apply_w2v_case(w2v_sim, case_categories_corresponding_pairs)
def w2v_sim(): w2v_sim = text2vec.Similarity(embedding_type='w2v') print(w2v_sim.get_score(a, b))
def bert_sim(): bert_sim = text2vec.Similarity(embedding_type='bert') s = bert_sim.get_score(a, b) print(s)
def test_bert_sim(self): bert_sim = text2vec.Similarity(embedding_type='bert') r = bert_sim.get_score(a, b) print(r) self.assertEqual(round(r, 3), 0.577)
def test_w2v_sim(self): """测试w2v_sim""" w2v_sim = text2vec.Similarity(embedding_type='w2v') r = w2v_sim.get_score(a,b) print(r) self.assertEqual(round(r, 3), 0.989)
# query1 query2 matching? case_same_keywords = [['飞行员没钱买房怎么办?', '父母没钱买房子', False], ['聊天室都有哪些好的', '聊天室哪个好', True], ['不锈钢上贴的膜怎么去除', '不锈钢上的胶怎么去除', True], ['动漫人物的口头禅', '白羊座的动漫人物', False]] case_categories_corresponding_pairs = [['从广州到长沙在哪里定高铁票', '在长沙哪里坐高铁回广州?', False], ['请问现在最好用的听音乐软件是什么啊', '听歌用什么软件比较好', True], ['谁有吃过完美的产品吗?如何?', '完美产品好不好', True], ['朱熹是哪个朝代的诗人', '朱熹是明理学的集大成者,他生活在哪个朝代', True], ['这是哪个奥特曼?', '这是什么奥特曼...', True], ['网上找工作可靠吗', '网上找工作靠谱吗', True], ['你们都喜欢火影忍者里的谁啊', '火影忍者里你最喜欢谁', True]] bert_sim = text2vec.Similarity(embedding_type='bert') w2v_sim = text2vec.Similarity(embedding_type='w2v') def apply_bert_case(cases: List[List[str]]): for line in cases: q1 = line[0] q2 = line[1] a = line[2] s = bert_sim.get_score(q1, q2) print(f'q1:{q1}, q2:{q2}, expect a:{a}, actual a:{s}') def apply_w2v_case(cases: List[List[str]]): for line in cases: