用Python构建深度推荐系统的Python框架

DRec的Python项目详细描述


GitHub versionDocumentation StatusLicense: MITBuild Status

DRecPy:Python的深度推荐者

目录

  1. Introduction
  2. Installation
  3. Getting Started
  4. Implemented Models
  5. Benchmarks
  6. License
  7. Contributors
  8. Development Status

简介

DRecPy是一个Python框架,它使构建基于深度学习的推荐系统变得更加容易, 通过提供各种工具来开发和测试新模型。在

DRecPy提供的主要功能如下:

  • 通过使用名为 InteractionDataset。在
  • Auto Internal to raw id conversion:自动构建从原始标识符到内部标识符的映射,以便所有推荐者都支持包含字符串id或非连续数字id的数据集。在
  • 支持多列数据集,即不限于(user,item,rating)三元组,还支持时间戳、会话、位置等其他列
  • 定义良好的工作流,用于开发基于深度学习的推荐者(同时也支持基于非深度学习的推荐者)。在
  • 使用自定义函数支持epoch回调,其结果将在模型训练结束时记录并显示在绘图中。在
  • Early stopping支持使用自定义函数,这些函数可以使用以前的epoch回调结果或模型丢失值。在
  • 数据集拆分技术根据专用于 推荐系统。在
  • 采样技术用于基于点和基于列表的模型。在
  • 评估过程,用于预测模型以及学习对模型排序。在
  • 自动生成progress loggingplot for loss values during model training,以及 模型评估。在
  • 所有具有随机因子的方法都会收到一个种子参数,以允许结果的再现性。在

有关框架及其组件的更多信息,请访问documentation page。在

以下是每个推荐人的一般呼叫流程的简要概述: Call Worlflow

如果您使用DRecPy进行任何已发表的研究,我们将非常感谢您的引用:

