Caffe 中的嵌入层采用什么类型的输入? 它是否需要已经以一种热形式编码的单词?
假设,N = 输入句子中的单词数; M = 词汇量
那么单个句子的一个热向量的阶数为 N x M
这是否意味着输入的 dim 参数将为 N?
最后应该以什么格式保存句子,以便 Caffe 嵌入层可以正确读取它?
最佳答案
请参阅 "Embed"
的文档层:
A layer for learning "embeddings" of one-hot vector input. Equivalent to an InnerProductLayer with one-hot vectors as input, but for efficiency the input is the "hot" index of each column itself.
因此,您的输入不是代表单词(或字符或“项目”)的“热向量”,而是单词的紧凑表示:字典中单词的整数索引。
因此,如果您的字典中有 M=1000
个单词,并且您想学习嵌入到 100 维空间中:
layer {
name: "embed1000_to_100"
type: "Embed"
bottom: "compact_one_hot_dim1000"
top: "embed1000_to_100"
embed_param {
num_output: 100 # output dimension
input_dim: 1000
}
}
请注意,“compact_one_hot_dim1000”
的数据应为 (0..999) 范围内的整数。
参见caffe.help了解更多信息。
关于machine-learning - Caffe 嵌入层输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42722048/