Try to search your question here, if you can't find : Ask Any Question Now ?

How can I convert a Pandas DataFrame of vectors and labels into input for an RNN in TensorFlow

HomeCategory: stackoverflowHow can I convert a Pandas DataFrame of vectors and labels into input for an RNN in TensorFlow
craig asked 1 week ago

I’m working on a text classifier using an LSTM in TensorFlow and can’t figure out the format of the input data.
My input data is a Pandas Dataframe with one feature column and one label column.

My feature column is a 2D array representing an array of vectors and my label column is a String, an example of my data input is below.

How do I convert this Dataframe into a dataset that can be used as input to be used in a Tensorflow.Keras model?

I’ve tried converting the Dataframe into a TensorFlow.Dataset dataset using tf.data.Dataset.from_tensor_slices but this produces a TypeError

##Building input data
test01 = ([[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],'label1')
test02 = ([[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[0,0,0,0]],'label2')
test03 = ([[1,1,1,1],[1,1,1,1],[1,1,1,1],[0,0,0,0],[1,1,1,1]],'label3')
test04 = ([[1,1,1,1],[0,0,0,0],[1,1,1,1],[1,1,1,1],[1,1,1,1]],'label1')
test_data = [test01,test02,test03,test04]


##DataFrame from data
columns = ['feature','label']
t_df = pd.DataFrame(data = test_data, columns = columns)

##Convert to TensorFlow Dataset
dataset = tf.data.Dataset.from_tensor_slices((t_df['feature'], t_df['label']))

This produces the following error:

TypeError: Expected binary or unicode string, got [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
##TensorFlow Model Example 
model = tf.keras.Sequential([,
    tf.keras.layers.LSTM(input_shape),
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid')
])
1 Answers
Best Answer
Mannu answered 1 week ago
Your Answer

9 + 20 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com