Skip to content

自动稠密特征工程

songyue1104 edited this page Aug 12, 2019 · 2 revisions

功能

可在训练引擎内进行特征级别的counting统计,从而简化离线特征计算流程的复杂度

用法

在xdl.embedding接口函数中添加参数statis_list、statis_decay、statis_decay_period、labels,典型例子如下:

emb, statis = xdl.embedding(emb_name, batch["unit_id_expand"], xdl.Normal(stddev=0.001),
                            emb_dim, 50000, emb_combiner, vtype="hash",
                            feature_add_probability=feature_add_probability,
                            statis_list=['click'], statis_decay=0.07, statis_decay_period=10,
                            agg_type='sum,avg,min,max',
                            labels=batch['label'])
# emb 是原embedding的输出,进入dense网络。
# statis 是统计输出,也可进入dense网络计算,也可由xdl.TrainSession(hooks).run()打印结果。数目与statis_list一致。
  • statis_list是统计类型名列表,目前支持'pv'、'click'两种。
  • statis_decay是global_step经过statis_decay_period轮次后的衰减因子,S[N] = a[N] + decay * S[N-1]。
  • labels是batch["label"],用于click统计。
  • agg_type是多ID聚合方案列表,逗号分隔,不限制个数并且可重复。

算法

  • 由于异步更新,因此统计漏项在无锁条件下不可避免,但可以将统计漏项对整体结果的影响最小化,方法是在累加项中去除含N的因子。
  • 引入offset避免乘方结果溢出float表示范围,注意重新加载ckpt训练时的情形。
  /*
   *  S[0] = a[0]
   *  S[N] = a[N] + decay * S[N-1]
   *       = a[N] + decay*a[N-1] + decay^2*a[N-2] + ... + decay^(N-1)*a[1] + decay^N*a[0]
   *       = decay^N * sum<j=0:N+1> { decay^(-j) * a[j] }
   *
   *  N = gs / period
   *  K = decay^(N-offset)
   *  acc = sum<j=0:N+1> { decay^(offset-j) * a[j] }
   *  data = K * acc
   */
Clone this wiki locally