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

深圳建网站的公公司变更登记申请书下载

深圳建网站的公,公司变更登记申请书下载,怎么选择锦州网站建设,建设企业银行登录NLP实践——知识图谱问答模型FiD0. 简介1. 模型结构2. 召回3. 问答4. 结合知识的问答0. 简介 好久没有更新了#xff0c;今天介绍一个知识图谱问答#xff08;KBQA#xff09;模型#xff0c;在此之前我一直在用huggingface的Pipeline中提供的QA模型#xff0c;非常方便但… NLP实践——知识图谱问答模型FiD0. 简介1. 模型结构2. 召回3. 问答4. 结合知识的问答0. 简介 好久没有更新了今天介绍一个知识图谱问答KBQA模型在此之前我一直在用huggingface的Pipeline中提供的QA模型非常方便但是准确性不是特别好。今天介绍的这个模型是Facebook在2021年就已经提出来的FiDFusion-in-Decoder发表在ACL上。 论文地址 https://aclanthology.org/2021.eacl-main.74.pdf 项目地址https://github.com/facebookresearch/FiD 其实我原本是想看EMNLP2022中的一篇文章也已经开源。这个项目叫Grape其基本思想实在FiD的基础上采用两个T5 Encoder并且在解码之前利用query和候选文本中的实体构建GNN在节点上做了Attention以增强Encoder的表征。 论文地址 https://arxiv.org/pdf/2210.02933.pdf 但是grape的这个项目我在实验的时候遇到了一点环境配置上的问题作者采用了一个比较冷门的dgl版本这个版本在Linux_x86_64系统上没有官方编译过于是我尝试自己编译又遇到了一堆cmake和gcc版本的问题于是放弃尝试。但顺着Grape的论文找到了FiD这一项目。 1. 模型结构 所谓KBQA也就是在问答模型的基础上除了给定原文的信息之外还考虑知识库中其他的预料信息。这个模型的原理很简单就是一个生成模型加上召回任务。 也就是先利用一个召回模型在知识库中召回若干与给定的原文相关的文本然后再将问题分别与原文以及相关文本进行拼接拼接后的结果分别进行编码再将编码的结果进行concat最终把concat的结果给到Decoder由Decoder生成答案。 采用的基础模型是T5分别在两个数据集NaturalQuestions和TriviaQA上进行了训练数据和训练好的模型均可在git上找到。 2. 召回 召回这部分其实没有什么东西在官方的git中就是采用bert-base做了一下编码我没有跟着它的做法感兴趣的同学可以自行阅读retrieval相关的py文件。 这里我是觉得自己编码更方便一些可以直接采用Sentence transformer的预训练模型或者你自己训练的什么编码模型另外做成faiss或者milvus索引的话效率还会高不少。关于Sentence transformer在好久之前的这篇博客中也介绍过。 3. 问答 虽然这个模型是KBQA模型但是git上似乎也没有直接给出Fusion的那部分代码。这里我们不妨自己先写一个预测方法利用它训练好的模型来实现QA的功能。 由于它本身其实就是一个T5模型所以只要你对transformers模块比较熟悉的话可以很轻易的写出预测方法。 首先我们加载一下模型和tokenizer from transformers import AutoTokenizer from src.model import FiDT5 # 注意引用时的目录引不进来就直接把这个类复制过来# 从git上下载你想要尝试的模型比如nq把文件都放在一个目录里然后用from_pretrained读取它 model FiDT5.from_pretrained(your_path_to_Fid_model/nq_reader_base/) tokenizer AutoTokenizer.from_pretrained(t5-large) # 联网下载或提前下载好放在本地目录# 然后eval一下关掉dropout和BN如果你比较叛逆不关也是可以的 model.eval()接下来我们写一个简单的预测方法就可以实现QA了。 def predict(model, tokenizer, question, title, context, devicecpu):预测:param model: T5模型:param tokenizer: 分词器:param question: 问题:param title: 标题没有的话可以给空字符:param context: 正文:param device: 在cpu还是cuda上执行---------------ver: 2023-01-12by: changhongyuif device.startswith(cuda):model.to(device)combined_text question: question title: title context: contextinputs tokenizer(combined_text, max_length1024, return_tensorspt)test_outputs model.generate(input_idsinputs[input_ids].unsqueeze(0).to(device),attention_maskinputs[attention_mask].unsqueeze(0).to(device),max_length50,)answer tokenizer.decode(test_outputs[0])return answer来测试一下效果 predict(model, tokenizer,Who is Russias new commander,Russia Ukraine War Live Updates: Russia changes commanders again in Ukraine,09:20 (IST) Jan 12 Ukrainian military analyst Oleh Zhdanov said the situation in Soledar was approaching that of critical The Ukrainian armed forces are holding their positions. About one half of the town is under our control. Fierce fighting is going on near the town centre, he said on YouTube.However, Zhdanov told Ukrainian television that if Russian forces seized Soledar or nearby Bakhmut it would be more a political victory than military. 09:18 (IST) Jan 12 Russian private military firm Wagner Group said its capture of the salt mining town Soledar in eastern Ukraine was complete- a claim denied by Ukraine 09:08 (IST) Jan 12 Russia changes commanders again in Ukraine Moscow named a new commander for its invasion of Ukraine. Russian Defence Minister Sergei Shoigu on Wednesday appointed Chief of the General Staff Valery Gerasimov as overall commander for what Moscow calls its special military operation in Ukraine, now in its 11th month.The change effectively demoted General Sergei Surovikin, who was appointed only in October to lead the invasion and oversaw heavy attacks on Ukraines energy infrastructure. 06:40 (IST) Jan 12 Russia, Ukraine agree new prisoner swap in Turkey Russia and Ukraine on Wednesday agreed a new prisoner swap during rare talks in Turkey during which they also discussed the creation of a humanitarian corridor in the war zone. Ukraines human rights ombudsman Dmytro Lubinets met his Russian counterpart Tatyana Moskalkova on the sidelines of an international conference in Ankara attended by Turkish President Recep Tayyip Erdogan. 06:39 (IST) Jan 12 President Volodymyr Zelenskyy urged NATO on Wednesday to do more than just promise Ukraine its door is open at a July summit, saying Kyiv needs powerful steps as it tries to join the military alliance. 06:39 (IST) Jan 12 Russian forces shelled 13 settlements in and around Kharkiv region largely returned to Ukrainian hands in September and October, the Ukrainian military said. 06:38 (IST) Jan 12 Russias war on Ukraine latest: Russia puts top general in charge of invasion Russia ordered its top general on Wednesday to take charge of its faltering invasion of Ukraine in the biggest shake-up yet of its malfunctioning military command structure after months of battlefield setbacks. 06:37 (IST) Jan 12 Zelenskyy says Russian war wont become WWIII Ukraine will stop Russian aggression and the conflict wont turn into World War III, President Volodymyr Zelenskiy said as his forces battled to keep control of Soledar and Bakhmut in the eastern Donetsk region. The Kremlin had positioned the most experienced units from the Wagner military-contracting company near Soledar, according to Ukrainian operational command spokesman Serhiy Cherevatyi. )模型给出的回答符合预期 Valery Gerasimov4. 结合知识的问答 官方的代码中好像没有给出这部分内容所以我根据论文的思路简单实现了一下简而言之就是在召回之后将目标文档的编码结果与召回的参考文档的编码结果进行拼接然后再统一进行解码即可。 def predict_with_reference(model, tokenizer, question, title, context, reference_title, reference_context, devicecpu):预测:param model: T5模型:param tokenizer: 分词器:param question: 问题:param title: 标题没有的话可以给空字符:param context: 正文:param reference_title: 召回文本的标题:param reference_context: 召回文本的正文:param device: 在cpu还是cuda上执行---------------ver: 2023-01-12by: changhongyuif device.startswith(cuda):model.to(device)combined_text question: question title: title context: contextcombined_refer question: question title: reference_title context: reference_contextquery_inputs tokenizer(combined_text, max_length1024, return_tensorspt)refer_inputs tokenizer(combined_refer, max_length1024, return_tensorspt)test_outputs model.generate(input_idstorch.cat([query_inputs[input_ids].unsqueeze(0), refer_inputs[input_ids].unsqueeze(0)], dim2).to(device),attention_masktorch.cat([query_inputs[attention_mask].unsqueeze(0), refer_inputs[attention_mask].unsqueeze(0)], dim2).to(device),max_length50,)answer tokenizer.decode(test_outputs[0])return answer然后来测试一下效果 假设我们有一篇地震相关的新闻 text The death toll in Syria and Turkey from the earthquake has passed 12,000, with the number of injured exceeding 100,000, while hundreds of thousands have been displaced. In Turkey, at least 9,000 have been killed and nearly 60,000 people have been injured, authorities said on Wednesday. The death toll in Syria stands at more than 3,000, according to the Syrian Observatory for Human Rights, while Syrian state media reported more than 298,000 people have been displaced.以及在知识库里召回的一篇叙相关的介绍 reference Syria (Arabic: سوريا‎, romanized: Sūriyā), officially the Syrian Arab Republic (Arabic: الجمهورية العربية السورية‎, romanized: al-Jumhūrīyah al-ʻArabīyah as-Sūrīyah), is a country in Western Asia, bordering Lebanon to the southwest, the Mediterranean Sea to the west, Turkey to the north, Iraq to the east, Jordan to the south, and Israel to the southwest. A country of fertile plains, high mountains, and deserts, Syria is home to diverse ethnic and religious groups, including Syrian Arabs, Kurds, Turkemens, Assyrians, Armenians, Circassians, Mandeans and Greeks. Religious groups include Sunnis, Christians, Alawites, Druze, Ismailis, Mandeans, Shiites, Salafis, Yazidis, and Jews. Arabs are the largest ethnic group, and Sunnis the largest religious group.然后进行问答 predict_with_reference(model, tokenizer,questionwhere is Syria.,titleEarthquake death toll exceeds 12,000 as Turkey, Syria seek help.,contexttext,reference_titleSyria,reference_contextreference, )模型给出的回答是 Western Asia答案也是符合预期的。 如果是召回多篇文档理论上将predict_with_reference这个方法的reference都改成list然后再拼接的时候把结果组合起来就可以了感兴趣的同学可以自己尝试一下。 以上就是本文的全部内容了在ChatGPT时代下KBQA这个话题似乎有点“过时”了但是这对于练习NLP基础任务和理解attention的运作还是很有帮助的。如果这篇文章对你有帮助欢迎一键三连加关注也欢迎评论区或私信交流我们下期再见。
http://www.w-s-a.com/news/35823/

