GithubHelp home page GithubHelp logo

ner's Introduction

NER

一个中文的实体命名识别系统

当前版本基于双向循环神经网络(BiRNN) + 条件随机场(CRF)来完成实体的标注。 基本思路是利用深度神经网络提取特征,从而避免了手动提取特征的麻烦。 第二部和传统的方式一样,使用CRF在做最后的标注。

该程序使用Tensorflow完成,使用了当前较新的DataSet API,使数据预处理和feed更优雅。

由于使用了新的API, Tensorflow版本必须大于1.2.0,代码升级后使用的是TensorFlow1.4,不确定原来Tensorflow1.2是否还兼容。

如何使用?

   1. 建议安装tensorflow >= 1.4.1

2. 提供训练所需的数据,具体格式在resource文件夹里有展示。但是需要自行分词。只需提供3个文件:
    source.txt target.txt 和 预训练的词向量。
    
3. 训练词向量,训练工具可以是gensim的word2vector或者glove等等,然后将词和对应的词向量以以下格式保存。
    具体格式是: 
    单词A:0.001,0.001,0.001,....
    单词B:0.001,0.001,0.001,....
    单词C:0.001,0.001,0.001,....
    .
    .
    .
    有些训练工具得出的文件结果就是以上格式不需要修改. 程序默认embedding size是300, 可以按需求做更改
    (注意:训练词向量的数据量越大越好,不只限于当前语聊,如果需要训练好的词向量可以联系我。)
    
4. 修改config.py里的文件存路径,所有的配置都在这个文件里。

5. 训练:修改config.py
    tf.app.flags.DEFINE_string("action", 'train', "train | predict")
    $ python rnn.py
    
6. 预测:修改config.py
    tf.app.flags.DEFINE_string("action", 'predict', "train | predict")
    $ python rnn.py

     

注意:    原本resource文件中只包含predict.txt, source.txt, target.txt, 如果更换自己的词向量文件记得删除其他自动生成的文件。

更多文件、问题见issues.

ner's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ner's Issues

rnn预测的时候遇到了问题。

Traceback (most recent call last):
File "/Users/YorkChu/PycharmProjects/NER/rnn.py", line 165, in
net = NER_net("ner", iterator, embedding, BATCH_SIZE)
File "/Users/YorkChu/PycharmProjects/NER/rnn.py", line 26, in init
self._build_net()
File "/Users/YorkChu/PycharmProjects/NER/rnn.py", line 66, in _build_net
self.outputs, self.y, self.seq_length)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 182, in crf_log_likelihood
transition_params)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 109, in crf_sequence_score
false_fn=_multi_seq_fn)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/layers/utils.py", line 206, in smart_cond
pred, true_fn=true_fn, false_fn=false_fn, name=name)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/framework/smart_cond.py", line 59, in smart_cond
name=name)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 432, in new_func
return func(*args, **kwargs)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2063, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1913, in BuildCondBranch
original_result = fn()
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 95, in _single_seq_fn
array_ops.concat([example_inds, tag_indices], axis=1))
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2975, in gather_nd
"GatherNd", params=params, indices=indices, name=name)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1734, in init
control_input_ops)
File "/Users/YorkChu/dev/anaconda3/envs/py2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1570, in _create_c_op
raise ValueError(str(e))
ValueError: indices.shape[-1] must be <= params.rank, but saw indices shape: [?,11] and params shape: [1,16] for 'ner/cond/GatherNd' (op: 'GatherNd') with input shapes: [1,16], [?,11].

遇到了一个问题,一直不知道怎么解决

Traceback (most recent call last):
File "rnn.py", line 153, in
embedding = load_word2vec_embedding(vocab_size)
File "/home/gmy/NER-master/utils.py", line 263, in load_word2vec_embedding
embeddings[index] = cofes # 将词和对应的向量存到字典里
ValueError: could not broadcast input array from shape (0) into shape (300)

不知道怎么回事。 谢谢

兄弟一直报这个错,能帮忙看一下吗

OutOfRangeError (see above for traceback): Read fewer bytes than requested
[[Node: index_to_string/table_init = InitializeTableFromTextFileV2[delimiter="\t", key_index=-1, value_index=-2, vocab_size=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](index_to_string, string_to_index/hash_table/table_init/asset_filepath)]]

请教

B-ORG B-LOC B-TIME I-TIME O B-ORG O B-ORG O B-ORG O B-ORG B-TIME
这些你是怎么标注下来的?是你自己标注的吗?还是本身就有的开源数据,我现在想构造与一个特定领域的命名实体程序,请问一下,可以怎么去利用你的这个程序,谢谢

IndexError: index 2 is out of bounds for axis 0 with size 2

