前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >[TextMatch框架] QA Match (QA匹配)

[TextMatch框架] QA Match (QA匹配)

作者头像
MachineLP
发布于 2020-10-29 02:23:20
发布于 2020-10-29 02:23:20
85900
代码可运行
举报
文章被收录于专栏:小鹏的专栏小鹏的专栏
运行总次数:0
代码可运行

run examples

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
git clone https://github.com/MachineLP/TextMatch
cd TextMatch
export PYTHONPATH=${PYTHONPATH}:../TextMatch
python tests/core_test/qa_match_test.py

qa match

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import sys
from textmatch.core.qa_match import QMatch, AMatch, SemanticMatch

test_dict = {"id0": "其实事物发展有自己的潮流和规律",
   "id1": "当你身处潮流之中的时候,要紧紧抓住潮流的机会",
   "id2": "想办法脱颖而出,即使没有成功,也会更加洞悉时代的脉搏",
   "id3": "收获珍贵的知识和经验。而如果潮流已经退去",
   "id4": "这个时候再去往这个方向上努力,只会收获迷茫与压抑",
   "id5": "对时代、对自己都没有什么帮助",
   "id6": "但是时代的浪潮犹如海滩上的浪花,总是一浪接着一浪,只要你站在海边,身处这个行业之中,下一个浪潮很快又会到来。你需要敏感而又深刻地去观察,略去那些浮躁的泡沫,抓住真正潮流的机会,奋力一搏,不管成败,都不会遗憾。"}


def test_q_match(testword):
    # QMatch
    q_match = QMatch( q_dict=test_dict, match_models=['bow', 'tfidf', 'ngram_tfidf']) 
    q_match_pre = q_match.predict(testword, match_strategy='score', vote_threshold=0.5, key_weight = {'bow': 1, 'tfidf': 1, 'ngram_tfidf': 1})
    print ('q_match_pre>>>>>', q_match_pre )
    return q_match_pre

def test_a_match(testword):
    # AMatch
    a_match = AMatch( a_dict=test_dict, match_models=['bow', 'tfidf', 'ngram_tfidf']) 
    a_match_pre = a_match.predict(testword, ['id0', 'id1'], match_strategy='score', vote_threshold=0.5, key_weight = {'bow': 1, 'tfidf': 1, 'ngram_tfidf': 1}) 
    print ('a_match_pre>>>>>', a_match_pre )
    # a_match_pre>>>>> {'id0': 1.0, 'id1': 0.0} 
    return a_match_pre


def test_semantic_match(testword,words_dict=test_dict):
    # SemanticMatch
    s_match = SemanticMatch( words_dict=words_dict, match_models=['bow', 'tfidf', 'ngram_tfidf'] ) 
    s_match_pre = s_match.predict(testword, ['id0','id1', "id5"], match_strategy='score', vote_threshold=0.5, key_weight = {'bow': 1, 'tfidf': 1, 'ngram_tfidf': 1})
    print ('s_match_pre>>>>>', s_match_pre ) 
    # s_match_pre>>>>> {'id0': 1.0, 'id1': 0.0}
    return s_match_pre




if __name__ == '__main__':
    testword = "其实事物发展有自己的潮流和规律"
    test_q_match(testword)
    test_a_match(testword)
    test_semantic_match(testword)

基于关键词辅助

run examples

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
git clone https://github.com/MachineLP/TextMatch
cd TextMatch
export PYTHONPATH=${PYTHONPATH}:../TextMatch
python tests/core_test/qa_match_kw_test.py
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import sys
from textmatch.core.qa_match_kw import QAMatchKW

res_dict={'id0':0.8, 'id1':0.3}

qkw_dict = {
    'id0': ['神仙水|神仙', '价格|多少钱'],
    'id1': ['海蓝之谜|lammer', '面霜', '功效|功能|作用'],
    'id2': ['快递']
    }

akw_dict = {
    'id0': ['799|七百九十九|七九九'],
    'id1': ['补水|祛斑'],
    'id2': ['顺丰']
    }