相关文章:

  • 卧龙区网站建设国内漂亮网站欣赏
  • 服装 网站模板 wordpress石家庄做网站的公司有哪些
  • 惠州技术支持网站建设百度怎样注册免费的网站
  • 无锡哪里有做网站的公司泸州网站建设公司
  • 怎么进行网站推广jsp可以做那些小网站
  • 懒人手机网站wordpress修改秒速
  • WordPress资讯网站用花生壳做网站
  • 关于营销方面的网站建设网站怎么克隆
  • 站长网seo综合查询工具电商公司简介
  • 全能网站建设教程广告制作公司需要什么设备
  • 汽车行业做网站网站改版seo建议
  • 建设职业注册中心网站photoshop属于什么软件
  • 公司网站展示有哪些wordpress工单
  • iis新建网站seo是做什么工作的
  • 临沂网站建设厂家做外贸的女生现状
  • 电子商务网站建设实践临沂做网站的
  • 网站职能建设论文做外贸都有哪些网站
  • 网站建设项目需求分析房地产网站源码
  • 网站充值提现公司账务怎么做中国能建设计公司网站
  • 网站信息资源建设包括哪些网站网站做维护
  • 网站性能优化的方法有哪些建设施工合同网站
  • 郑州建设企业网站山西省住房和城乡建设厅网站
  • 做网站的去哪找客户正规制作网站公司
  • 网站代理访问是什么意思外国优秀设计网站
  • 合肥个人建站模板网络技术服务有限公司
  • 做网站什么公司好dw企业网站开发教程
  • 怎么做自己的个人网站宝安网站设计哪家最好
  • 浩博建设集团网站站长网站统计
  • 电商网站开发视频seo排名优化方式方法
  • 宿迁市住房城乡建设局网站wordpress纯图片主题