首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tf.optimizer更新稀疏输入的所有现有权重

tf.optimizer更新稀疏输入的所有现有权重
EN

Stack Overflow用户
提问于 2018-07-17 12:04:06
回答 0查看 77关注 0票数 0

我正在使用tf通过FTRLOp为稀疏数据集训练LR模型。代码片段如下:

代码语言:javascript
复制
feature_columns = [
       tf.feature_column.categorical_column_with_hash_bucket('query_id',15),
       tf.feature_column.categorical_column_with_hash_bucket('ad_id',15),
       tf.feature_column.categorical_column_with_hash_bucket('cat_id',15),
    ]
label_column = tf.feature_column.numeric_column('label', dtype=tf.float32, default_value=0)
columns = feature_columns + [label_column]
cols_to_vars = {}
parsed_example = tf.parse_example(serialized_example, tf.feature_column.make_parse_example_spec(columns))
logits = tf.feature_column.linear_model(
            features=parsed_example,
            feature_columns=feature_columns,
            cols_to_vars=cols_to_vars
        )
loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(labels=label, logits=logits))
optimizer = tf.train.FtrlOptimizer(learning_rate=0.5, learning_rate_power=-0.5, initial_accumulator_value=0.5,  l1_regularization_strength=2, l2_regularization_strength=0.1)

可训练对象= tf.trainable_variables() grads_and_vars =tf.gradients(损失,可训练对象)

输入是稀疏的和分类的,输入是热的,并且记住非零的索引,例如,前两个记录是: 6,10,13 3,9,12梯度显示:The result of first record only input: current gradients is: IndexedSlicesValue(values=array([[0.5]], dtype=float32), indices=array([6]), dense_shape=array([15, 1], dtype=int32)) current gradients is: IndexedSlicesValue(values=array([[0.5]], dtype=float32), indices=array([10]), dense_shape=array([15, 1], dtype=int32)) current gradients is: IndexedSlicesValue(values=array([[0.5]], dtype=float32), indices=array([13]), dense_shape=array([15, 1], dtype=int32)) current gradients is: [0.5]

Result of first two input: current gradients is: IndexedSlicesValue(values=array([[0.25], [0.25]], dtype=float32), indices=array([6, 3]), dense_shape=array([15, 1], dtype=int32)) current gradients is: IndexedSlicesValue(values=array([[0.25], [0.25]], dtype=float32), indices=array([10, 9]), dense_shape=array([15, 1], dtype=int32)) current gradients is: IndexedSlicesValue(values=array([[0.25], [0.25]], dtype=float32), indices=array([13, 12]), dense_shape=array([15, 1], dtype=int32)) current gradients is: [0.5]

由于第二个记录在6,10,13中没有值,所以我认为处理完第二个记录时,梯度不应该改变。这似乎与Ftrl论文中的计算不同。

有什么错误被指出吗?提前感谢

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51373072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档