Transformers: When i run the script run_tf_ner.py, i got ValueError: Expected floating point type, got <dtype: 'int32'>.

Created on 19 Dec 2019  ยท  8Comments  ยท  Source: huggingface/transformers

I have tried tf 2.0.0a0, 2.0.0b0, 2.0.0b1, but the same error was reported.

โ“ Questions & Help


Traceback (most recent call last):
File "run_tf_ner.py", line 615, in
app.run(main)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "run_tf_ner.py", line 517, in main
cache_dir=args['cache_dir'] if args['cache_dir'] else None)
File "/home/zpchen/transformers-master/transformers/modeling_tf_utils.py", line 303, in from_pretrained
ret = model(model.dummy_inputs, training=False) # build the network with dummy inputs
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 712, in __call__
outputs = self.call(inputs, args, *kwargs)
File "/home/zpchen/transformers-master/transformers/modeling_tf_bert.py", line 1011, in call
outputs = self.bert(inputs, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 712, in __call__
outputs = self.call(inputs, *args, *
kwargs)
File "/home/zpchen/transformers-master/transformers/modeling_tf_bert.py", line 547, in call
embedding_output = self.embeddings([input_ids, position_ids, token_type_ids, inputs_embeds], training=training)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 709, in __call__
self._maybe_build(inputs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1966, in _maybe_build
self.build(input_shapes)
File "/home/zpchen/transformers-master/transformers/modeling_tf_bert.py", line 122, in build
initializer=get_initializer(self.initializer_range))
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 389, in add_weight
aggregation=aggregation)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py", line 713, in _add_variable_with_custom_getter
*kwargs_for_getter)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 154, in make_variable
shape=variable_shape if variable_shape else None)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 260, in __call__
return cls._variable_v1_call(
args, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 221, in _variable_v1_call
shape=shape)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 60, in getter
return captured_getter(captured_previous, *
kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py", line 1250, in creator_with_resource_vars
return self._create_variable(args, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/distribute/one_device_strategy.py", line 76, in _create_variable
return next_creator(args, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 199, in
previous_getter = lambda *kwargs: default_variable_creator(None, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 2502, in default_variable_creator
shape=shape)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 264, in __call__
return super(VariableMetaclass, cls).__call__(args, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 464, in __init__
shape=shape)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 608, in _init_from_args
initial_value() if init_from_fn else initial_value,
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 134, in
init_val = lambda: initializer(shape, dtype=dtype)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/init_ops_v2.py", line 341, in __call__
dtype = _assert_float_dtype(dtype)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/init_ops_v2.py", line 769, in _assert_float_dtype
raise ValueError("Expected floating point type, got %s." % dtype)
ValueError: Expected floating point type, got .

wontfix

Most helpful comment

You can try with the latest version of TensorFlow 2.X. You can install it through pip install tensorflow==2.1.0-rc1. Keep us updated

Yes, But I also get this error 'AttributeError: module 'tensorflow.python.keras.api._v2.keras.layers' has no attribute 'LayerNormalization'.

Here they say to update TensorFlow 2.0 version from alpha-0 to beta-0. But I remember that when you update TF you encounter another problem. Can you give a try? pip install tensorflow==2.0.0-beta0

I can try. But I got "ValueError: Expected floating point type, got ." previously when i use 2.0.0-beta0.

All 8 comments

I have tried tf 2.0.0a0, 2.0.0b0, 2.0.0b1, but the same error was reported.

Questions & Help

Traceback (most recent call last):
File "run_tf_ner.py", line 615, in
app.run(main)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "run_tf_ner.py", line 517, in main
cache_dir=args['cache_dir'] if args['cache_dir'] else None)
File "/home/zpchen/transformers-master/transformers/modeling_tf_utils.py", line 303, in from_pretrained
ret = model(model.dummy_inputs, training=False) # build the network with dummy inputs
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 712, in call
outputs = self.call(inputs, args, kwargs)
File "/home/zpchen/transformers-master/transformers/modeling_tf_bert.py", line 1011, in call
outputs = self.bert(inputs, *
kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 712, in *call

outputs = self.call(inputs, *args, kwargs)
File "/home/zpchen/transformers-master/transformers/modeling_tf_bert.py", line 547, in call
embedding_output = self.embeddings([input_ids, position_ids, token_type_ids, inputs_embeds], training=training)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 709, in *
call
self._maybe_build(inputs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1966, in _maybe_build
self.build(input_shapes)
File "/home/zpchen/transformers-master/transformers/modeling_tf_bert.py", line 122, in build
initializer=get_initializer(self.initializer_range))
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 389, in add_weight
aggregation=aggregation)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py", line 713, in _add_variable_with_custom_getter
kwargs_for_getter)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 154, in make_variable
shape=variable_shape if variable_shape else None)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 260, in *call

