KGAT推荐系统

1:数据处理,数据分割。2:模型构建。包括各个网络的搭建损失函数的设计等。3:构建trainer,包括模型训练fit,和模型评估evaluate。4:数据预测
1:数据处理,数据分割
根据需要的数据集合inter,link,kg数据。进行remap。数据进行分割操作包括以8:1:1的方式分割成train,valid,test。并且根据模型的不同计算neg_item。kg_neg_item。最后返回三个dataloader。
2:KGAT模型构建
网络层的设计,Loss设计,以及Aggarater设计,A的初始化,Cal_Loss,Cal_kg_loss,Updata_A,predict。
3:构建trainer,包括,构建优化器,fit函数,和evaluate函数。

1:数据处理
拼接路径
kg_path = os.path.join(dataset_path, f’{token}.kg’)

‘/Users/apple/Desktop/Code/Recommendation_System/rec/config/…/dataset_example/ml-100k/ml-100k.kg’

这个为拼接起来的路径加文件。

with open(kg_path, ‘r’) as f:
head = f.readline()[:-1]

‘head_id:token\trelation_id:token\ttail_id:token’

for field_type in head.split(field_separator):
field, ftype = field_type.split(‘:’)
columns.append(field)
usecols.append(field_type)
dtype[field_type] = np.float64 if ftype == FeatureType.FLOAT else str

columns->[‘head_id’, ‘relation_id’, ‘tail_id’]
usecols->[‘head_id:token’, ‘relation_id:token’, ‘tail_id:token’]
dtype->{‘head_id:token’: <class ‘str’>, ‘relation_id:token’: <class ‘str’>, ‘tail_id:token’: <class ‘str’>}

之后用df = pd.read_csv(filepath, delimiter=self.config[‘field_separator’], usecols=usecols, dtype=dtype)读取数据
读取的kg数据
请添加图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值