#506·DeepCTR

dropout和batchnorm层已经传了training,outputs._uses_learning_phase = training is not None的作用是什么?

Author: DaemoonnCreated Dec 13, 2022Updated Dec 13, 2022
Labelsquestion

Describe the question(问题描述) 既然DNN中的bn_layers和dropout_layers已经传入了training状态参数来区分是在训练还是在预测阶段,手动设置_uses_learning_phase的作用是什么? 我的tf版本2.10.0,应该是执行outputs._uses_learning_phase = training is not None https://github.com/shenweichen/DeepCTR/blob/e8f4d818f9b46608bc95bb60ef0bb0633606b2f2/deepctr/layers/sequence.py#L266-L288

在求attention_score的时候,不是已经把training状态传给DNN里的dropout和batchnorm层了吗? https://github.com/shenweichen/DeepCTR/blob/e8f4d818f9b46608bc95bb60ef0bb0633606b2f2/deepctr/layers/sequence.py#L266

https://github.com/shenweichen/DeepCTR/blob/e8f4d818f9b46608bc95bb60ef0bb0633606b2f2/deepctr/layers/core.py#L104 https://github.com/shenweichen/DeepCTR/blob/e8f4d818f9b46608bc95bb60ef0bb0633606b2f2/deepctr/layers/core.py#L198 https://github.com/shenweichen/DeepCTR/blob/e8f4d818f9b46608bc95bb60ef0bb0633606b2f2/deepctr/layers/core.py#L205

为什么还需要对_uses_learning_phase手动设置? https://github.com/shenweichen/DeepCTR/blob/e8f4d818f9b46608bc95bb60ef0bb0633606b2f2/deepctr/layers/sequence.py#L283-L286

这里手动设置_uses_learning_phase是否发挥实际作用?去掉会怎么样?对于outputs这个tf.Tensor来说,好像是没有_uses_learning_phase这个类属性,这么写好像是临时新建个了_uses_learning_phase属性,然后赋值成xxx

outputs._uses_learning_phase = xxx

求大佬指点

Additional context Add any other context about the problem here.

Operating environment(运行环境):

  • python version 3.9.12
  • tensorflow version 2.10.0
  • deepctr version 0.9.3