当前位置:网站首页>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
边栏推荐
- Impala元数据简介
- C4 学习资料(未完待续)
- Chapter 3 business function development (delete the remarks of market activities)
- JMeter project practice: BeanShell processes the obtained results 64base processing
- Introduction to flex layout
- Impala 3.4的新功能和社区进展
- JS optimization method of double-layer for loop
- [electronic device note 1] resistance parameters and selection
- .NET下IN关键字下多个并列参数的参数化
- 如何在Apache JIRA中搜索issue
猜你喜欢
2022电工(初级)操作证考试题及答案
Flink内核源码(六)状态容错与两阶段提交
Cake cutting problem [Olympiad Mathematics in grade two of primary school]
Summary of important knowledge points of management
TicTacToe three child Lianzhu game (with source code)
3. Editors (vim)
Edge浏览器打开控制台后程序总是停止进入debug模式关闭教程【八仙过海之又一过海方案】
优化yum源之优化base库
Pikachu shooting range SQL injection character injection (get) clearance steps
类型详解(枚举+联合)
随机推荐
How to participate in discussions in impala community
[notes on electronic devices 2] tips for using resistors
动态调整Impala日志级别
Kubernetes 高可用API Server
Optimize the base library of Yum source
Impala查询卡顿分析案例
wx:小程序传值
如何参与Impala社区的讨论
Impala's question answer about a code of valuetransfergraph
在CDH6.3中单独升级Impala到Apache Impala 3.4
Resolution of PIP installation dependency failure
Pikachu shooting range SQL injection character injection (get) clearance steps
低频量化之可转债埋伏配债、埋伏埋伏配债和配债选股策略
Pikachu靶场-SQL注入-数字型注入(post)过关步骤
Impala shell related source code Notes
Solve the error: do not access object prototype method ‘hasOwnProperty‘ from target object no
wet-英语困难户的好选择-控制台翻译
华为机试:单词搜索
C4 学习资料(未完待续)
基于bat+jad.exe实现jar包批量反编译