I want to check if any of a set of given values are contained in a sparse tensor. The sparse tensor is called labels
and has just one dimension containing a list of ids.
In the end this seems like a simple set intersection problem, so I tried this.
sparse_ids = load_ids_as_sparse_tensor()
wanted_ids = tf.constant([34, 56, 12])
intersection = tf.sets.set_intersection(
wanted_ids,
tf.cast(sparse_ids.values, tf.int32)
)
contains_any_wanted_ids = tf.not_equal(tf.size(intersection), 0)
However, I am getting this error:
ValueError: Shape must be at least rank 2 but is rank 1 for 'DenseToDenseSetOperation' (op: 'DenseToDenseSetOperation') with input shapes: [3], [?].
Any ideas?