命名实体识别的学习代码选择的是github上star最多的代码:A very simple BiLSTM-CRF model for Chinese Named Entity Recognition 中文命名实体识别 (TensorFlow)。 这也算是学习的第一个大点儿的tf项目吧。
配合源码作者的博客BiLSTM-CRF模型做基于字的中文命名实体识别
模型如下图。
一、model.py文件主要是构建模型——类BiLSTM_CRF。
add_placeholders方法添加占位符。 这里讲一下tf中占位符的作用。tf.constant用来定义常量。那么tf中变量如何定义呢?就用到了tf.placeholder() 和 feed_dict。
x = tf.placeholder(tf.string)
with tf.Session() as sess:
output = sess.run(x, feed_dict={x: 'Hello World'})
tf.placeholder表示一个占位符,至于是什么类型,看自己定义了,这里定义的是tf.string类型,然后呢,在session开始run以前&#x