0
$\begingroup$

I am trying to build an LSTM and am confused about the best way to shape my data.

I have a dataframe that looks like this:

df.head(5)

 data                                                     labels
0  [0.0009808844009380855, 0.0008974465127279559]             1
1  [0.0007158940267629654, 0.0008202958833774329]             3
2  [0.00040971929722210984, 0.000393972522972382]             3
3  [7.916243163372941e-05, 7.401835468434177e243]             3
4  [8.447556379936086e-05, 8.600626393842705e-05]             3

The 'data' column is my X and the labels is y. The df has 34890 rows. Each row contains 2 floats. The data represents a bunch of sequential text and each observation is a representation of a sentence. There are 5 classes.

I am trying to fit an LSTM with this data and am confused about how to use the timestep parameter.

With this code, I get the following:

data = np.array(df.class_proba.to_list())

labels = pd.get_dummies(df['speaker_spaff']).values

print('Shape of data tensor:', data.shape)
print('Shape of label tensor:', labels.shape)

Shape of data tensor: (34890, 2)
Shape of label tensor: (34890, 5)

I think my label tensor is correct, but I am confused about my data tensor.

Keras LSTM layers require the shape: samples, time steps, and features.

If I understand correctly, my number of samples is 34890, my features is 2, but what about timestamps? What should the timestamp parameter be and how can I reshape my data to fit this?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.