当前位置:网站首页>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
边栏推荐
- Redis is used in Windows system
- 【常见问题】浏览器环境、node环境的模块化问题
- QT中foreach的使用
- Hisense A7 ink screen mobile phone cannot be started
- Arrangement of language resources of upgraded version
- What are the defaults for Binding. Mode=Default for WPF controls?
- [personal summary] learning plan
- Litjson parses the generated JSON file and reads the dictionary in the JSON file
- Knowledge points of 2022 system integration project management engineer examination: software quality assurance and quality evaluation
- [punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
猜你喜欢

【笔记】2022.5.23 MySQL

Utilisation de foreach en Qt

1150_ Makefile learning_ Duplicate name target processing in makefile

December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society

Hudi record

Is the largest layoff and salary cut on the internet coming?

Number of students from junior college to Senior College (4)

Mysql性能优化(5):主从同步原理与实现

共124篇!墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG)

How to view Tencent's 2022 school recruitment salary, the total contract of cabbage is 40W?
随机推荐
【筆記】AB測試和方差分析
Use of custom MVC
X Book 6.97 shield unidbg calling method
Principle, advantages and disadvantages of three operating modes of dc/dc converter under light load
ReSharper 7. Can X be used with vs2013 preview? [off] - can resharper 7 x be used with VS2013 preview? [closed]
Global and Chinese market of ULTRACENTRIFUGES 2022-2028: Research Report on technology, participants, trends, market size and share
Node-RED系列(二八):基于OPC UA节点与西门子PLC进行通讯
[FAQ] page cross domain and interface Cross Domain
Some common functions and precautions
Global and Chinese market of bulk acoustic wave devices 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of medical mass notification system 2022-2028: Research Report on technology, participants, trends, market size and share
51单片机的室内环境监测系统,MQ-2烟雾传感器和DHT11温湿度传感器,原理图,C编程和仿真
OP diode limit swing
Redis高并发分布式锁(学习总结)
Tidb 6.0: making Tso more efficient tidb Book rush
Use common fileUpload to upload files
I have published a book, "changing life against the sky - the way for programmers to become gods", which is open source. I have been working for ten years. There are 100 life suggestions from technica
Knowledge points of 2022 system integration project management engineer examination: software quality assurance and quality evaluation
Litjson parses the generated JSON file and reads the dictionary in the JSON file
C#【高级篇】 C# 多线程