lundi 21 février 2022

How to randomly remove spaces from a tensor of strings in Tensorflow

There is a Tensor of strings, for each string I want to remove n spaces randomly where n <= the number of the spaces in that string.

import tensorflow as tf

strings_with_spaces = tf.constant([b'A B C D E F', b'1 2 3 4 5 6'])
remove_spaces_randomly = None
T = tf.map_fn(remove_spaces_randomly, strings_with_spaces)

I expect the output to be something like:
['A BC D EF', '1 2 34 5 6']



Aucun commentaire:

Enregistrer un commentaire