【发布时间】:2019-02-27 20:19:17
【问题描述】:
我想为使用字符嵌入的句子分类构建 LSTM 模型。
我知道如何使用词嵌入来做到这一点,模型可以从词索引中学习嵌入,但不知道如何使用字符嵌入来做到这一点。
对于词嵌入:
sentence_list = ['this is a dog', 'the cat and the mouse']
label = [1,0]
word_dict = {'this':1,
'is':2,
'a':3,
'dog':4,
'the':5,
'cat':6,
'and':7,
'mouse':8}
# set vector length = 9
vectors = [[1,2,3,4,0,0,0,0,0]
[0,0,0,0,5,6,7,5,8]]
model.fit(vectors,label)
因此可以将其安装到 LSTM 模型中。
我们如何处理基于字符的向量?
例如: 如果我有这个字符字典:
char_dict = {'t':1,
'h':2,
'i':3,
's':4,
'a':5,
'd':6,
'o':7,
'g':8}
如何将其格式化为 LSTM 分类模型的可读性? 更具体地说,我们如何组合多个字符向量以输入 LSTM 模型?
【问题讨论】:
标签: python tensorflow keras lstm