【发布时间】:2017-12-20 23:02:59
【问题描述】:
我在 Tensorflow 中遇到了多类分类问题。标签是字符串类型,具有 1000 个唯一值。如何编码?
如果我直接将它作为标签传递,则会出现此错误
ValueError: Labels dtype should be integer Instead got <dtype: 'string'>.
【问题讨论】:
标签: tensorflow multiclass-classification
我在 Tensorflow 中遇到了多类分类问题。标签是字符串类型,具有 1000 个唯一值。如何编码?
如果我直接将它作为标签传递,则会出现此错误
ValueError: Labels dtype should be integer Instead got <dtype: 'string'>.
【问题讨论】:
标签: tensorflow multiclass-classification
您没有提供任何代码,所以我不知道您实际传递标签的位置。但我可以给出一个笼统的答案。
在具有已知类别数量的分类问题中,您只需为每个类别分配一个整数。因此,在您的情况下,您可以创建一个 python 字典,它将您的单词映射到这样的整数:
word_to_index = {'word1': 0, 'word2': 1, 'word3': 2}
label = 'word2'
index = word_to_index[label]
从你提出问题的方式和你得到的错误(它说integer)来看,在我看来,你使用的 API 只需要这样的整数。
【讨论】: