当前位置:网站首页>Conversion code from "implementation details" character index to word index
Conversion code from "implementation details" character index to word index
2022-07-20 11:19:00 【365JHWZGo】
Example
In the reading comprehension task , The answer is often to give the index of the starting position of the character , Such as SQuAD1.1 An example of a dataset is as follows .
context:
Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi’s Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the “golden anniversary” with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as “Super Bowl L”), so that the logo could prominently feature the Arabic numerals 50.
answer:
however , This answer_start It is often not the index we need , So we need to turn it into Denver Broncos In this context Word index position in .
Code
context:
she loves this puppy.
question:
what does this girl love?
answer:
puppy
answer_start:
15
tokens:
[‘she’,‘loves’,‘this’,‘puppy’,‘.’]
punctuations:
[’ ‘,’\n’]
idx = 0
flag = False
s_idx = answer_start
e_idx = s_idx + len(answer)
for i,t in enumerate(tokens):
# Calculation contains spaces 、 Characters including line breaks
while idx < len(context):
if context[idx] in punctuations:
idx += 1
else:
break
# Count the length of the word
idx += len(t)
if idx > s_idx and flag == False:
# The starting position of the word sequence
s_idx = i
flag = True
if idx >= e_idx:
# End position of word sequence
e_idx = i
break
边栏推荐
- Pip安装依赖失败的解决
- Personal test online examination of operation version Online_ Testck163 2.7.18 powerful online examination module
- 利用SQL注入漏洞实习读写文件
- 2022/7/17 每日一题(构造+数学+贪心+指针)
- Comparator sorted pit
- JS optimization method of double-layer for loop
- Edge浏览器打开控制台后程序总是停止进入debug模式关闭教程【八仙过海之又一过海方案】
- One question per day on July 16, 2022 (structure)
- Kubernetes highly available API server
- C4 学习资料(未完待续)
猜你喜欢
Codeforces Round #808 (Div. 2)(A,B,C)
H5 introduction of Web debugging tools and vconsole
《实现细节》字符索引向字词索引的转化代码
Introduction to impala metadata
Comparator排序的坑
Codeforces Round #807 (Div. 2)(A.B.C)
动态调整Impala日志级别
wet-英语困难户的好选择-控制台翻译
[vector space]
Chapter 3 business function development (delete the remarks of market activities)
随机推荐
二叉树的最近公共祖先
Optimisation de la Bibliothèque de base pour les sources Yum
JMeter project practice: BeanShell processes the obtained results 64base processing
哈希表(散列表)和哈希冲突
Personal test online examination of operation version Online_ Testck163 2.7.18 powerful online examination module
如何将数据从客户端通过copy命令导入优炫数据库
JDBC connection MySQL loading class `com mysql. jdbc. Driver‘. This is deprecated
Impala元数据简介
Scala Basics
ikbc键盘win键失效的解决方法
2022P气瓶充装考试题库及答案
蓝桥杯单片机国二经验分享
Assimp库中文文档
wet-英语困难户的好选择-控制台翻译
One question per day on July 16, 2022 (structure)
Kubernetes 高可用API Server
Resolution of PIP installation dependency failure
优化yum源之优化base库
Impala 2.x的新patch -- IMPALA-6812 Kudu Read Mode
Impala元数据缓存的生命周期