【发布时间】:2019-10-07 05:18:50
【问题描述】:
我有一个清单:
code = ['<s>', 'are', 'defined', 'in', 'the', '"editable', 'parameters"', '\n', 'section.', '\n', 'A', 'larger', '`tsteps`', 'value', 'means', 'that', 'the', 'LSTM', 'will', 'need', 'more', 'memory', '\n', 'to', 'figure', 'out']
我想转换为一种热编码。我试过了:
to_categorical(code)
我得到一个错误:ValueError: invalid literal for int() with base 10: '<s>'
我做错了什么?
【问题讨论】:
-
根据docs,
to_categorical的参数必须是整数向量,而不是字符串 -
如何将这些字符串转换为整数?
标签: python keras one-hot-encoding