Fábio Colaço, Márcia Barros, and Francisco M. Couto. 2020. DRecPy: A Python Framework for Developing Deep Learning-Based Recommenders. In Fourteenth ACM Conference on Recommender Systems (RecSys '20). Association for Computing Machinery, New York, NY, USA, 675–680. DOI:https://doi.org/10.1145/3383313.3418483

安装

使用pip:

$ pip install drecpy

如果无法从PyPi获取最新版本:

^{pr2}$

或者直接通过克隆Git repo:

$ git clone https://github.com/fabioiuri/DRecPy
$ cd DRecPy
$ python setup.py install

更新版本

如果要更新到最新的DRecPy版本,请使用:

$ pip install drecpy --upgrade

入门

有关如何实现新的推荐程序或扩展现有推荐程序的快速指南和示例,请查看documentation page on creating novel recommenders。在

下面是一个示例脚本,使用一个已实现的推荐程序(CDAE)来训练、使用验证集和评估 它在MovieLens 100k数据集上的排名表现。在

fromDRecPy.RecommenderimportCDAEfromDRecPy.Recommender.EarlyStoppingimportMaxValidationValueRulefromDRecPy.Datasetimportget_train_datasetfromDRecPy.Datasetimportget_test_datasetfromDRecPy.Evaluation.Processesimportranking_evaluationfromDRecPy.Evaluation.Splitsimportleave_k_outfromDRecPy.Evaluation.MetricsimportNDCGfromDRecPy.Evaluation.MetricsimportHitRatiofromDRecPy.Evaluation.MetricsimportPrecisionimporttimeds_train=get_train_dataset('ml-100k')ds_test=get_test_dataset('ml-100k')ds_train,ds_val=leave_k_out(ds_train,k=1,min_user_interactions=10,seed=0)defepoch_callback_fn(model):return{'val_'+metric:vformetric,vinranking_evaluation(model,ds_val,n_pos_interactions=1,n_neg_interactions=100,generate_negative_pairs=True,k=10,verbose=False,seed=10,metrics=[HitRatio(),NDCG()]).items()}start_train=time.time()cdae=CDAE(hidden_factors=50,corruption_level=0.2,loss='bce',seed=10)cdae.fit(ds_train,learning_rate=0.001,reg_rate=0.001,epochs=100,batch_size=64,neg_ratio=5,epoch_callback_fn=epoch_callback_fn,epoch_callback_freq=10,early_stopping_rule=MaxValidationValueRule('val_HitRatio'),early_stopping_freq=10)print("Training took",time.time()-start_train)print(ranking_evaluation(cdae,ds_test,k=[1,5,10],novelty=True,n_pos_interactions=1,n_neg_interactions=100,generate_negative_pairs=True,seed=10,metrics=[HitRatio(),NDCG(),Precision()],max_concurrent_threads=4,verbose=True))

Output

Creating user split tasks: 100%|██████████| 943/943 [00:00<00:00, 4704.11it/s]
Splitting dataset: 100%|██████████| 943/943 [00:03<00:00, 296.04it/s]

[2020-09-02 00:13:37,764] (INFO) CDAE_CLOGGER: Max. interaction value: 5
[2020-09-02 00:13:37,764] (INFO) CDAE_CLOGGER: Min. interaction value: 0
[2020-09-02 00:13:37,764] (INFO) CDAE_CLOGGER: Interaction threshold value: 0.001
[2020-09-02 00:13:37,764] (INFO) CDAE_CLOGGER: Number of unique users: 943
[2020-09-02 00:13:37,765] (INFO) CDAE_CLOGGER: Number of unique items: 1680
[2020-09-02 00:13:37,765] (INFO) CDAE_CLOGGER: Number of training points: 89627
[2020-09-02 00:13:37,765] (INFO) CDAE_CLOGGER: Sparsity level: approx. 94.3426%
[2020-09-02 00:13:37,765] (INFO) CDAE_CLOGGER: Creating auxiliary structures...
[2020-09-02 00:13:37,833] (INFO) CDAE_CLOGGER: Number of registered trainable variables: 5
Fitting model... Epoch 100 Loss: 0.1882 | val_HitRatio@10: 0.5493 | val_NDCG@10: 0.3137 | MaxValidationValueRule best epoch: 80: 100%|██████████| 100/100 [15:05<00:00, 29.77s/it]
[2020-09-02 00:30:02,831] (INFO) CDAE_CLOGGER: Reverting network weights to epoch 80 due to the evaluation of the early stopping rule MaxValidationValueRule.
[2020-09-02 00:30:02,833] (INFO) CDAE_CLOGGER: Network weights reverted from epoch 100 to epoch 80.
[2020-09-02 00:30:02,979] (INFO) CDAE_CLOGGER: Model fitted.

Starting user evaluation tasks: 100%|██████████| 943/943 [00:00<00:00, 2454.84it/s]
Evaluating model ranking performance:  99%|█████████▊| 929/943 [02:16<00:02,  4.81it/s]

{'HitRatio@1': 0.1198, 'HitRatio@5': 0.3945, 'HitRatio@10': 0.5536, 'NDCG@1': 0.1198, 
'NDCG@5': 0.2588, 'NDCG@10': 0.3103, 'Precision@1': 0.1198, 'Precision@5': 0.0789, 'Precision@10': 0.0554}

生成的绘图

  • 培训

CDAE Training Performance

  • 评价

CDAE Evaluation Performance

提供了更多快速简单的示例here。在

实施推荐人

基于深度学习

Recommender TypeName
Learn-to-rankCDAE (Collaborative Denoising Auto-Encoder)
Learn-to-rankDMF (Deep Matrix Factorization)
SequentialCaser

基于非深度学习的

^{tb2}$

基准

托多

许可证

检查LICENCE.md。在

贡献者

这项工作是在Francisco M.Couto教授的监督下进行的,在最初的开发阶段,该项目得到了里斯本大学科学院研究机构LASIGE的FCT研究奖学金UID/CEC/00408/2019的资助。在

欢迎公众捐款,如果你想捐款,请打开公关或联系我fabioiuri@live.com。在

发展现状

阿尔法阶段的项目。在

计划工作:

  • 整理丢失的文档
  • 实施更多模型
  • 细化和清理单元测试

如果您有任何错误需要报告或更新建议,您可以使用DRecPy的github issues page或直接通过电子邮件发送给fabioiuri@live.com。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使图像以正确的速度在屏幕上移动,以适应所有显示   内存Java分配:从预先存在/分配的池中分配对象   java这种书写方式?   Java正则表达式查找字符串的开头   java是否可以创建一个类来处理安卓中的所有日志代码(例如log.d(TAG,message))   如何使用Selenium和java单击WebTable任意页面上的WebElement   java解析字符串中的文件名   java刷新JTree内容   java如何覆盖RequestMappingHandler   爪哇数石头、布、剪刀赢了多少   struts中的java无效令牌   swing JTree,优化算法,Java   java Tomcat和SSL:密钥库格式无效