Converting an input with shape (m, n) to (m, k, n), where k is "hidden" inside as a string representation of an array?

Viewed 68

I have a dataset like the one in the picture below, with m rows (= batch size) and n columns (v1, v2, ... vn), each representing a feature. For each example in the dataset, each feature is a string representation of an array of floats, so something like this '[-0.05, 1.12, -0.23, ..., 1.22]'. The "hidden" array represented as a string, if converted to an array of floats, has length k. This input is fed directly into a Tensorflow/Keras model without any Python preprocessing: the dataset is passed as is to model.fit, so there is no way to do conversions and reshaping in Pandas or Numpy.

Is there a way to convert and reshape inside the model, as the first layer? The model takes the input with shape (m, n), extract the hidden array of length k and rearrange the input shape to (m, k, n)

1 Answers

Firstly, You can't feed strings into the model directly. You will need to convert it to float first.

You can't reshape the data from inside the model but what you can do is to set the input shape to None. If your input data shape is not fixed, you can set input shape to None. In this case, your model will accept data of any shape.

You can take a look into the discussion here too. https://github.com/keras-team/keras/issues/2054

Related