Traceback (most recent call last):
File "E:/python-files/NER/rnn.py", line 153, in
embedding = load_word2vec_embedding(vocab_size)
File "E:\python-files\NER\utils.py", line 264, in load_word2vec_embedding
embeddings[index] = coefs # 将词和对应的向量存到字典里
IndexError: index 2 is out of bounds for axis 0 with size 2
请问一下作者,这个问题怎么解决啊,弄了半天,不知道怎么办?

流程可以稍微讲一下吗

感谢码主,不过可以给config文件里面的各种文件和作用注释一下吗,新手看了根本一头雾水呀,看不懂源码也捋不清各个文件的作用和从头到尾的流程。希望楼主能改进一下,给你加星了。

运行rnn出现问题

Traceback (most recent call last):
File "G:/NER-master/Rnn.py", line 152, in
embedding = load_word2vec_embedding(vocab_size)
File "G:\NER-master\utils.py", line 265, in load_word2vec_embedding
embeddings[index] = coefs # 将词和对应的向量存到字典里
IndexError: index 2 is out of bounds for axis 0 with size 2

求解答

预测时报这个错误

File "D:\App\novel\NER\rnn.py", line 166, in
net = NER_net("ner", iterator, embedding, BATCH_SIZE)
File "D:\App\novel\NER\rnn.py", line 26, in init
self._build_net()
File "D:\App\novel\NER\rnn.py", line 66, in _build_net
self.outputs, self.y, self.seq_length)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 182, in crf_log_likelihood
transition_params)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 109, in crf_sequence_score
false_fn=_multi_seq_fn)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\layers\utils.py", line 206, in smart_cond
pred, true_fn=true_fn, false_fn=false_fn, name=name)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\smart_cond.py", line 60, in smart_cond
name=name)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\util\deprecation.py", line 432, in new_func
return func(*args, **kwargs)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2047, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 1897, in BuildCondBranch
original_result = fn()
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 95, in _single_seq_fn
array_ops.concat([example_inds, tag_indices], axis=1))
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 3414, in gather_nd
"GatherNd", params=params, indices=indices, name=name)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3292, in create_op
compute_device=compute_device)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3332, in _create_op_helper
set_shapes_for_outputs(op)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2496, in set_shapes_for_outputs
return _set_shapes_for_outputs(op)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2469, in _set_shapes_for_outputs
shapes = shape_func(op)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2399, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn
require_shape_fn)
File "C:\Users\qiand\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 691, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: indices.shape[-1] must be <= params.rank, but saw indices shape: [?,11] and params shape: [1,16] for 'ner/cond/GatherNd' (op: 'GatherNd') with input shapes: [1,16], [?,11].

数据量大求指导

Traceback (most recent call last):
File "D:/rnn_lstm/rnn.py", line 153, in
embedding = load_word2vec_embedding(vocab_size)
File "D:\rnn_lstm\utils.py", line 285, in load_word2vec_embedding
initializer=tf.constant_initializer(embeddings), trainable=False)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1203, in get_variable
constraint=constraint)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1092, in get_variable
constraint=constraint)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 425, in get_variable
constraint=constraint)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 394, in _true_getter
use_resource=use_resource, constraint=constraint)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 805, in _get_single_variable
constraint=constraint)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variables.py", line 213, in init
constraint=constraint)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variables.py", line 303, in _init_from_args
initial_value(), name="initial_value", dtype=dtype)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 779, in
shape.as_list(), dtype=dtype, partition_info=partition_info)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\ops\init_ops.py", line 200, in call
self.value, dtype=dtype, shape=shape, verify_shape=verify_shape)
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 208, in constant
value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 447, in make_tensor_proto
"Cannot create a tensor proto whose content is larger than 2GB.")
ValueError: Cannot create a tensor proto whose content is larger than 2GB.

GPU使用率太低

模型跑通了,但GPU使用率不超过20%,请问可能是什么问题导致的?

标注类型问题

O
B-LOC
I-TIME
B-ORG
I-CRIME
B-PER
I-ORG
B-TIME
B-ROLE
B-CRIME
I-PER
I-LAW
I-LOC
I-ROLE
B-LAW

具体有这些类别,但具体表示的什么,大神可以做个备注吗?

预测速度缓慢的小伙伴们看过来!

rnn.py 的138~139行改为:
tags = sess.run(tag_table.lookup(tf.constant(viterbi_sequence, dtype=tf.int64)))

作者循环执行run,导致预测及其缓慢。。
不过还是感谢作者

训练报错

使用你给我的wiki.zh.vec训练时,出现以下报错

building word index...
source vocabulary file has already existed, continue to next stage.
loading word embedding, it will take few minutes...
Traceback (most recent call last):
File "rnn.py", line 153, in
embedding = load_word2vec_embedding(vocab_size)
File "/root/NER/utils.py", line 264, in load_word2vec_embedding
embeddings[index] = coefs # 将词和对应的向量存到字典里
IndexError: index 391175 is out of bounds for axis 0 with size 391175

