您的位置:首页 > 其它

大规模特征编码问题和工程实践

2017-12-14 14:58 846 查看

One-Hot Encoding


方式1:序号编码

根据特征在整个特征集合中的index进行编码。

在Spark里的编码逻辑:

1.把样本集合的特征map{feature:value}放到一个Set集合里,然后取集合的index作为一个特征feature:value的编号,map{map{feature:value}:index}。

2.然后将每条样本转成index表示的fea_ids。

2.最后将每条样本表示成SparseVector(feature_zise,fea_ids,1)。


方式2:哈希编码

根据特征值的hash值进行编码

output_id = Hash(input_feature_string) % bucket_size

比如在tesorflow中对商品id进行编码:
item_id = tf.contrib.layers.sparse_column_with_hash_bucket("item_id", hash_bucket_size=10000000)


Embedding

用户、商品等id类特征维度合计高达几千万维, 假设在输入层后直接连接 100 个输出神经元的全连接层,那么这个模 型的参数规模将达到上亿规模。

直接接入全连接层将导致以下几个问题:

1. 各个域都存在冷门的特征,这些冷门的特征将会被热门的特征淹没,基本不起作用, 跟全连接层的连接边权值会趋向于 0,冷门的商品只会更冷门。

2. 模型的大小 将会非常庞大,超过G,在训练以及预测中都会出现很多工程上的问题。

所以对大规模特征的Embedding需要一些特殊的Trick,目前探索的方法如下:
https://stackoverflow.com/questions/43288147/how-do-i-use-a-very-large-2m-word-embedding-in-tensorflow https://stackoverflow.com/questions/44863493/could-word2vec-algorithm-be-distributed-on-multi-computers-using-tensorflow https://stackoverflow.com/questions/43130893/seq2seq-embedding-size-is-too-large-for-distributed-training https://stackoverflow.com/questions/38427471/why-does-tf-nn-embedding-lookup-use-a-list-of-embeddings https://stackoverflow.com/questions/47523374/feature-columns-embedding-lookup https://stackoverflow.com/questions/34870614/what-does-tf-nn-embedding-lookup-function-do
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: