forked from OSSInnovation/mindspore
!5960 [ModelZoo]Add bgcf epoch time print
Merge pull request !5960 from zhanke/bgcf
This commit is contained in:
commit
20991a0718
|
@ -50,7 +50,7 @@ def novelty_at_k(topk_items, item_degree_dict, num_user, k):
|
|||
"""Calculate the novelty at k"""
|
||||
avg_nov = []
|
||||
for item in topk_items[:k]:
|
||||
avg_nov.append(-np.log2(item_degree_dict[item] / num_user))
|
||||
avg_nov.append(-np.log2((item_degree_dict[item] + 1e-8) / num_user))
|
||||
return np.mean(avg_nov)
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
BGCF training script.
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
import datetime
|
||||
|
||||
from mindspore import Tensor
|
||||
|
@ -56,6 +57,7 @@ def train_and_eval():
|
|||
|
||||
for _epoch in range(1, parser.num_epoch + 1):
|
||||
|
||||
epoch_start = time.time()
|
||||
iter_num = 1
|
||||
|
||||
for data in itr:
|
||||
|
@ -96,7 +98,7 @@ def train_and_eval():
|
|||
if iter_num == num_iter:
|
||||
print('Epoch', '%03d' % _epoch, 'iter', '%02d' % iter_num,
|
||||
'loss',
|
||||
'{}'.format(train_loss))
|
||||
'{}, cost:{:.4f}'.format(train_loss, time.time() - epoch_start))
|
||||
iter_num += 1
|
||||
|
||||
if _epoch % parser.eval_interval == 0:
|
||||
|
|
Loading…
Reference in New Issue