当前位置:网站首页>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 实现亿级海量数据统计
- 如何利用FME 创建自己的功能软件
- Feign pit
- December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society
- [punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]
- dotnet-exec 0.5.0 released
- 124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)
- Implementation of property management system with ssm+ wechat applet
- 绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
- GIS related data
猜你喜欢

1148_ Makefile learning_ Targets, variables, and wildcards in makefile

Simple theoretical derivation of SVM (notes)

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

51 single chip microcomputer indoor environment monitoring system, mq-2 smoke sensor and DHT11 temperature and humidity sensor, schematic diagram, C programming and simulation

From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years

【笔记】2022.5.27 通过pycharm操作MySQL

The jupyter notebook kernel hangs up frequently and needs to be restarted

unity input system 使用记录(实例版)

dbt产品初体验

【论文阅读|深读】Role2Vec:Role-Based Graph Embeddings
随机推荐
Number of students from junior college to Senior College (4)
C [advanced] C interface
[note] on May 27, 2022, MySQL is operated through pychart
Product thinking - is the future of UAV express worth looking forward to?
【笔记】2022.6.7 数据分析概论
Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code
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
利用反射整合ViewBinding和ViewHolder
巧用 Bitmap 实现亿级海量数据统计
[FAQ] page cross domain and interface Cross Domain
Local, locallow and roaming in the appdata folder
王爽-汇编语言 万字学习总结
[punch in - Blue Bridge Cup] day 5 --- lower() small
[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]
共124篇!墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG)
If you can tell whether the external stock index futures trading platform I am trading is formal and safe?
[note] on May 28, 2022, data is obtained from the web page and written into the database
C#【高级篇】 C# 泛型(Generic)【需进一步补充:泛型接口、泛型事件的实例】
dbt产品初体验
laravel9本地安裝