当前位置: 首页 > news >正文

网站配色 蓝色电话销售-网站建设-开场白

网站配色 蓝色,电话销售-网站建设-开场白,设计师招聘平台,如何在百度上做网站代码以及视频讲解 本文所涉及所有资源均在传知代码平台可获取 概述 本文复现论文 Hearst patterns revisited: Automatic hypernym detection from large text corpora[1] 提出的文本中上位词检测方法。 在自然语言处理中#xff0c;上下位关系#xff08;Is-a Relations…代码以及视频讲解 本文所涉及所有资源均在传知代码平台可获取 概述 本文复现论文 Hearst patterns revisited: Automatic hypernym detection from large text corpora[1] 提出的文本中上位词检测方法。 在自然语言处理中上下位关系Is-a Relationship表示的是概念又称术语之间的语义包含关系。其中上位词Hypernym表示的是下位词Hyponym的抽象化和一般化而下位词则是对上位词的具象化和特殊化。举例来说“水果”是“苹果”、“香蕉”、“橙子”等的上位词“汽车”、“电动车”、“自行车”等则是“交通工具”的下位词。在自然语言处理任务中理解概念之间的上下位关系对于诸如词义消歧、信息检索、自动问答、语义推理等任务都具有重要意义。 文本中上位词检测方法即从文本中提取出互为上下位关系的概念。现有的无监督上位词检测方法大致可以分为两类——基于模式的方法和基于分布模型的方法 1基于模式的方法其主要思想是利用特定的词汇-句法模式来检测文本中的上下位关系。例如我们可以通过检测文本中是否存在句式“【词汇1】是一种【词汇2】”或“【词汇1】例如【词汇2】”来判断【词汇1】和【词汇2】间是否存在上下位关系。这些模式可以是预定义的也可以是通过机器学习得到的。然而基于模式的方法存在一个众所周知的问题——极端稀疏性即词汇必须在有限的模式中共同出现其上下位关系才能被检测到。 2基于分布模型的方法基于大型文本语料库词汇可以被学习并表示成向量的形式。利用特定的相似度度量我们可以区分词汇间的不同关系。 在该论文中作者研究了基于模式的方法和基于分布模型的方法在几个上下位关系检测任务中的表现并发现简单的基于模式的方法在常见的数据集上始终优于基于分布模型的方法。作者认为这种差异产生的原因是基于模式的方法提供了尚不能被分布模型准确捕捉到的重要上下文约束。 算法原理 Hearst 模式 作者使用如下模式来捕捉文本中的上下位关系 模板例子 X X X which is a (example|class|kind…) of Y Y YCoffee, which is a beverage, is enjoyed worldwide. X X X (and|or) (any|some) other Y Y YCoffee and some other hot beverages are popular in the morning. X X X which is called Y Y YCoffee, which is called “java”. X X X is JJS (most)? Y Y YCoffee is the most consumed beverage worldwide. X X X is a special case of Y Y YEspresso is a special case of coffee. X X X is an Y Y Y thatA latte is a coffee that includes steamed milk. X X X is a !(member|part|given) Y Y YA robot is a machine.!(features|properties) Y Y Y such as X 1 X_1 X1​, X 2 X_2 X2​, …Beverages such as coffee, tea, and soda have various properties such as caffeine content and flavor.(Unlike|like) (most|all|any|other) Y Y Y, X X XUnlike most beverages, coffee is often consumed hot. Y Y Y including X 1 X_1 X1​, X 2 X_2 X2​, …Beverages including coffee, tea, and hot chocolate are served at the café. 通过对大型语料库使用模式捕捉候选上下位词对并统计频次可以计算任意两个词汇之间存在上下位关系的概率 上下位关系得分 设 p ( x , y ) p(x,y) p(x,y)是词汇 x x x 和 y y y 分别作为下位词和上位词出现在预定义模式集合 P P P 中的频率 p − ( x ) p^-(x) p−(x)是 x x x 作为任意词汇的下位词出现在预定义模式中的频率 p ( y ) p^(y) p(y)是 y y y 作为任意词汇的上位词出现在预定义模式中的频率。作者定义正逐点互信息Positive Point-wise Mutual Information作为词汇间上下位关系得分的依据 ppmi ( x , y ) max ⁡ ( 0 , log ⁡ p ( x , y ) p − ( x ) , p ( y ) ) \text{ppmi}(x,y)\max(0,\log\frac{p(x,y)}{p^-(x),p^(y)}) ppmi(x,y)max(0,logp−(x),p(y)p(x,y)​) 由于模式的稀疏性部分存在上下位关系的词对并不会出现在特定的模式中。为了解决这一问题作者利用PPMI得分矩阵的稀疏表示来预测任意未知词对的上下位关系得分。PPMI得分矩阵定义如下 M ∈ R m × m , M i j ppmi ( x , y ) ( 1 ≤ x , y ≤ m ) M\in R^{m\times m},M_{ij}\text{ppmi}(x,y)(1\le x,y\le m) M∈Rm×m,Mij​ppmi(x,y)(1≤x,y≤m) 其中 KaTeX parse error: Undefined control sequence: \or at position 18: …|\{x|(x,y)\in P\̲o̲r̲(y,x)\in P\}|。 对矩阵 M M M 做奇异值分解可得 M U Σ V T MU\Sigma V^T MUΣVT然后我们可以通过下式计算出上下位关系 spmi 得分 spmi ( x , y ) u x T Σ r v y \text{spmi}(x,y)u_x^T\Sigma_r v_y spmi(x,y)uxT​Σr​vy​ 其中 u x u_x ux​ 和 v y v_y vy​ 分别是矩阵 U U U 和 V V V 的第 x x x 行和第 y y y 行 Σ r \Sigma_r Σr​是对 Σ \Sigma Σ 的 r r r 截断即除了最大的 r r r 个元素其余全部置零。 核心逻辑 具体的核心逻辑如下所示 import spacy import json from tqdm import tqdm import re from collections import Counter import numpy as np import mathnlp spacy.load(en_core_web_sm)def clear_text(text):对文本进行清理# 这里可以添加自己的清理步骤# 删去交叉引用标识例如[1]pattern r\[\d\]result re.sub(pattern, , text)return resultdef split_sentences(text):将文本划分为句子doc nlp(text)sentences [sent.text.strip() for sent in doc.sents]return sentencesdef extract_noun_phrases(text):从文本中抽取出术语doc nlp(text)terms []# 遍历句子中的名词性短语例如a type of robotfor chunk in doc.noun_chunks:term_parts []for token in list(chunk)[-1::]:# 以非名词且非形容词或是代词的词语为界保留右半部分(例如robot)if token.pos_ in [NOUN, ADJ] and token.dep_ ! PRON:term_parts.append(token.text)else:breakif term_parts ! []:term .join(term_parts)terms.append(term)return termsdef term_lemma(term):将术语中的名词还原为单数lemma []doc nlp(term)for token in doc:if token.pos_ NOUN:lemma.append(token.lemma_)else:lemma.append(token.text)return .join(lemma)def find_co_occurrence(sentence, terms, patterns):找出共现于模板的术语对pairs []# 两两之间匹配for hyponym in terms:for hypernym in terms:if hyponym hypernym:continuefor pattern in patterns:# 将模板中的占位符替换成候选上下位词pattern pattern.replace(__HYPONYM__, re.escape(hyponym))pattern pattern.replace(__HYPERNYM__, re.escape(hypernym))# 在句子中匹配if re.search(pattern, sentence) ! None:# 将名词复数还原为单数pairs.append((term_lemma(hyponym), term_lemma(hypernym)))return pairsdef count_unique_tuple(tuple_list):统计列表中独特元组出现次数counter Counter(tuple_list)result [{tuple: unique, count: count} for unique, count in counter.items()]return resultdef find_rth_largest(arr, r):找到第r大的元素rth_largest_index np.argpartition(arr, -r)[-r]return arr[rth_largest_index]def find_pairs(corpus_file, patterns, disable_tqdmFalse):读取文件并找出共现于模板的上下位关系术语对pairs []# 按行读取语料库lines corpus_file.readlines()for line in tqdm(lines, descFinding pairs, ascii 123456789#, disabledisable_tqdm):# 删去首尾部分的空白字符line line.strip()# 忽略空白行if line :continue# 清理文本line clear_text(line)# 按句处理sentences split_sentences(line)for sentence in sentences:# 抽取出句子中的名词性短语并分割成术语candidates_terms extract_noun_phrases(sentence)# 找出共现于模板的术语对pairs pairs find_co_occurrence(sentence, candidates_terms, patterns)return pairsdef spmi_calculate(configs, unique_pairs):基于对共现频率的统计计算任意两个术语间的spmi得分# 计算每个术语分别作为上下位词的出现频次terms list(set([pair[tuple][0] for pair in unique_pairs] [pair[tuple][1] for pair in unique_pairs]))term_count {term: {hyponym_count: 0, hypernym_count: 0} for term in terms}all_count 0for pair in unique_pairs:term_count[pair[tuple][0]][hyponym_count] pair[count]term_count[pair[tuple][1]][hypernym_count] pair[count]all_count pair[count]# 计算PPMI矩阵 ppmi_matrix np.zeros((len(terms), len(terms)), dtypenp.float32)for pair in unique_pairs:hyponym pair[tuple][0]hyponym_id terms.index(hyponym)hypernym pair[tuple][1]hypernym_id terms.index(hypernym)ppmi (pair[count] * all_count) / (term_count[hyponym][hyponym_count] * term_count[hypernym][hypernym_count])ppmi max(0, math.log(ppmi))ppmi_matrix[hyponym_id, hypernym_id] ppmi# 对PPMI进行奇异值分解并截断r configs[clip]U, S, Vt np.linalg.svd(ppmi_matrix)S[S find_rth_largest(S, r)] 0S_r np.diag(S)# 计算任意两个术语间的spmiparis2spmi []for hyponym_id in range(len(terms)):for hypernym_id in range(len(terms)):# 同一个术语间不计算得分if hyponym_id hypernym_id:continuespmi np.dot(np.dot(U[hyponym_id , :], S_r), Vt[:, hypernym_id]).item()# 保留得分大于阈值的术语对if spmi configs[threshold]:hyponym terms[hyponym_id]hypernym terms[hypernym_id]paris2spmi.append({hyponym: hyponym, hypernym: hypernym, spmi: spmi})# 按spmi从大到小排序paris2spmi sorted(paris2spmi, keylambda x: x[spmi], reverseTrue)return paris2spmiif __name__ __main__:# 读取配置文件with open(config.json, r) as config_file:configs json.load(config_file)# 读取模板with open(configs[patterns_path], r) as patterns_file:patterns json.load(patterns_file)# 语料库中共现于模板的术语对with open(configs[corpus_path], r, encodingutf-8) as corpus_file:pairs find_pairs(corpus_file, patterns)# 统计上下位关系的出现频次unique_pairs count_unique_tuple(pairs)with open(configs[pairs_path], w) as pairs_file:json.dump(unique_pairs, pairs_file, indent6, ensure_asciiTrue)# 计算任意两个术语间的spmi得分paris2spmi spmi_calculate(configs, unique_pairs)with open(configs[spmi_path], w) as spmi_file:json.dump(paris2spmi, spmi_file, indent6, ensure_asciiTrue)以上代码仅作展示更详细的代码文件请参见附件。 效果演示 运行脚本main.py程序会自动检测语料库中存在的上下位关系。运行结果如下所示 使用方式 解压附件压缩包并进入工作目录。如果是Linux系统请使用如下命令 unzip Revisit-Hearst-Pattern.zip cd Revisit-Hearst-Pattern代码的运行环境可通过如下命令进行配置 pip install -r requirements.txt python -m spacy download en_core_web_sm如果希望在本地运行程序请运行如下命令 python main.py如果希望在线部署请运行如下命令 python main-flask.py如果希望添加新的模板请修改文件data/patterns.json。 _HYPONYM_表示下位词占位符_HYPERNYM_表示上位词占位符其余格式请遵照 python.re 模块的正则表达式要求。 如果希望使用自己的文件路径或改动其他实验设置请在文件config.json中修改对应参数。以下是参数含义对照表 参数名含义corpus_path文本语料库文件路径默认为“data/corpus.txt”。patterns_path预定义模式库的路径。默认为“data/patterns.json”。pairs_path利用模式筛选出的上下位关系词对路径默认为“data/pairs.json”。spmi_path上下位关系词对及其spmi得分路径默认为“data/spmi.json”。clip用于对 Σ \Sigma Σ 进行截断的参数 r r r ,默认为10。thresholdspmi得分小于该值的词对将被舍去。默认为1。max_bytes输入文件大小上限用于在线演示默认为200kB。 以上内容皆为原创请勿转载 参考文献 [1] Roller S, Kiela D, Nickel M. Hearst patterns revisited: Automatic hypernym detection from large text corpora[J]. arXiv preprint arXiv:1806.03191, 2018. 源码下载
文章转载自:
http://www.morning.fbylq.cn.gov.cn.fbylq.cn
http://www.morning.hyfrd.cn.gov.cn.hyfrd.cn
http://www.morning.lrskd.cn.gov.cn.lrskd.cn
http://www.morning.fyskq.cn.gov.cn.fyskq.cn
http://www.morning.ftrpvh.cn.gov.cn.ftrpvh.cn
http://www.morning.pbmg.cn.gov.cn.pbmg.cn
http://www.morning.kgsws.cn.gov.cn.kgsws.cn
http://www.morning.npfkw.cn.gov.cn.npfkw.cn
http://www.morning.xmyrn.cn.gov.cn.xmyrn.cn
http://www.morning.fplqh.cn.gov.cn.fplqh.cn
http://www.morning.qxmpp.cn.gov.cn.qxmpp.cn
http://www.morning.thlzt.cn.gov.cn.thlzt.cn
http://www.morning.sgnxl.cn.gov.cn.sgnxl.cn
http://www.morning.jfmjq.cn.gov.cn.jfmjq.cn
http://www.morning.lqznq.cn.gov.cn.lqznq.cn
http://www.morning.rykmf.cn.gov.cn.rykmf.cn
http://www.morning.fqqcn.cn.gov.cn.fqqcn.cn
http://www.morning.kmqlf.cn.gov.cn.kmqlf.cn
http://www.morning.xrwbc.cn.gov.cn.xrwbc.cn
http://www.morning.c7496.cn.gov.cn.c7496.cn
http://www.morning.xqffq.cn.gov.cn.xqffq.cn
http://www.morning.czqqy.cn.gov.cn.czqqy.cn
http://www.morning.ttryd.cn.gov.cn.ttryd.cn
http://www.morning.dztp.cn.gov.cn.dztp.cn
http://www.morning.c7501.cn.gov.cn.c7501.cn
http://www.morning.rsnn.cn.gov.cn.rsnn.cn
http://www.morning.glxmf.cn.gov.cn.glxmf.cn
http://www.morning.xjnw.cn.gov.cn.xjnw.cn
http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn
http://www.morning.cwrnr.cn.gov.cn.cwrnr.cn
http://www.morning.bktly.cn.gov.cn.bktly.cn
http://www.morning.tnbas.com.gov.cn.tnbas.com
http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn
http://www.morning.3jiax.cn.gov.cn.3jiax.cn
http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn
http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com
http://www.morning.wmhlz.cn.gov.cn.wmhlz.cn
http://www.morning.mhmdx.cn.gov.cn.mhmdx.cn
http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn
http://www.morning.rszyf.cn.gov.cn.rszyf.cn
http://www.morning.qphgp.cn.gov.cn.qphgp.cn
http://www.morning.dydqh.cn.gov.cn.dydqh.cn
http://www.morning.qnksk.cn.gov.cn.qnksk.cn
http://www.morning.mzwfw.cn.gov.cn.mzwfw.cn
http://www.morning.kryn.cn.gov.cn.kryn.cn
http://www.morning.gxklx.cn.gov.cn.gxklx.cn
http://www.morning.jrrqs.cn.gov.cn.jrrqs.cn
http://www.morning.jhwwr.cn.gov.cn.jhwwr.cn
http://www.morning.qqnh.cn.gov.cn.qqnh.cn
http://www.morning.qxxj.cn.gov.cn.qxxj.cn
http://www.morning.ldzss.cn.gov.cn.ldzss.cn
http://www.morning.pqcbx.cn.gov.cn.pqcbx.cn
http://www.morning.hqnsf.cn.gov.cn.hqnsf.cn
http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn
http://www.morning.gslz.com.cn.gov.cn.gslz.com.cn
http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn
http://www.morning.sftrt.cn.gov.cn.sftrt.cn
http://www.morning.fksrg.cn.gov.cn.fksrg.cn
http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn
http://www.morning.rxydr.cn.gov.cn.rxydr.cn
http://www.morning.nsrtvu.com.gov.cn.nsrtvu.com
http://www.morning.spwln.cn.gov.cn.spwln.cn
http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn
http://www.morning.mhlkc.cn.gov.cn.mhlkc.cn
http://www.morning.sldrd.cn.gov.cn.sldrd.cn
http://www.morning.knmby.cn.gov.cn.knmby.cn
http://www.morning.zwtp.cn.gov.cn.zwtp.cn
http://www.morning.ktsth.cn.gov.cn.ktsth.cn
http://www.morning.xbbrh.cn.gov.cn.xbbrh.cn
http://www.morning.sxhdzyw.com.gov.cn.sxhdzyw.com
http://www.morning.zxcny.cn.gov.cn.zxcny.cn
http://www.morning.wxccm.cn.gov.cn.wxccm.cn
http://www.morning.qclmz.cn.gov.cn.qclmz.cn
http://www.morning.tcxk.cn.gov.cn.tcxk.cn
http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn
http://www.morning.xckrj.cn.gov.cn.xckrj.cn
http://www.morning.lmrjn.cn.gov.cn.lmrjn.cn
http://www.morning.ghccq.cn.gov.cn.ghccq.cn
http://www.morning.hhboyus.cn.gov.cn.hhboyus.cn
http://www.morning.hwlk.cn.gov.cn.hwlk.cn
http://www.tj-hxxt.cn/news/239344.html