return cls._variable_v1_call(
args, kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 221, in _variable_v1_call
shape=shape)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 60, in getter
return captured_getter(captured_previous, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py", line 1250, in creator_with_resource_vars
return self._create_variable(
args, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/distribute/one_device_strategy.py", line 76, in _create_variable
return next_creator(
args, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 199, in
previous_getter = lambda *
kwargs: default_variable_creator(None, *kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 2502, in default_variable_creator
shape=shape)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 264, in *
call

return super(VariableMetaclass, cls).call(args, kwargs)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 464, in *
init
shape=shape)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 608, in _init_from_args
initial_value() if init_from_fn else initial_value,
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 134, in
init_val = lambda: initializer(shape, dtype=dtype)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/init_ops_v2.py", line 341, in call
dtype = _assert_float_dtype(dtype)
File "/home/zpchen/anaconda7/lib/python3.6/site-packages/tensorflow/python/ops/init_ops_v2.py", line 769, in _assert_float_dtype
raise ValueError("Expected floating point type, got %s." % dtype)
ValueError: Expected floating point type, got .

Do you try to look into this StackOverflow question and #1780 ?

Yes, But I also get this error 'AttributeError: module 'tensorflow.python.keras.api._v2.keras.layers' has no attribute 'LayerNormalization'.

Yes, But I also get this error 'AttributeError: module 'tensorflow.python.keras.api._v2.keras.layers' has no attribute 'LayerNormalization'.

Here they say to update TensorFlow 2.0 version from alpha-0 to beta-0. But I remember that when you update TF you encounter another problem. Can you give a try? pip install tensorflow==2.0.0-beta0

Yes, But I also get this error 'AttributeError: module 'tensorflow.python.keras.api._v2.keras.layers' has no attribute 'LayerNormalization'.

Here they say to update TensorFlow 2.0 version from alpha-0 to beta-0. But I remember that when you update TF you encounter another problem. Can you give a try? pip install tensorflow==2.0.0-beta0

I can try. But I got "ValueError: Expected floating point type, got ." previously when i use 2.0.0-beta0.

You can try with the latest version of TensorFlow 2.X. You can install it through pip install tensorflow==2.1.0-rc1. Keep us updated

Yes, But I also get this error 'AttributeError: module 'tensorflow.python.keras.api._v2.keras.layers' has no attribute 'LayerNormalization'.

Here they say to update TensorFlow 2.0 version from alpha-0 to beta-0. But I remember that when you update TF you encounter another problem. Can you give a try? pip install tensorflow==2.0.0-beta0

I can try. But I got "ValueError: Expected floating point type, got ." previously when i use 2.0.0-beta0.

Thank you. I will try.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Thank you. I will try.

have you solved this "ValueError: Expected floating point type, got ." problem?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hsajjad picture hsajjad  ยท  3Comments

delip picture delip  ยท  3Comments

alphanlp picture alphanlp  ยท  3Comments

HanGuo97 picture HanGuo97  ยท  3Comments

adigoryl picture adigoryl  ยท  3Comments