def test_qkw_match(testword):
    qkw_match = QAMatchKW( qkw_dict=qkw_dict, akw_path=akw_dict ) 
    res = qkw_match.post_processing_q( testword,res_dict )
    print ('res>>>>>', res )
    return res


def test_akw_match(testword):
    qkw_match = QAMatchKW( qkw_dict=qkw_dict, akw_path=akw_dict ) 
    res = qkw_match.post_processing_a( testword,res_dict )
    print ('res>>>>>', res )
    return res



if __name__ == '__main__':
    testword = "神仙税多少钱"
    test_qkw_match(testword)
    testword = "799"
    test_akw_match(testword)

'''
res>>>>> {'id0': 1.0}
res>>>>> {'id0': [1.0, '神仙水'], 'id1': [0.0, '海蓝之谜|lammer']}
'''
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/07/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
[TextMatch框架] 简介
TextMatch is a semantic matching model library for QA & text search … It’s easy to train models and to export representation vectors.
MachineLP
2020/10/29
7330
[TextMatch框架] tests
TextMatch is a semantic matching model library for QA & text search … It’s easy to train models and to export representation vectors.
MachineLP
2020/10/29
3870
[TextMatch框架] 基于召回和排序的文本搜索
git clone https://github.com/MachineLP/TextMatch cd TextMatch export PYTHONPATH=${PYTHONPATH}:../TextMatch python tests/core_test/text_search_test.py tests/core_test/text_search_test.py import sys from textmatch.core.text_match import TextMatch from textma
MachineLP
2020/10/29
8590
[TextMatch框架] 基于faiss的搜索
run examples git clone https://github.com/MachineLP/TextMatch cd TextMatch export PYTHONPATH=${PYTHONPATH}:../TextMatch python tests/tools_test/faiss_test.py tests/tools_test/faiss_test.py import sys import json import time import faiss import numpy as np
MachineLP
2020/10/29
4540
[TextMatch框架] train model
TextMatch is a semantic matching model library for QA & text search … It’s easy to train models and to export representation vectors.
MachineLP
2020/10/29
5590
[TextMatch框架] server
TextMatch is a semantic matching model library for QA & text search … It’s easy to train models and to export representation vectors.
MachineLP
2020/10/29
5740
[TextMatch框架] 生成词云
TextMatch is a semantic matching model library for QA & text search … It’s easy to train models and to export representation vectors.
MachineLP
2020/10/29
1.9K0
[TextMatch框架] 生成词云
Similarities:精准相似度计算与语义匹配搜索工具包,多维度实现多种算法,覆盖文本、图像等领域,支持文搜、图搜文、图搜图匹配搜索
Similarities 相似度计算、语义匹配搜索工具包,实现了多种相似度计算、匹配搜索算法,支持文本、图像等。
汀丶人工智能
2023/08/12
4.1K0
Similarities:精准相似度计算与语义匹配搜索工具包,多维度实现多种算法,覆盖文本、图像等领域,支持文搜、图搜文、图搜图匹配搜索
解锁搜索新境界!让文本语义匹配助你轻松找到你需要的一切!(快速上手baseline)
实现了多种相似度计算、匹配搜索算法,支持文本、图像,python3开发,pip安装,开箱即用。
汀丶人工智能
2023/10/11
3730
解锁搜索新境界!让文本语义匹配助你轻松找到你需要的一切!(快速上手baseline)
Caffe2 - (二十) Detectron 之 config.py 文件参数
config.py 给出了 Detectron 的默认参数,其位于 lib/core/config.py. 类似于 Faster R-CNN 中对应的形式.
AIHGF
2019/02/27
3.2K0
爬虫框架scrapy
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中。 其最初是为了页面抓取 (更确切来说, 网络抓取 )所设计的, 也可以应用在获取API所返回的数据(例如 Amazon Associates Web Services ) 或者通用的网络爬虫。Scrapy用途广泛,可以用于数据挖掘、监测和自动化测试。
菲宇
2019/06/12
1.8K0
爬虫框架scrapy
精通 Transformers(一)
在过去的 20 年间,我们在自然语言处理(NLP)领域已经见证了巨大的变化。在此期间,我们经历了不同的范式,最终进入了由神奇的Transformers架构主宰的新时代。这种深度学习架构是通过继承多种方法而形成的。诸如上下文词嵌入、多头自注意力、位置编码、可并行化的架构、模型压缩、迁移学习和跨语言模型等方法都在其中。从各种基于神经网络的自然语言处理方法开始,Transformers架构逐渐演变成为一个基于注意力的编码器-解码器架构,并持续至今。现在,我们在文献中看到了这种架构的新成功变体。有些出色的模型只使用了其编码器部分,比如 BERT,或者只使用了其解码器部分,比如 GPT。
ApacheCN_飞龙
2024/05/24
3470
精通 Transformers(一)
Rabbitmq小书
1.生产者(Publisher): 发布消息到RabbitMQ中的交换机(Exchange)上
大忽悠爱学习
2022/10/04
3.4K0
Rabbitmq小书
Elasticsearch readonlyrest
ReadonlyREST is a light weight Elasticsearch plugin that adds encryption, authentication, authorization and access control capabilities to Elasticsearch embedded REST API. The core of this plugin is an ACL engine that checks each incoming request through a sequence of rules a bit like a firewall. There are a dozen rules that can be grouped in sequences of blocks and form a powerful representation of a logic chain.
鹏程
2023/05/02
3.2K0
Elasticsearch readonlyrest
SqlAlchemy 2.0 中文文档(五十九)
本文详细介绍了 1.4 版本中进行的单个问题级别的更改。有关 1.4 中的新内容的叙述性概述,请参阅 SQLAlchemy 1.4 有什么新功能?。
ApacheCN_飞龙
2024/08/16
2260
pyntho经典面试题
 (1)与java相比:在很多方面,Python比Java要简单,比如java中所有变量必须声明才能使用,而Python不需要声明,用少量的代码构建出很多功能;(高效的高级数据结构)