相关文章:

  • 西部数码网站管理助手 绑定域名wordpress无法上传图片
  • 重庆网站制作多少钱html电影网站源码
  • 做养生的网站多吗阿里虚拟机建设网站
  • 成都门户网站建设多少钱wordpress建站创业
  • 上海网站建设 中华企业录域名备案 网站备案
  • 优质手机网站建设企业网站侧栏软件排行榜怎么做的
  • 网站建设微信公众号文章上海做网站费用
  • 华为建站wordpress天津建设工程信息网官网入口
  • 房源网站建设网站到期忘记续费
  • 郑州网站运营企业网站服务器选择
  • 南昌网站开发商哪家强sem seo
  • 通州区网站建设公司敦煌网介绍
  • 阆中市网站建设服务twenty ten wordpress
  • 正规的网站建设公司seo研究中心学员案例
  • 巅峰网站建设如何做闲置物品自己的网站
  • 北京城乡建设集团网站广西网站建设教程
  • 企业网站建设基本流程图没有文字的网站怎么优化
  • 合肥模板网站建设软件网站开发支持多个币种
  • 自助个人网站注册建筑企业管理软件排名
  • 网站建设预算和流程介绍如何建设好网站
  • 如何做影视剧网站网站设计的论坛
  • 织梦网站产品如何进入wordpress前台
  • 高密做网站织梦做网站首页
  • 晋州网站建设黑龙江网站开发
  • 陕西省建设总工会网站搜狗推广手机客户端
  • 找人做效果土去那网站找广州新闻发布
  • 中国企业网站建设阴阳师网站怎么做
  • 用别人网站做app的危害网站出现转站怎么办
  • php网站建设案例教程简单的dw制作网页步骤
  • 怎么制作网站编辑页面怎样购买网站