I want to train a data which varies array size. For example, Let's assume we wish to train sentences. The first sentence is "I am John" and The second one is "I know". If the sentences are converted into tensor. The first thing will become ["I", "am", "John"] and the next will be ["I","know"]. Consequently, the first array will need 3 as n_input for shape of placeholder. However, 2 is needed for the second array.
x = tf.placeholder("float", [None, n_input])
y = tf.placeholder("float", [None, n_classes])
I will need above codes for definition of placeholder. However, I can't determine n_input.
Additionally, What does None in shape mean? batch_size? Please help me.
Technically the placeholder doesn't need a shape at all. It can be defined as such.
x =tf.placeholder(tf.float32, shape=[])
In this case the place holder itself has no shape information to it. If you know the dimensions of the tensor but not it's actual numerical shape we replace the numerical value of that dimension with None because it can have a variable size.
x =tf.placeholder(tf.float32, shape=[None, None, None])
This affects some down stream static shape analysis that tensorflow does to get the shape information but otherwise it should still work as intended.
In scenarios like yours, we usually make the second dimension(the time_steps or the input length) as a constant number, say the largest length of the sentence, and the blanks are fed with pads or zeros directly. Then you can set the placeholders as:
x = tf.placeholder(tf.int32, [None, max_input_steps])
y = tf.placeholder(tf.int32, [None, nax_output_steps])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With