combiner must be one of 'mean', 'sqrtn' or 'sum'
Package:
tensorflow
158813

Exception Class:
ValueError
Raise code
"""
TypeError: If `sp_ids` is not a `SparseTensor`, or if `sp_weights` is
neither `None` nor `SparseTensor`.
ValueError: If `combiner` is not one of {"mean", "sqrtn", "sum"}.
"""
if combiner is None:
combiner = "mean"
if combiner not in ("mean", "sqrtn", "sum"):
raise ValueError("combiner must be one of 'mean', 'sqrtn' or 'sum'")
if isinstance(params, variables.PartitionedVariable):
params = list(params) # Iterate to get the underlying Variables.
if not isinstance(params, list):
params = [params]
if not isinstance(sp_ids, sparse_tensor.SparseTensor):
raise TypeError("sp_ids must be SparseTensor")
ignore_weights = sp_weights is None
Links to the raise (1)
https://github.com/tensorflow/tensorflow/blob/7acd515ec218b414d5b16e6710268ac03d9f5421/tensorflow/python/ops/embedding_ops.py#L485Ways to fix
The valid values of the combiner
parameters are:
"sum" ,"mean", "sqrtn"
If any other value is given it is invalid and causes an error:
Reproducing the error:
import tensorflow as tf
import numpy as np
example = tf.SparseTensor(indices=[[0], [1], [2]], values=[3, 6, 9], dense_shape=[3])
vocabulary_size = 10
embedding_size = 1
var = np.array([0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0])
embeddings = tf.Variable(var)
embed = tf.nn.embedding_lookup_sparse(embeddings, example, None,combiner="sqrt")
print(embed)
The error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-7bd9e512c941> in <module>()
9 embeddings = tf.Variable(var)
10
---> 11 embed = tf.nn.embedding_lookup_sparse(embeddings, example, None,combiner="sqrt")
12 print(embed)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
204 """Call target, and fall back on dispatchers if there is a TypeError."""
205 try:
--> 206 return target(*args, **kwargs)
207 except (TypeError, ValueError):
208 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/embedding_ops.py in embedding_lookup_sparse_v2(params, sp_ids, sp_weights, combiner, max_norm, name)
668 """
669 return embedding_lookup_sparse(params, sp_ids, sp_weights, "div", name,
--> 670 combiner, max_norm)
671
672
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
204 """Call target, and fall back on dispatchers if there is a TypeError."""
205 try:
--> 206 return target(*args, **kwargs)
207 except (TypeError, ValueError):
208 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/embedding_ops.py in embedding_lookup_sparse(params, sp_ids, sp_weights, partition_strategy, name, combiner, max_norm)
484 combiner = "mean"
485 if combiner not in ("mean", "sqrtn", "sum"):
--> 486 raise ValueError("combiner must be one of 'mean', 'sqrtn' or 'sum'")
487 if isinstance(params, variables.PartitionedVariable):
488 params = list(params) # Iterate to get the underlying Variables.
ValueError: combiner must be one of 'mean', 'sqrtn' or 'sum'
The fix:
Make sure the combiner is set to a valid value.
import tensorflow as tf
import numpy as np
example = tf.SparseTensor(indices=[[0], [1], [2]], values=[3, 6, 9], dense_shape=[3])
vocabulary_size = 10
embedding_size = 1
var = np.array([0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0])
embeddings = tf.Variable(var)
embed = tf.nn.embedding_lookup_sparse(embeddings, example, None,combiner="sqrtn")
print(embed)
Output:
tf.Tensor([ 9. 36. 81.], shape=(3,), dtype=float64)
Add a possible fix
Please authorize to post fix