I have a tensorflow dataset:
def fake_sequence():
seq = [np.random.choice(["A", "B", "C", "D"]) for _ in range(100)]
mutate = [np.random.choice(["E", "F", "G", "H"]) for _ in range(100)]
mask = np.random.choice(a=[True, False], size=100, p=[0.999, 0.001])
return "".join(np.where(mask, seq, mutate))
seqs = [fake_sequence() for _ in range(100)]
ds = tf.data.Dataset.from_tensor_slices(seqs)
I'd like to filter it with the following pythonic function:
def python_filter(x):
x = set(x)
x = x.issubset({"A", "B", "C", "D"})
return x
Unfortunately, decorating with @tf.function doesn't work. Can any of you wizards help me? Here's what I have so far.
def filter(x):
x = tf.strings.bytes_split(x)
x = tf.unique(x)[0]
# tensorflow function for x.issubset({"A", "B", "C", "D"})
return x
ds = ds.filter(filter)