Tensorflow - get each character in the string tensor

I am trying to get characters in a string tensor to predict character level. Fundamental truths are words in which each character has an identifier in the dictionary. I have a tensor corresponding to the length of the string.

Now I have to get every character in the string tensor. After checking the relevant messages, a simple search may be as follows. Example string "This"

a= tf.constant("This",shape=[1])
b=tf.string_split(a,delimiter="").values  #Sparse tensor has the values array which stores characters

Now I want to create a line with spaces between the letters "This" ie "T h i s". I need distance both at the beginning and at the end. How to do it?

I tried iterating through the characters as below

for i in xrange(b.dense_shape[1]): # b.dense_shape[1] has the length of string
        x=b.values[i]

But the cycle expects the whole, not the tensor.

, ? , ( tf.string_split). .

+6
1

, Tensor, . , numpy eval() tf.map_fn.

b numpy array, .eval() .values :

with tf.Session() as sess:
    a = tf.constant("This", shape=[1])
    b = tf.string_split(a, delimiter="").values.eval()

    for i in b:
        print(i)

- , TensorFlow. , "" . ( fn ):

with tf.Session() as sess:
    a = tf.constant("This", shape=[1])
    b = tf.string_split(a, delimiter="").values

    fn = lambda i: i

    print(tf.map_fn(fn, b).eval())
+5

All Articles