正确率太低

在网上找了100维的词向量,不知道是因为维数太低还是其他原因,测试时放进去的句子几乎都识别不出来,把训练用的句子放进去也是错误的,请问哪里应该调整?

越界

tensorflow.python.framework.errors_impl.OutOfRangeError
2018-07-13 16 00 47

为啥语料换成我自己的就不行了。。

您好我用您给的source和target是可以训练的,但是有个问题是换成我自己的就不行了。我之前用crf进行sequence labling,写了个脚本把之前的语料处理了一下变成您的格式,语料和标注的格式跟您的完全一样,训练的时候也没有报错,就是没有反应。我开始以为是太多了,后来我取了几十k的测试,还是没反应,请问您碰到过吗

HashTable has different value for same key

错误信息:HashTable has different value for same key. Key 提交的維基人及時間: has 249 and trying to add value 5693
请问下,在训练的时候报这个错误,如何解决?

这个训练要多大内存啊

我用的前几个issue里作者回复的预训练词向量,结果在训练程序开始之前就迅速爆掉了。可是按理说,这个向量文件的大小都才1.3G左右,会一瞬间撑爆8G内存吗?

使用predict模式测试训练数据出现报错.

不知道什么意思.
building word index...
loading word embedding, it will take few minutes...
WARNING:tensorflow:From /root/NER/utils.py:210: init (from tensorflow.contrib.data.python.ops.readers) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.data.TextLineDataset.
Traceback (most recent call last):
File "rnn.py", line 166, in
net = NER_net("ner", iterator, embedding, BATCH_SIZE)
File "rnn.py", line 26, in init
self._build_net()
File "rnn.py", line 66, in _build_net
self.outputs, self.y, self.seq_length)
File "/usr/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 201, in crf_log_likelihood
transition_params)
File "/usr/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 128, in crf_sequence_score
fn2=_multi_seq_fn)
File "/usr/lib/python2.7/site-packages/tensorflow/python/layers/utils.py", line 211, in smart_cond
return control_flow_ops.cond(pred, true_fn=fn1, false_fn=fn2, name=name)
File "/usr/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 316, in new_func
return func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1894, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1752, in BuildCondBranch
original_result = fn()
File "/usr/lib/python2.7/site-packages/tensorflow/contrib/crf/python/ops/crf.py", line 114, in _single_seq_fn
array_ops.concat([example_inds, tag_indices], axis=1))
File "/usr/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2000, in gather_nd
"GatherNd", params=params, indices=indices, name=name)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3162, in create_op
compute_device=compute_device)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3208, in _create_op_helper
set_shapes_for_outputs(op)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2427, in set_shapes_for_outputs
return _set_shapes_for_outputs(op)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2400, in _set_shapes_for_outputs
shapes = shape_func(op)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2330, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn
require_shape_fn)
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: indices.shape[-1] must be <= params.rank, but saw indices shape: [?,11] and params shape: [1,16] for 'ner/cond/GatherNd' (op: 'GatherNd') with input shapes: [1,16], [?,11].

关于如何运行的问题

首先感谢兄dei提供的工程,我对RNN不太了解,我想知道这个工程 如何能运行起来,然后来研究流程

我的准备情况是这样,我在pydev建立的工程 语法py2.7,解释器是py3.6(已装好TensorFlow),这样不用去修改print 但是报错的地方依然是utils.py中的47行if type(word) is unicode: 我修改为 if isinstance(word,str)==True:

在resource文件夹中把兄dei网盘中的wiki.zh.vec放在里面,加上原先的3个txt 就是这4个文件
config.py 中 我先把action中的predict改成了 train 试着能否运行 结果是不能运行

所以兄dei能告诉我 正确的运行方法吗,真的很想知道

运行问题

运行train时出现以下错误提示:何解?

absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --src_file before flags were parsed.

你好数组下标问题

Traceback (most recent call last):
File "F:/PyCharm Community Edition 2018.1/Project/venv/rnn.py", line 153, in
embedding = load_word2vec_embedding(vocab_size)
File "F:\PyCharm Community Edition 2018.1\Project\venv\utils.py", line 268, in load_word2vec_embedding
embeddings[index] = coefs # 将词和对应的向量存到字典里
IndexError: index 2 is out of bounds for axis 0 with size 2

预测完全错误的问题

我在训练时程序运行正常,但是在预测的过程中出现以下错误

building word index...
source vocabulary file has already existed, continue to next stage.
target vocabulary file has already existed, continue to next stage.
loading word embedding, it will take few minutes...
2018-04-14 08:29:30.012808: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
D:\ProgramData\Miniconda3\envs\tensorflow35\lib\site-packages\tensorflow\python\ops\gradients_impl.py:96: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "

