当前位置:网站首页>NER中BiLSTM-CRF解读score_sentence
NER中BiLSTM-CRF解读score_sentence
2022-06-30 03:34:00 【365JHWZGo】
如果你对下面的内容有疑惑,可能需要看一下我前一篇写的对BiLSTM-CRF的讲解
CRF+BiLSTM代码分步骤解读
讲解
这个函数的作用在于计算出最佳路径的得分,这个和之前那个Forward_algorithm是不同的,主要区别在于score_sentence用于记录当前时刻看来之前一条最佳路径得分,而Forward_algorithm记录的是到达当前时刻之前所有路径的得分。
举例

过程

计算结果️
s c o r e 1 = 0 + t 3 → 0 + e 0 + t 0 → 1 + e 1 + t 1 → 0 + e 0 + t 0 → 2 + e 2 s c o r e 2 = s c o r e 1 + t 2 → 4 score_{1} = 0+t_{3\rightarrow0}+e_0+t_{0\rightarrow1}+e_1+t_{1\rightarrow0}+e_0+t_{0\rightarrow2}+e_2\\ score_{2} = score_{1}+t_{2\rightarrow4} score1=0+t3→0+e0+t0→1+e1+t1→0+e0+t0→2+e2score2=score1+t2→4
代码
def score_sentence(self,e_score, tags):
# e_score (BATCH_SIZE,SEQ_LEN,tags_size) tags (BATCH_SIZE,SEQ_LEN)
# score (BATCH_SIZE,1)
score = torch.zeros((BATCH_SIZE,1),device=device)
# 给每一条标签序列添加开始标签<START> tags (BATCH_SIZE,SEQ_LEN+1)
tags = torch.cat([torch.tensor([self.s2i[START_TAG] for _ in range(BATCH_SIZE)], dtype=torch.long).reshape(BATCH_SIZE,1), tags],dim=-1)
for size in range(BATCH_SIZE):
for i, feat in enumerate(e_score[size]):
score[size] += self.t_score[tags[size,i + 1], tags[size,i]] + feat[tags[size,i + 1]]
score[size] += self.t_score[self.s2i[STOP_TAG], tags[size,-1]]
return score
边栏推荐
- Usage record of unity input system (instance version)
- [punch in - Blue Bridge Cup] day 1 --% 7F format output
- Chapter 2 control structure and function (programming problem)
- 利用反射整合ViewBinding和ViewHolder
- December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society
- Global and Chinese markets for advanced wound care 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of bronze valves 2022-2028: Research Report on technology, participants, trends, market size and share
- 【十分钟】manim安装 2022
- Global and Chinese market of bulk acoustic wave devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 共124篇!墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG)
猜你喜欢

【筆記】AB測試和方差分析

124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)

Wang Shuang - assembly language learning summary

Implementation of property management system with ssm+ wechat applet
![[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII](/img/b2/0059659867e867a32b8e7cef567c8b.jpg)
[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII

MySQL performance optimization (6): read write separation

Linked list: insert a node in the head

General paging (2)

Simple custom MVC optimization

laravel9本地安装
随机推荐
What are the defaults for Binding. Mode=Default for WPF controls?
Huawei interview question: tall and short people queue up
Vscode+anaconda+jupyter reports an error: kernel did with exit code
Redis中的SDS理解
Neo4j---性能优化
Global and Chinese market of medical mass notification system 2022-2028: Research Report on technology, participants, trends, market size and share
Installation and use of yarn
Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯
UML diagrams and list collections
Huawei interview question: divide candy
ReSharper 7. Can X be used with vs2013 preview? [off] - can resharper 7 x be used with VS2013 preview? [closed]
Use of custom MVC
Laravel9 installation locale
MySQL + JSON = King fried
[ten minutes] manim installation 2022
Feign pit
Global and Chinese market of bronze valves 2022-2028: Research Report on technology, participants, trends, market size and share
The 5-year Android development interview took 20 days to join Alibaba
Are you a "social bull" or a "social terrorist" in the interview?
UML图与List集合