python2 没有控制循环变量的变量名的作用域,致使同名变量冲突了,这在 python3 中已经修复。
使用了相同的变量名,导致先前的变量指向了另一个变量,导致错误。来自 DIEN 代码
...
uid = self.source_dicts[0][ss[1]] if ss[1] in self.source_dicts[0] else 0 # user id-number
mid = self.source_dicts[1][ss[2]] if ss[2] in self.source_dicts[1] else 0 # item id-number
cat = self.source_dicts[2][ss[3]] if ss[3] in self.source_dicts[2] else 0 # category id-number
is the default value for any (user, item, category) not appear in training data
can be found in generate_voc.py default_mid, default_cat
tmp = []
for mid in ss[4].split(""): # mid_str, change name fea -> mid,** bug in here! **
id_number = self.source_dicts[1][mid] if mid in self.source_dicts[1] else 0
tmp.append(mid_number)
mid_list = tmp
...
更坑之处在于,tensorflow 报错指向的地方不对,指向的是最后一个点,
prob, loss, acc, aux_loss = model.calculate(sess, [uids, mids, cats, mid_his, cat_his, mid_mask, target, sl, noclk_mids, noclk_cats, timeinterval_history_np, timelast_history_np, timenow_history_np])
一直说是 timenow_history_np 对应的 self.timenow_history: inps[12],
出错,实际上是 mids, cats 出错。
这是需要把 [uids, mids, cats, mid_his, cat_his, mid_mask, target, sl, noclk_mids, noclk_cats, timeinterval_history_np, timelast_history_np, timenow_history_np]
全部打印出来,才能发现错误。