py3study
2020/01/17
3.1K0
Python 迁移学习实用指南:6~11
在计算机视觉的保护下,图像识别是一个活跃的跨学科研究领域。 顾名思义,图像或对象识别是识别图像或视频序列中的对象的任务。 传统上,该领域利用数学和计算机辅助建模以及对象设计方面的进步。 这些年来,已经开发了一些手工标注的数据集,以测试和评估图像识别系统。 我们现在称它们为传统技术,一直统治着整个场景,并且不断地改进这项任务,直到最近。 2012 年,深度学习参加了 ImageNet 竞赛,为快速改善和进步计算机视觉和深度学习技术打开了闸门。
ApacheCN_飞龙
2023/04/23
1.7K0
Python100Days
这可能是我目前发现最好最好的Python教程了,故整理至我的博客。 原项目GitHub地址https://github.com/jackfrued/Python-100-Days
一点儿也不潇洒
2018/08/07
9.9K0
干货 | 突破disable_functions限制执行命令·下
UAF漏洞(Use-After-Free)是一种内存破坏漏洞,漏洞成因是一块堆内存被释放了之后又被使用。又被使用指的是:指针存在(悬垂指针被引用)。这个引用的结果是不可预测的,因为不知道会发生什么。由于大多数的堆内存其实都是C++对象,所以利用的核心思路就是分配堆去占坑,占的坑中有自己构造的虚表。
HACK学习
2022/02/17
3.4K0
干货 | 突破disable_functions限制执行命令·下
Python面试题之Python面试题汇总
(1)与java相比:在很多方面,Python比Java要简单,比如java中所有变量必须声明才能使用,而Python不需要声明,用少量的代码构建出很多功能;(高效的高级数据结构)
Jetpropelledsnake21
2018/08/01
11.6K0
Python面试题之Python面试题汇总
相关推荐
[TextMatch框架] 简介
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文