loading pre-trained model from resource/model/points-10000.....
['新华社', '北京', '9', '月', '11', '日电', '第二十二届', '国际', '检察官', '联合会', '年会', '暨', '会员', '代表大会', '11', '日', '上午', '在', '北京', '开幕', '。', '国家', '主席', '***', '发来', '贺信', ',', '对', '会议', '召开', '表示祝贺', '。']
[b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'O', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'', b'']
32
33
Traceback (most recent call last):
File "E:/NER-master/rnn.py", line 180, in
predict(net, tag_table, sess)
File "E:/NER-master/rnn.py", line 140, in predict
write_result_to_file(file_iter, tags)
File "E:\NER-master\utils.py", line 297, in write_result_to_file
assert len(words) == len(tags)
AssertionError

发现预测的结果不是O就是unknown,而且也报了长度不一致的错误,请问这种情况应该怎样解决。

双向RNN计算的长度问题

双向RNN里边需要传递batch里边每一条数据的确切长度,不然backward的结果完全就是错误的,费了好长时间才发现这个问题,麻烦请及时更正。

tf.nn.bidirectional_dynamic_rnn(cell_fw, cell_bw, seq, seq_length, initial_state_fw,initial_state_bw)

训练后使用预测模型跑报参数错误

请教下在同一套代码训练和预测的,为什么训练后去预测会保证错呢
WARNING:tensorflow:From D:\workspace\python_project\NER\package\utils.py:210: TextLineDataset.init (from tensorflow.contrib.data.python.ops.readers) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.data.TextLineDataset.
Traceback (most recent call last):
File "D:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 686, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices.shape[-1] must be <= params.rank, but saw indices shape: [?,11] and params shape: [1,16] for 'ner/cond/GatherNd' (op: 'GatherNd') with input shapes: [1,16], [?,11].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:/workspace/python_project/NER/package/rnn.py", line 168, in
net = NER_net("ner", iterator, embedding, BATCH_SIZE)
File "D:/workspace/python_project/NER/package/rnn.py", line 28, in init
self._build_net()
File "D:/workspace/python_project/NER/package/rnn.py", line 68, in _build_net
self.outputs, self.y, self.seq_length)
File "D:\Python35\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 201, in crf_log_likelihood
transition_params)
File "D:\Python35\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 128, in crf_sequence_score
fn2=_multi_seq_fn)
File "D:\Python35\lib\site-packages\tensorflow\python\layers\utils.py", line 211, in smart_cond
return control_flow_ops.cond(pred, true_fn=fn1, false_fn=fn2, name=name)
File "D:\Python35\lib\site-packages\tensorflow\python\util\deprecation.py", line 316, in new_func
return func(*args, **kwargs)
File "D:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 1894, in cond
orig_res_t, res_t = context_t.BuildCondBranch(true_fn)
File "D:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 1752, in BuildCondBranch
original_result = fn()
File "D:\Python35\lib\site-packages\tensorflow\contrib\crf\python\ops\crf.py", line 114, in _single_seq_fn
array_ops.concat([example_inds, tag_indices], axis=1))
File "D:\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2567, in gather_nd
"GatherNd", params=params, indices=indices, name=name)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3162, in create_op
compute_device=compute_device)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3208, in _create_op_helper
set_shapes_for_outputs(op)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2427, in set_shapes_for_outputs
return _set_shapes_for_outputs(op)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2400, in _set_shapes_for_outputs
shapes = shape_func(op)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2330, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn
require_shape_fn)
File "D:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 691, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: indices.shape[-1] must be <= params.rank, but saw indices shape: [?,11] and params shape: [1,16] for 'ner/cond/GatherNd' (op: 'GatherNd') with input shapes: [1,16], [?,11].

预测时words length 与tag length不一致,如下:

Traceback (most recent call last):
File "/root/pycharm/NER-master/rnn.py", line 181, in
predict(net, tag_table, sess)
File "/root/pycharm/NER-master/rnn.py", line 142, in predict
write_result_to_file(file_iter, tags)
File "/root/pycharm/NER-master/utils.py", line 291, in write_result_to_file
assert len(words) == len(tags)
AssertionError

词向量的问题

输入wiki.zh.vec作为与训练的词向量,我发现这个里面词向量的长度有300,301,这样在load_word2vec_embedding中就会进入到
except ValueError:
# 如果真的这个词出现在了训练数据里,这么做就会有潜在的bug。那coefs的值就是上一轮的值。
print values[0], values[1:]
那么在train或者predict的时候,就会提示一个key含有多个不一样的值这样的问题,导致训练不能进行
HashTable has different value for same key
请问这个该怎么解决呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.