当前位置:网站首页>Interpretation score of bilstm-crf in NER_ sentence
Interpretation score of bilstm-crf in NER_ sentence
2022-06-30 03:48:00 【365JHWZGo】
If you have any doubts about the following , You may need to read what I wrote in my previous article BiLSTM-CRF Explanation
CRF+BiLSTM The code is interpreted step by step
Explain
This function is used to calculate the score of the best path , This is the same as the previous one Forward_algorithm Is different , The main difference is that score_sentence It is used to record the score of the previous best path at the current time , and Forward_algorithm It records the scores of all paths before reaching the current time .
give an example

The process

The result of the calculation is ️
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
Code
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)
# Add a start tag to each tag sequence <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
边栏推荐
猜你喜欢

【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码

巧用 Bitmap 实现亿级海量数据统计

Laravel9 installation locale

Buffer pool of MySQL notes
![[note] May 23, 2022 MySQL](/img/a1/dd71610236729e1d25c4c3e903c0e0.png)
[note] May 23, 2022 MySQL

Redis中的Hash设计和节省内存数据结构设计

Arrangement of language resources of upgraded version

Stc89c52/90c516rd/89c516rd DHT11 temperature and humidity sensor drive code

1152_ Makefile learning_ Pattern matching rules

Redis is used in Windows system
随机推荐
[note] Introduction to data analysis on June 7, 2022
X Book 6.97 shield unidbg calling method
laravel9本地安裝
C#【高级篇】 C# 接口(Interface)
Vscode+anaconda+jupyter reports an error: kernel did with exit code
Half a year after joining the company, I was promoted to a management post
如何通过进程启动来分析和解决EasyCVR内核端口报错问题?
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
【常见问题】页面跨域和接口跨域
第2章 控制结构和函数(编程题)
[frequently asked questions] modularization of browser environment and node environment
SDS understanding in redis
1151_ Makefile learning_ Static matching pattern rules in makefile
Semantic segmentation resources
[0x0] open questions left by the principal
What does the hyphen mean for a block in Twig like in {% block body -%}?
51单片机的室内环境监测系统,MQ-2烟雾传感器和DHT11温湿度传感器,原理图,C编程和仿真
Linear interpolation of spectral response function
ReSharper 7. Can X be used with vs2013 preview? [off] - can resharper 7 x be used with VS2013 preview? [closed]
Hudi record