DeepPavlov: Error while trying to get the probablities of the predicted entities using ontonotes_bert ner model

Deeppavlov version: 0.12.1 Python version: 3.7.7 "return_probas"set to true in ner_ontonotes_bert config json Command: python -m deeppavlov interact F:\miniconda3\envs\ute_query_params_service\Lib\site-packages\deeppavlov\configs\ner\ner_ontonotes_bert.js Command string: London is in England. Full Traceback: [nltk_data] Downloading package punkt to [nltk_data] C:\Users\User\AppData\Roaming\nltk_data… [nltk_data] Package punkt is already up-to-date! [nltk_data] Downloading package stopwords to [nltk_data] C:\Users\User\AppData\Roaming\nltk_data… [nltk_data] Package stopwords is already up-to-date! [nltk_data] Downloading package perluniprops to [nltk_data] C:\Users\User\AppData\Roaming\nltk_data… [nltk_data] Package perluniprops is already up-to-date! [nltk_data] Downloading package nonbreaking_prefixes to [nltk_data] C:\Users\User\AppData\Roaming\nltk_data… [nltk_data] Package nonbreaking_prefixes is already up-to-date! WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\tokenization.py:125: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.

2020-11-30 21:37:31.122 INFO in ‘deeppavlov.core.data.simple_vocab’[‘simple_vocab’] at line 115: [loading vocabulary from C:\Users\User.deeppavlov\models\ner_ontonotes_bert\tag.dict] WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:37: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:222: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:222: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:193: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\models\bert\bert_sequence_tagger.py:236: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\models\bert\bert_sequence_tagger.py:314: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\modeling.py:178: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\modeling.py:418: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\modeling.py:499: The name tf.assert_less_equal is deprecated. Please use tf.compat.v1.assert_less_equal instead.

WARNING:tensorflow: The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see:

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\modeling.py:366: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\modeling.py:680: dense (from tensorflow.python.layers.core) is deprecated and will be removed in a future version. Instructions for updating: Use keras.layers.Dense instead. WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\tensorflow_core\python\layers\core.py:187: Layer.apply (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version. Instructions for updating: Please use layer.__call__ method instead. WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\bert_dp\modeling.py:283: The name tf.erf is deprecated. Please use tf.math.erf instead.

WARNING:tensorflow:Variable *= will be deprecated. Use var.assign(var * other) if you want assignment to the variable value or x = x * y if you want a new python Tensor object. WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\models\bert\bert_sequence_tagger.py:75: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\tensorflow_core\contrib\crf\python\ops\crf.py:213: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version. Instructions for updating: Please use keras.layers.RNN(cell), which is equivalent to this API WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:234: The name tf.train.AdadeltaOptimizer is deprecated. Please use tf.compat.v1.train.AdadeltaOptimizer instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:131: The name tf.get_collection is deprecated. Please use tf.compat.v1.get_collection instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:131: The name tf.GraphKeys is deprecated. Please use tf.compat.v1.GraphKeys instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:94: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\tensorflow_core\python\training\moving_averages.py:433: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version. Instructions for updating: Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts. WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\models\bert\bert_sequence_tagger.py:671: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\models\bert\bert_sequence_tagger.py:244: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.

WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\models\bert\bert_sequence_tagger.py:249: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version. Instructions for updating: Use standard file APIs to check for files with this prefix. 2020-11-30 21:40:57.982 INFO in ‘deeppavlov.core.models.tf_model’[‘tf_model’] at line 51: [loading model from C:\Users\User.deeppavlov\models\ner_ontonotes_bert\model] WARNING:tensorflow:From f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\models\tf_model.py:54: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

x::London is in England. Traceback (most recent call last): File “f:\miniconda3\envs\ute_query_params_service\lib\runpy.py”, line 193, in _run_module_as_main “main”, mod_spec) File “f:\miniconda3\envs\ute_query_params_service\lib\runpy.py”, line 85, in run_code exec(code, run_globals) File "f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov_main.py", line 4, in <module> main() File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\deep.py”, line 89, in main interact_model(pipeline_config_path) File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\commands\infer.py”, line 89, in interact_model pred = model(*args) File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\common\chainer.py”, line 207, in call return self._compute(*args, param_names=self.in_x, pipe=self.pipe, targets=self.out_params) File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\common\chainer.py”, line 230, in _compute res = component.call(*x) File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 92, in call looked_up_batch = [self(sample, is_top=False) for sample in batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 92, in <listcomp> looked_up_batch = [self(sample, is_top=False) for sample in batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 92, in call looked_up_batch = [self(sample, is_top=False) for sample in batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 92, in <listcomp> looked_up_batch = [self(sample, is_top=False) for sample in batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 92, in call looked_up_batch = [self(sample, is_top=False) for sample in batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 92, in <listcomp> looked_up_batch = [self(sample, is_top=False) for sample in batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 94, in call return self[batch] File “f:\miniconda3\envs\ute_query_params_service\lib\site-packages\deeppavlov\core\data\simple_vocab.py”, line 161, in getitem raise NotImplementedError(“not implemented for type {}”.format(type(key))) NotImplementedError: not implemented for type <class 'numpy.float32'>

I would like to get the probablities of predicted entities. Is return_probas is the way to go? Please help. Thanks in advance.

  • Ravishankar

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Hi!

You also need to remove the last component from pipe, which converts label indices to actual labels.

{
        "ref": "tag_vocab",
        "in": ["y_pred_ind"],
        "out": ["y_pred"]
}

and change chainer out section "out": ["x_tokens", "y_pred"] -> "out": ["x_tokens", "y_pred_ind"] As result, model will return tokens and labels probabilities for each token. Order of labels probabilities is the same as in labels vocabulary: https://github.com/deepmipt/DeepPavlov/blob/c10b079b972493220c82a643d47d718d5358c7f4/deeppavlov/configs/ner/ner_ontonotes_bert.json#L30