jiaqianghuai / tf-lstm-crf-batch Goto Github PK
View Code? Open in Web Editor NEWTensorflow-LSTM-CRF tool for Named Entity Recognizer
Tensorflow-LSTM-CRF tool for Named Entity Recognizer
I am trying to use your code for experiment, but error appeared:
from utils import iob2, iob_iobes
ImportError: cannot import name iob2
And I checked it that no iob2, iob_iobes exist in the util.py file.
I need your help, thank you.
Environment:
Ubuntu 16.04
Python 2.7.12
TensorFlow 1.4.0 on CPU
Running train.py with attached crf_train.txt and crf_test.txt.
crf_test.txt
crf_train.txt
Got the following error:
eek@ubuntu:~/polygon/tf-lstm-crf-batch$ python train.py --train ./data/crf_train.txt --dev ./data/crf_test.txt --test ./data/crf_test.txt --mode=1
Model location: ./models/lower=False,zeros=False,char_dim=25,char_lstm_dim=25,char_bidirect=True,word_dim=100,word_lstm_dim=100,word_bidirect=True,crf=True,dropout=0.0,lr_method=sgd,lr_rate=0.005,clip_norm=0.0,is_train=1,batch_size=20
Found 145 unique words (1245139 in total)
Found 143 unique characters
Found 4 unique named entity tags
26695 / 6674 / 6674 sentences in train / dev / test.
Saving the mappings to disk...
2018-01-22 20:22:16.826412: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
Starting epoch 0...
5000, cost average: 9.993771, accuracy average: 0.869311, sentence accuracy avg: 0.111753, cost time: 0
2018-01-22 20:23:36.046608: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: flat indices[960, :] = [960, -1] does not index into param (shape: [1340,7,25]).
2018-01-22 20:23:36.052338: W tensorflow/core/framework/op_kernel.cc:1192] Invalid argument: flat indices[960, :] = [960, -1] does not index into param (shape: [1340,7,25]).
Traceback (most recent call last):
File "train.py", line 301, in <module>
dev_score, dev_sentence_score = evaluate(sess, tags_scores, model, parameters, dev_data, n_tag)
File "/home/eek/polygon/tf-lstm-crf-batch/utils.py", line 378, in evaluate
f_scores = sess.run(f_eval, feed_dict=feed_dict_)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: flat indices[960, :] = [960, -1] does not index into param (shape: [1340,7,25]).
[[Node: char_for_output = GatherNd[Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](char_lstm_for_h_trans, _arg_char_pos_ids_0_1)]]
Caused by op u'char_for_output', defined at:
File "train.py", line 195, in <module>
cost, tags_scores, train_op = model.build(**parameters)
File "/home/eek/polygon/tf-lstm-crf-batch/model.py", line 142, in build
char_for_output = tf.gather_nd(char_lstm_for_h_trans, self.char_pos_ids, name='char_for_output')
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1971, in gather_nd
"GatherNd", params=params, indices=indices, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): flat indices[960, :] = [960, -1] does not index into param (shape: [1340,7,25]).
[[Node: char_for_output = GatherNd[Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](char_lstm_for_h_trans, _arg_char_pos_ids_0_1)]]
Hello, Qianghuai,
Thank you very much for rewriting this framework into TensorFlow. I bet this wouldTF be a very educational repo.
I found that there is a line in loader.py "from utils import iob2, iob_iobes"
and a line in train.py "parameters['update'] = opts.update_scheme", which report errors in my environment and I found that they are indeed undefined.
Thus, I deleted these two lines and it works fine now.
Is there any reason why you need this two lines?
Thank you very much.
like, the precision, recall, f1? thank you .
when I am training my model,the error is occured.my tf 's version 1.0.
Building model finished
Traceback (most recent call last):
File "train.py", line 212, in
del tf.get_collection_ref('LAYER_NAME_UIDS')[0]
IndexError: list assignment index out of range
can you provide me with the data? thank you so much!!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.