Vaisakh Venugopal
Vaisakh Venugopal

Reputation: 31

Tensorflow classification label with 1000 classes encoding

I'm having multi-class classification problem in Tensorflow. Label are string type & having 1000 unique values. How to encode this?

if I am passing it directly as label, getting this error

ValueError: Labels dtype should be integer Instead got <dtype: 'string'>.

Upvotes: 1

Views: 483

Answers (1)

Addy
Addy

Reputation: 1450

You have not provided any code, so I don't know where you are actually passing the labels. But I can give a general answer.

In a classification problem with a known number of classes, you simply assign an integer to each class. So in your case, you could create a python dictionary which would map your words to an integer like this:

word_to_index = {'word1': 0, 'word2': 1, 'word3': 2}
label = 'word2'
index = word_to_index[label]

From the way you posed your question and the error you got (it says integer), it seems to me that the API you are using just expects such integer.

Upvotes: 2

Related Questions