当前位置:网站首页>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
边栏推荐
- 巧用 Bitmap 实现亿级海量数据统计
- 声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
- Vscode+anaconda+jupyter reports an error: kernel did with exit code
- Arrangement of language resources of upgraded version
- 【常见问题】浏览器环境、node环境的模块化问题
- [Note] ab Test and Variance Analysis
- 学校实训要做一个注册页面,要打开数据库把注册页面输入的内容存进数据库但是
- [0x0] open questions left by the principal
- 【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码
- Version correspondence table of tensorflow, CUDA and bazel
猜你喜欢

Redis中的SDS理解
![[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]](/img/c2/13693dcb51aab565957b6c5e686b7c.jpg)
[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]

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

Product thinking - is the future of UAV express worth looking forward to?

(04).NET MAUI实战 MVVM

DO280私有仓库持久存储与章节实验

Simple theoretical derivation of SVM (notes)

Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush

Geometric objects in shapely

1150_ Makefile learning_ Duplicate name target processing in makefile
随机推荐
C#【高级篇】 C# 多线程
Radiant energy, irradiance and radiance
Realization of BFS in C language by storing adjacency matrix of graph
December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
华为云原生——数据开发与DataFactory
【云原生】AI云开发平台——AI Model Foundry介绍(开发者可免费体验AI训练模型)
【论文阅读|深读】DANE:Deep Attributed Network Embedding
Vscode+anaconda+jupyter reports an error: kernel did with exit code
Laravel9 installation locale
【常见问题】页面跨域和接口跨域
4-5 count words and spaces (15 points)
C # [advanced part] C # multithreading
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
How to view Tencent's 2022 school recruitment salary, the total contract of cabbage is 40W?
Neo4j--- performance optimization
【笔记】2022.5.27 通过pycharm操作MySQL
X Book 6.97 shield unidbg calling method
ReSharper 7. Can X be used with vs2013 preview? [off] - can resharper 7 x be used with VS2013 preview? [closed]
GIS related data