I want to use a sparse tensor in tensorflow of python for training. I found a lot of code how to do that, but none of them worked.
Here an example code to show what I mean, it throws an error:
import numpy as np
x_vals = tf.sparse.SparseTensor([[0, 0], [0, 1], [1, 2]], [1, 2, 1], [2, 3])
#x_vals = tf.sparse.to_dense(x_vals) #this line decides, if there is an error
y_vals = np.array([0, 1])
layer_args = lambda : None
layer_args.input_shape = (3,)
layer_args.activation = "sigmoid"
layer_args.use_bias = False
model = tf.keras.models.Sequential(tf.keras.layers.Dense(1, **layer_args.__dict__))
model.compile(loss = "mse")
model.fit(x_vals, y_vals)
The error is:
ValueError: The two structures don't have the same nested structure.
...and a huge stacktrace