I have a tensor x,
x={Tensor} Tensor("Cast:0", shape=(?,3), dtype=int32)
Now, I need to iterate over each triple of this tensor batch (say a triple is (a,b,c)) and fetch the first element (in this example, a) of that.
Then, I need to fetch all other triples in the dataset Y (below) that also have 'a' as their first element.
Ultimately, I wish to return all triples with 'a' as the first element, excluding the triple in question (i.e. in this case, excluding (a,b,c)).
I was previously working with the same, assuming that x is a list.
Therefore, in terms of list operations:
t=list({triple for x in x_to_score for triple in self.d[x[0]]} - set(x_to_score.eval()))
where d is a dictionary containing list of all the triples grouped by first elements. For example:
For
Y=np.array([['a', 'y', 'b'],
['b', 'y', 'a'],
['a', 'y', 'c'],
['c', 'y', 'a'],
['a', 'y', 'd'],
['c', 'y', 'd'],
['b', 'y', 'c'],
['f', 'y', 'e']])
d={'f': [('f', 'y', 'e')],
'c': [('c', 'y', 'a'), ('c', 'y', 'd')],
'a': [('a', 'y', 'b'), ('a', 'y', 'c'), ('a', 'y', 'd')],
'b': [('b', 'y', 'a'), ('b', 'y', 'c')]}
However, I am new to tensorflow and cannot find a way to convert these operations into tensors. The result should also be of the order [?,3] for each triple evaluated.
Please note that eager execution must be disabled.
Any help is welcome!
EDIT: If the input tensor x=(a,y,d) (note that this can be a batch, so x=[(a,y,d),(b,y,c)] etc.), then the expected output will be:
[('a', 'y', 'b'), ('a', 'y', 'c')]