{"id":466227,"date":"2025-07-07T15:05:38","date_gmt":"2025-07-07T15:05:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466227"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466227","title":{"rendered":"<span>RecBole \u2014 \u00ab\u043a\u043e\u043c\u0431\u0430\u0439\u043d\u00bb \u043d\u0430 PyTorch \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c <strong>RecBole<\/strong> \u2014 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430 PyTorch, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0442\u0440\u0438 \u043d\u0430\u0441\u0443\u0449\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043b\u044e\u0431\u043e\u0433\u043e ML-\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u041a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u043a\u0430\u0442\u0430\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 (\u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e MF \u0434\u043e SASRec \u0438 KGAT) \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u2014 \u0431\u0435\u0437 \u0441\u043e\u0442\u043d\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432?<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c YAML, \u0430 \u043d\u0435 \u0432 \u0442\u0440\u0451\u0445 \u0441\u043e\u0442\u043d\u044f\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 CLI?<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u0441\u0442\u043d\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a \u0438 \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043b\u0443\u0447\u0448\u0438\u0439 \u0447\u0435\u043a\u043f\u043e\u0438\u043d\u0442 \u0432 \u043f\u0440\u043e\u0434?<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"bash\">pip install recbole&gt;=1.2 python -m recbole.quick_start.run_recbole --model=BPR --dataset=ml-1m<\/code><\/pre>\n<p>\u0423 RecBole \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 (<code>ml-1m<\/code>, <code>yelp<\/code>, <code>amazon-*<\/code>). \u0421\u0432\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043a\u0438\u0434\u0430\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 <code>dataset\/&lt;name&gt;\/<\/code> \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <strong>Atomic Files<\/strong>:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0444\u0430\u0439\u043b<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;name&gt;.inter<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>user_id<\/code>, <code>item_id<\/code>, <code>rating<\/code>, <code>timestamp<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0432\u0435 \u043f\u0435\u0440\u0432\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;name&gt;.item<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>item_id<\/code>, <code>genre<\/code>, <code>year<\/code>, \u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043b\u044e\u0431\u044b\u0435 side-\u0444\u0438\u0447\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;name&gt;.user<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>user_id<\/code>, <code>age<\/code>, <code>city<\/code>, \u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">optional<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Parquet \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e RecBole \u00ab\u043f\u0440\u043e\u0433\u043b\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u00bb \u0438 CSV.<\/p>\n<h4>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043f\u043b\u0438\u0442<\/h4>\n<p>\u0412 <code>recbole.yaml<\/code> \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e:<\/p>\n<pre><code class=\"yaml\">split_ratio: [0.8, 0.1, 0.1]   # train\/valid\/test group_by_user: True            # \u0447\u0442\u043e\u0431\u044b \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044e\u0437\u0435\u0440\u0430 \u0431\u044b\u043b\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b<\/code><\/pre>\n<p>\u0412\u0441\u0451, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0440\u0443\u0447\u043d\u044b\u0445 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u043e\u0432 \u043d\u0430 pandas.<\/p>\n<h4>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441 API<\/h4>\n<h4>run_recbole<\/h4>\n<pre><code class=\"python\">from recbole.quick_start import run_recbole  run_recbole(     model='LightGCN',          # \u043b\u044e\u0431\u0430\u044f \u0438\u0437 90+ \u043c\u043e\u0434\u0435\u043b\u0435\u0439     dataset='ml-1m',           # \u0438\u043b\u0438 \u043f\u0443\u0442\u044c \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443     config_dict={              # \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0430\u0434 YAML \u0438 CLI         'epochs': 50,         'topk': 10,         'neg_sampling': {'uniform': 1},         'seed': 42,            # \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u00ab\u043f\u043b\u0430\u0432\u0430\u043b\u0438\u00bb     } )<\/code><\/pre>\n<h4>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0428\u0430\u0433<\/p>\n<\/th>\n<th data-colwidth=\"188\" width=\"188\">\n<p align=\"left\">\u0412\u044b\u0437\u043e\u0432<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Config<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0451 \u0438\u0437 <code>recbole.yaml<\/code>, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 CLI <strong>\u0438<\/strong> <code>config_dict<\/code>, \u0434\u0430\u0432\u0430\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443. \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>config.save()<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 YAML \u0434\u043b\u044f \u0440\u0435\u043f\u0440\u043e\u0434\u044e\u0441\u0430.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0414\u0430\u0442\u0430<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>create_dataset<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0447\u0438\u0442\u0430\u0435\u0442 <em>Atomic Files<\/em>, \u0430\u0432\u0442\u043e-\u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0438\u0442 \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0435\u0439 (int\/float\/token\/sequence), \u043f\u0438\u0448\u0435\u0442 \u043c\u0435\u0442\u0430-JSON \u0432 <code>processed\/*.json<\/code>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0421\u0435\u043c\u043f\u043b\u0435\u0440\u044b<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>create_sampler<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u0442\u0440\u043e\u0438\u0442 <code>Sampler<\/code> (point-wise, pair-wise, full-sort). \u0425\u043e\u0442\u0438\u0442\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0435\u0433\u0430\u0442\u0438\u0432 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 <code>neg_sampling.dynamic: 1<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u0435\u043c\u043f\u043b\u0435\u0440 \u0431\u0435\u0437 \u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u041b\u043e\u0430\u0434\u0435\u0440\u044b<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>create_dataloader<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043b\u0435\u043d\u0438\u0432\u043e \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0431\u0430\u0442\u0447\u0438; \u0434\u043b\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u0432\u044c\u0442\u0435 <code>lazy_loading: True<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0451 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u041c\u043e\u0434\u0435\u043b\u044c<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Model<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0432\u044b\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0435\u0439 \u0438\u0437 <code>recbole.model<\/code>. \u0425\u043e\u0442\u0438\u0442\u0435 \u043a\u0430\u0441\u0442\u043e\u043c \u2014 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0439\u0442\u0435\u0441\u044c \u043e\u0442 <code>BaseModel<\/code>, \u0440\u0435\u0433\u0430\u0439\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 <code>register_model<\/code>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0422\u0440\u0435\u043d\u0435\u0440<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Trainer<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\/\u0441\u043a\u0435\u0434\u044c\u044e\u043b\u0435\u0440, early-stopping, \u043b\u043e\u0433\u0433\u0435\u0440. \u0414\u043b\u044f knowledge distillation \u0435\u0441\u0442\u044c <code>KnowledgeDistillationTrainer<\/code>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u042d\u0432\u0430\u043b\u0430\u0440<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Evaluator<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u0447\u0438\u0442\u0430\u0435\u0442 HR@K, NDCG@K, MRR, MAP; <code>full_sort_topk<\/code> \u0440\u0430\u043d\u0436\u0438\u0440\u0443\u0435\u0442 \u0432\u0435\u0441\u044c \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u0430 \u043d\u0435 sampled-\u043d\u0435\u0433\u0430\u0442\u0438\u0432\u044b.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0412\u044b\u0432\u043e\u0434<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\">~<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043b\u0443\u0447\u0448\u0438\u0439 \u0447\u0435\u043a-\u043f\u043e\u0439\u043d\u0442 + \u043b\u043e\u0433 \u0432 <code>\/saved\/LightGCN-&lt;timestamp&gt;\/<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0425\u043e\u0442\u0438\u0442\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 W&amp;B \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 <code>wandb: True<\/code> \u0432 YAML. \u041d\u0443\u0436\u0435\u043d mixed-precision \u2014 <code>train_stage: fp16<\/code>. \u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0447\u0435\u0440\u0435\u0437 CLI: <code>python run_recbole.py --learning_rate=5e-4 --dropout_prob=0.3<\/code>.<\/p>\n<h4>\u0413\u0440\u0430\u043d\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c<\/h4>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u0438\u043a \u2014 \u0440\u043e\u0441\u043a\u043e\u0448\u044c, \u0438 \u043d\u0443\u0436\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443. \u0422\u043e\u0433\u0434\u0430:<\/p>\n<pre><code class=\"python\">from recbole.config import Config from recbole.data import create_dataset, data_preparation from recbole.utils import init_seed from recbole.model.general_recommender import LightGCN from recbole.trainer import Trainer  # 1. \u041a\u043e\u043d\u0444\u0438\u0433 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 + CLI config = Config(model='LightGCN', dataset='ml-1m')      # \u0447\u0438\u0442\u0430\u0435\u0442 recbole.yaml config['epochs'] = 30                                   # \u043e\u0432\u0435\u0440\u0440\u0430\u0439\u0434 \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb  # 2. Dataset init_seed(config['seed']) dataset = create_dataset(config)                        # &lt;RecDataset 1 1000209&gt;  # 3. Sampler \/ Dataloader train_data, valid_data, test_data = data_preparation(config, dataset)  # 4. \u041c\u043e\u0434\u0435\u043b\u044c model = LightGCN(config, dataset).to(config['device'])  # 5. \u0422\u0440\u0435\u043d\u0435\u0440 trainer = Trainer(config, model) best_valid_score, best_valid_result = trainer.fit(     train_data, valid_data, saved=True, show_progress=True)  score, result = trainer.evaluate(test_data, load_best_model=True) print(result)     # {'Recall@10': 0.1627, 'NDCG@10': 0.0894, ...}<\/code><\/pre>\n<h4>Config<\/h4>\n<pre><code class=\"yaml\"># recbole.yaml (\u043a\u0443\u0441\u043e\u0447\u0435\u043a) MODEL_TYPE: Sequential     # \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442, \u0447\u0442\u043e \u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0441\u0442\u044c max_seq_length epochs: 40 neg_sampling:   dynamic: 1 eval_args:   mode: full                # full-sort evaluation   order: RO                 # \u0440\u0435\u0439\u0442\u0438\u043d\u0433 -&gt; \u043e\u043d\u043b\u0430\u0439\u043d   split: {'RS': [0.8,0.1,0.1]} checkpoint_dir: .\/saved\/ wandb: True <\/code><\/pre>\n<p><strong>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435<\/strong>:<\/p>\n<pre><code class=\"python\">cfg = Config(model='SASRec', dataset='ml-1m',              config_dict={'epochs': 10, 'dropout_prob': 0.2})<\/code><\/pre>\n<p><strong>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c<\/strong> \u2014 \u043f\u043e \u043a\u043b\u044e\u0447\u0443: <code>cfg['topk']<\/code>, <code>cfg.final_config_dict<\/code> \u2014 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h4>Dataset \u0438 \u0434\u0440\u0443\u0437\u044c\u044f<\/h4>\n<pre><code class=\"python\">from recbole.data import Dataset dset = Dataset(config)      # \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a torch.utils.data.Dataset len(dset.field2type)        # {'user_id': 'token', 'item_id': 'token', ...}<\/code><\/pre>\n<ul>\n<li>\n<p><strong>Custom \u043f\u043e\u043b\u044f<\/strong> \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432 <code>.inter<\/code> \u0438 \u043e\u043f\u0438\u0448\u0438\u0442\u0435 \u0442\u0438\u043f \u0432 YAML:<\/p>\n<pre><code class=\"yaml\">FIELD_TYPES: {'price': float, 'brand': token}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Sequence -&gt; unrolled<\/strong>. \u0414\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (SASRec, GRU4Rec) RecBole \u0441\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u0442 <code>hist_seq<\/code> \u0438 <code>target_item<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Lazy loading<\/strong> \u0434\u043b\u044f &gt;10 GB \u0434\u0430\u0442:<\/p>\n<pre><code class=\"yaml\">lazy_loading: True<\/code><\/pre>\n<\/li>\n<\/ul>\n<h4>\u0421\u0430\u043c\u043f\u043b\u0435\u0440\u044b \u0438 \u201c\u043a\u043e\u0440\u043c\u0443\u0448\u043a\u0438\u201d<\/h4>\n<pre><code class=\"python\">from recbole.data import (     create_samplers, create_dataloader, data_preparation )  samplers = create_samplers(config, dataset)       # TrainSampler \/ FullSortSampler train_loader, valid_loader, test_loader = create_dataloader(     config, dataset, samplers)<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043d\u0435\u0433\u0430\u0442\u0438\u0432<\/strong>:<\/p>\n<pre><code class=\"yaml\">neg_sampling:   popularity: 1<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 <code>PopularitySampler<\/code> \u2014 item-frequency softmax.<\/p>\n<\/li>\n<li>\n<p><strong>Dynamic Sampler<\/strong> \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0432\u0435\u0436\u0438\u0435 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u044b \u043a\u0430\u0436\u0434\u0443\u044e \u044d\u043f\u043e\u0445\u0443, \u0441\u043f\u0430\u0441\u0430\u044f \u043e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438-leakage.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e \u043c\u043e\u0434\u0435\u043b\u044c<\/h4>\n<pre><code class=\"python\">from recbole.model.abstract_recommender import GeneralRecommender from recbole.model.loss import BPRLoss import torch.nn as nn import torch  class MyDotMF(GeneralRecommender):     def __init__(self, config, dataset):         super().__init__(config, dataset)         self.embedding_size = config['embedding_size']         self.user_embedding = nn.Embedding(             dataset.num(self.USER_ID), self.embedding_size)         self.item_embedding = nn.Embedding(             dataset.num(self.ITEM_ID), self.embedding_size)         self.loss_fct = BPRLoss()      def forward(self, interaction):         user = interaction[self.USER_ID]         pos_item = interaction[self.ITEM_ID]         user_e = self.user_embedding(user)         item_e = self.item_embedding(pos_item)         scores = (user_e * item_e).sum(-1)         return scores      def calculate_loss(self, interaction):         pos_score = self.forward(interaction)         neg_items = interaction[self.NEG_ITEM_ID]         neg_e = self.item_embedding(neg_items)         neg_score = (user_e.unsqueeze(1) * neg_e).sum(-1)         return self.loss_fct(pos_score, neg_score)<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code class=\"python\">from recbole.utils import register_model register_model('MyDotMF', MyDotMF)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 YAML \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e <code>model: MyDotMF<\/code>.<\/p>\n<h4>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0435\u0439\u0441:<\/h4>\n<pre><code class=\"bash\">mkdir -p dataset\/shop python - &lt;&lt;'PY' import pandas as pd, pyarrow.parquet as pq df = pq.read_table('orders.parquet').to_pandas() df[['user_id','sku','ts']].to_csv(     'dataset\/shop\/shop.inter', sep='\\t', index=False) PY<\/code><\/pre>\n<p><code>recbole.yaml<\/code>:<\/p>\n<pre><code class=\"yaml\">field_separator: \"\\t\" USER_ID_FIELD: user_id ITEM_ID_FIELD: sku TIME_FIELD: ts  model: SASRec epochs: 20 learning_rate: 1e-3 neg_sampling: ~ LABEL_FIELD: click topk: 20 metrics: ['Recall', 'NDCG', 'MRR'] device: cuda<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a:<\/p>\n<pre><code class=\"python\">from recbole.quick_start import run_recbole run_recbole(dataset='shop')<\/code><\/pre>\n<p><em>RecBole<\/em> \u0441\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043f\u043b\u0438\u0442, \u0437\u0430\u043b\u0438\u043e\u0433\u0438\u0440\u0443\u0435\u0442 <code>Recall@20<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0447\u0435\u043a-\u043f\u043e\u0439\u043d\u0442 \u0438 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 YAML \u0432 <code>saved\/SASRec-shop-&lt;ts&gt;\/<\/code>.<\/p>\n<h3>\u0424\u0438\u0447\u0438<\/h3>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 neg_sampling \u2014 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442 \u043a NDCG<\/h4>\n<pre><code class=\"yaml\">neg_sampling:   uniform: 1 # \u0438\u043b\u0438   popularity: 1 # \u0438\u043b\u0438   dynamic: 1            # \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 v1.2<\/code><\/pre>\n<p><code>dynamic<\/code> \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c +5 % NDCG@10 vs <code>uniform<\/code>. <\/p>\n<h4>Knowledge-Graph \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0431\u0435\u0440\u0451\u0442\u0435 KGAT\/CFKG\/TransRec, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0444\u0430\u0439\u043b \u0433\u0440\u0430\u0444\u0430:<\/p>\n<pre><code class=\"yaml\">knowledge_graph_file: shop.kg<\/code><\/pre>\n<p>\u0424\u043e\u0440\u043c\u0430\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439: <code>head relation tail<\/code>. RecBole \u0441\u0430\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442 adjacency matrix. <\/p>\n<h4>GPU-OOM \u043b\u043e\u0432\u0443\u0448\u043a\u0430<\/h4>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>train_batch_size<\/code> \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e GPU \u2192 \u0432\u0430\u0448\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432. \u041a\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u043e\u043d\u044f\u0435\u0442\u0435 SASRec \u043d\u0430 <code>A100 40 GB<\/code>, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0441\u043a\u0440\u044b\u0442\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 self-attention \u0440\u0430\u0441\u0442\u0451\u0442 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e \u043e\u0442 <code>max_seq_length<\/code>.<\/p>\n<pre><code class=\"yaml\">train_batch_size: 512     # \u043e\u043a max_seq_length: 200       # \u043e\u043a n_layers: 4               # \u043e\u043a<\/code><\/pre>\n<p>\u0423\u0435\u0445\u0430\u043b\u0438 \u0432 <code>1024\u00d7512\u00d76<\/code> \u2014 \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439, CUDA OOM.<\/p>\n<h4>\u042d\u043a\u0441\u043f\u043e\u0440\u0442 \u0432 \u043f\u0440\u043e\u0434<\/h4>\n<pre><code class=\"python\">torch.save(model.state_dict(), 'lightgcn.pt') # inference model = LightGCN(config, dataset) model.load_state_dict(torch.load('lightgcn.pt', map_location='cpu')) model.eval()<\/code><\/pre>\n<p>\u041d\u0438\u043a\u0430\u043a\u0438\u0445 RecBole-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435: \u0447\u0438\u0441\u0442\u044b\u0439 PyTorch \u0432\u043d\u0443\u0442\u0440\u0438 Docker.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>RecBole \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 80 % \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0440\u0435\u0441\u0451\u0440\u0447\u0430 \u0438 \u00abML-\u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432\u00bb \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435: \u0432\u0430\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0430\u0442\u044c, \u043a\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0443. \u0414\u0430, \u0431\u044b\u0432\u0430\u044e\u0442 \u043a\u0435\u0439\u0441\u044b, \u0433\u0434\u0435 \u043d\u0443\u0436\u0435\u043d Spark\u0438\u043b\u0438 multi-tower \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0434 \u0440\u0435\u043a\u043b\u0430\u043c\u0443 \u2013 \u0442\u043e\u0433\u0434\u0430 \u043f\u043b\u044f\u0448\u0435\u043c \u0440\u0443\u043a\u0430\u043c\u0438. \u041d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0431\u0435\u0439\u0437\u043b\u0430\u0439\u043d\u00bb \u0431\u044b\u0441\u0442\u0440\u0435\u0435 RecBole \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u0443\u043c\u0435\u0435\u0442.<\/p>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441\u00a0\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0438\u043b\u0438\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0438\u0445 \u0432\u00a0\u043f\u0440\u043e\u0434\u0443\u043a\u0442, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u0432\u00a0RecBole\u00a0\u2014 \u043c\u043e\u0449\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430\u00a0PyTorch, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0434\u043e 80% \u0437\u0430\u0434\u0430\u0447 \u0440\u0435\u0441\u0451\u0440\u0447\u0430 \u0438 ML\u2011\u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 90+ \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0435\u0434\u0438\u043d\u044b\u0439 YAML \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0438\u0431\u043a\u0438\u0439 negative sampling \u0438 \u0447\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438\u00a0\u2014 \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0435\u00a0\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u00a0\u0440\u0443\u0442\u0438\u043d\u0443 \u0438\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u00a0\u043f\u0440\u043e\u0434.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u00a0\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 RecBole \u0438 \u043d\u0435\u00a0\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u0434\u0435\u043b\u0438 \u043d\u0430\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a\u00a0\u043d\u0430\u0448\u0435\u043c\u0443 \u0446\u0438\u043a\u043b\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0443\u0440\u043e\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/sdYp\/\" rel=\"noopener noreferrer nofollow\">Data Science\u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f<\/a>!\u00a0\u2014 <em>10\u00a0\u0438\u044e\u043b\u044f \u0432 18:00<\/em> <\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/otus.pw\/d11I\/\" rel=\"noopener noreferrer nofollow\">Random Forest\u00a0\u2014 \u043c\u043e\u0449\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u00a0ML<\/a>\u00a0\u2014 <em>16\u00a0\u0438\u044e\u043b\u044f \u0432 18:00<\/em> <\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/otus.pw\/uJu3\/\" rel=\"noopener noreferrer nofollow\">ML \u0434\u043b\u044f\u00a0\u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u00a0\u2014 \u043f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438 \u0441\u00a0Jupyter Notebook<\/a>\u00a0\u2014 <em>23\u00a0\u0438\u044e\u043b\u044f \u0432 20:00 <\/em> <\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0440\u043e\u043a\u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435: \u043e\u0442\u00a0\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0435\u0439\u0437\u043b\u0430\u0439\u043d\u0430 \u043d\u0430\u00a0\u0441\u0432\u043e\u0451\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u0434\u043e\u00a0\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0432\u00a0inference. \u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c\u00a0\u2014 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u043d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e RecBole \u043c\u043e\u0436\u0435\u0442 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/924426\/\"> https:\/\/habr.com\/ru\/articles\/924426\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c <strong>RecBole<\/strong> \u2014 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430 PyTorch, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043d\u0430 \u0442\u0440\u0438 \u043d\u0430\u0441\u0443\u0449\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043b\u044e\u0431\u043e\u0433\u043e ML-\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>\u041a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u043a\u0430\u0442\u0430\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 (\u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e MF \u0434\u043e SASRec \u0438 KGAT) \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u2014 \u0431\u0435\u0437 \u0441\u043e\u0442\u043d\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432?<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c YAML, \u0430 \u043d\u0435 \u0432 \u0442\u0440\u0451\u0445 \u0441\u043e\u0442\u043d\u044f\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 CLI?<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u0441\u0442\u043d\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a \u0438 \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043b\u0443\u0447\u0448\u0438\u0439 \u0447\u0435\u043a\u043f\u043e\u0438\u043d\u0442 \u0432 \u043f\u0440\u043e\u0434?<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<pre><code class=\"bash\">pip install recbole&gt;=1.2 python -m recbole.quick_start.run_recbole --model=BPR --dataset=ml-1m<\/code><\/pre>\n<p>\u0423 RecBole \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 (<code>ml-1m<\/code>, <code>yelp<\/code>, <code>amazon-*<\/code>). \u0421\u0432\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043a\u0438\u0434\u0430\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 <code>dataset\/&lt;name&gt;\/<\/code> \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <strong>Atomic Files<\/strong>:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0444\u0430\u0439\u043b<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;name&gt;.inter<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>user_id<\/code>, <code>item_id<\/code>, <code>rating<\/code>, <code>timestamp<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0432\u0435 \u043f\u0435\u0440\u0432\u044b\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;name&gt;.item<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>item_id<\/code>, <code>genre<\/code>, <code>year<\/code>, \u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043b\u044e\u0431\u044b\u0435 side-\u0444\u0438\u0447\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;name&gt;.user<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>user_id<\/code>, <code>age<\/code>, <code>city<\/code>, \u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">optional<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Parquet \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e RecBole \u00ab\u043f\u0440\u043e\u0433\u043b\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u00bb \u0438 CSV.<\/p>\n<h4>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043f\u043b\u0438\u0442<\/h4>\n<p>\u0412 <code>recbole.yaml<\/code> \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e:<\/p>\n<pre><code class=\"yaml\">split_ratio: [0.8, 0.1, 0.1]   # train\/valid\/test group_by_user: True            # \u0447\u0442\u043e\u0431\u044b \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044e\u0437\u0435\u0440\u0430 \u0431\u044b\u043b\u0438 \u0432\u0441\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u044b<\/code><\/pre>\n<p>\u0412\u0441\u0451, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0440\u0443\u0447\u043d\u044b\u0445 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u043e\u0432 \u043d\u0430 pandas.<\/p>\n<h4>\u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441 API<\/h4>\n<h4>run_recbole<\/h4>\n<pre><code class=\"python\">from recbole.quick_start import run_recbole  run_recbole(     model='LightGCN',          # \u043b\u044e\u0431\u0430\u044f \u0438\u0437 90+ \u043c\u043e\u0434\u0435\u043b\u0435\u0439     dataset='ml-1m',           # \u0438\u043b\u0438 \u043f\u0443\u0442\u044c \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u043d\u0430\u0431\u043e\u0440\u0443     config_dict={              # \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043d\u0430\u0434 YAML \u0438 CLI         'epochs': 50,         'topk': 10,         'neg_sampling': {'uniform': 1},         'seed': 42,            # \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u00ab\u043f\u043b\u0430\u0432\u0430\u043b\u0438\u00bb     } )<\/code><\/pre>\n<h4>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h4>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0428\u0430\u0433<\/p>\n<\/th>\n<th data-colwidth=\"188\" width=\"188\">\n<p align=\"left\">\u0412\u044b\u0437\u043e\u0432<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Config<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0451 \u0438\u0437 <code>recbole.yaml<\/code>, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 CLI <strong>\u0438<\/strong> <code>config_dict<\/code>, \u0434\u0430\u0432\u0430\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443. \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>config.save()<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 YAML \u0434\u043b\u044f \u0440\u0435\u043f\u0440\u043e\u0434\u044e\u0441\u0430.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0414\u0430\u0442\u0430<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>create_dataset<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0447\u0438\u0442\u0430\u0435\u0442 <em>Atomic Files<\/em>, \u0430\u0432\u0442\u043e-\u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0438\u0442 \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0435\u0439 (int\/float\/token\/sequence), \u043f\u0438\u0448\u0435\u0442 \u043c\u0435\u0442\u0430-JSON \u0432 <code>processed\/*.json<\/code>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0421\u0435\u043c\u043f\u043b\u0435\u0440\u044b<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>create_sampler<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u0442\u0440\u043e\u0438\u0442 <code>Sampler<\/code> (point-wise, pair-wise, full-sort). \u0425\u043e\u0442\u0438\u0442\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0435\u0433\u0430\u0442\u0438\u0432 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 <code>neg_sampling.dynamic: 1<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0441\u0435\u043c\u043f\u043b\u0435\u0440 \u0431\u0435\u0437 \u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u041b\u043e\u0430\u0434\u0435\u0440\u044b<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>create_dataloader<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043b\u0435\u043d\u0438\u0432\u043e \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0431\u0430\u0442\u0447\u0438; \u0434\u043b\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u0432\u044c\u0442\u0435 <code>lazy_loading: True<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0451 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u041c\u043e\u0434\u0435\u043b\u044c<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Model<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0432\u044b\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0435\u0439 \u0438\u0437 <code>recbole.model<\/code>. \u0425\u043e\u0442\u0438\u0442\u0435 \u043a\u0430\u0441\u0442\u043e\u043c \u2014 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0439\u0442\u0435\u0441\u044c \u043e\u0442 <code>BaseModel<\/code>, \u0440\u0435\u0433\u0430\u0439\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 <code>register_model<\/code>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0422\u0440\u0435\u043d\u0435\u0440<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Trainer<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\/\u0441\u043a\u0435\u0434\u044c\u044e\u043b\u0435\u0440, early-stopping, \u043b\u043e\u0433\u0433\u0435\u0440. \u0414\u043b\u044f knowledge distillation \u0435\u0441\u0442\u044c <code>KnowledgeDistillationTrainer<\/code>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u042d\u0432\u0430\u043b\u0430\u0440<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\"><code>Evaluator<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u0447\u0438\u0442\u0430\u0435\u0442 HR@K, NDCG@K, MRR, MAP; <code>full_sort_topk<\/code> \u0440\u0430\u043d\u0436\u0438\u0440\u0443\u0435\u0442 \u0432\u0435\u0441\u044c \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u0430 \u043d\u0435 sampled-\u043d\u0435\u0433\u0430\u0442\u0438\u0432\u044b.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"91\" width=\"91\">\n<p align=\"left\">\u0412\u044b\u0432\u043e\u0434<\/p>\n<\/td>\n<td data-colwidth=\"188\" width=\"188\">\n<p align=\"left\">~<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043b\u0443\u0447\u0448\u0438\u0439 \u0447\u0435\u043a-\u043f\u043e\u0439\u043d\u0442 + \u043b\u043e\u0433 \u0432 <code>\/saved\/LightGCN-&lt;timestamp&gt;\/<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0425\u043e\u0442\u0438\u0442\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 W&amp;B \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 <code>wandb: True<\/code> \u0432 YAML. \u041d\u0443\u0436\u0435\u043d mixed-precision \u2014 <code>train_stage: fp16<\/code>. \u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0447\u0435\u0440\u0435\u0437 CLI: <code>python run_recbole.py --learning_rate=5e-4 --dropout_prob=0.3<\/code>.<\/p>\n<h4>\u0413\u0440\u0430\u043d\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c<\/h4>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u0438\u043a \u2014 \u0440\u043e\u0441\u043a\u043e\u0448\u044c, \u0438 \u043d\u0443\u0436\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443. \u0422\u043e\u0433\u0434\u0430:<\/p>\n<pre><code class=\"python\">from recbole.config import Config from recbole.data import create_dataset, data_preparation from recbole.utils import init_seed from recbole.model.general_recommender import LightGCN from recbole.trainer import Trainer  # 1. \u041a\u043e\u043d\u0444\u0438\u0433 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 + CLI config = Config(model='LightGCN', dataset='ml-1m')      # \u0447\u0438\u0442\u0430\u0435\u0442 recbole.yaml config['epochs'] = 30                                   # \u043e\u0432\u0435\u0440\u0440\u0430\u0439\u0434 \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb  # 2. Dataset init_seed(config['seed']) dataset = create_dataset(config)                        # &lt;RecDataset 1 1000209&gt;  # 3. Sampler \/ Dataloader train_data, valid_data, test_data = data_preparation(config, dataset)  # 4. \u041c\u043e\u0434\u0435\u043b\u044c model = LightGCN(config, dataset).to(config['device'])  # 5. \u0422\u0440\u0435\u043d\u0435\u0440 trainer = Trainer(config, model) best_valid_score, best_valid_result = trainer.fit(     train_data, valid_data, saved=True, show_progress=True)  score, result = trainer.evaluate(test_data, load_best_model=True) print(result)     # {'Recall@10': 0.1627, 'NDCG@10': 0.0894, ...}<\/code><\/pre>\n<h4>Config<\/h4>\n<pre><code class=\"yaml\"># recbole.yaml (\u043a\u0443\u0441\u043e\u0447\u0435\u043a) MODEL_TYPE: Sequential     # \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442, \u0447\u0442\u043e \u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0441\u0442\u044c max_seq_length epochs: 40 neg_sampling:   dynamic: 1 eval_args:   mode: full                # full-sort evaluation   order: RO                 # \u0440\u0435\u0439\u0442\u0438\u043d\u0433 -&gt; \u043e\u043d\u043b\u0430\u0439\u043d   split: {'RS': [0.8,0.1,0.1]} checkpoint_dir: .\/saved\/ wandb: True <\/code><\/pre>\n<p><strong>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435<\/strong>:<\/p>\n<pre><code class=\"python\">cfg = Config(model='SASRec', dataset='ml-1m',              config_dict={'epochs': 10, 'dropout_prob': 0.2})<\/code><\/pre>\n<p><strong>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c<\/strong> \u2014 \u043f\u043e \u043a\u043b\u044e\u0447\u0443: <code>cfg['topk']<\/code>, <code>cfg.final_config_dict<\/code> \u2014 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h4>Dataset \u0438 \u0434\u0440\u0443\u0437\u044c\u044f<\/h4>\n<pre><code class=\"python\">from recbole.data import Dataset dset = Dataset(config)      # \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a torch.utils.data.Dataset len(dset.field2type)        # {'user_id': 'token', 'item_id': 'token', ...}<\/code><\/pre>\n<ul>\n<li>\n<p><strong>Custom \u043f\u043e\u043b\u044f<\/strong> \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432 <code>.inter<\/code> \u0438 \u043e\u043f\u0438\u0448\u0438\u0442\u0435 \u0442\u0438\u043f \u0432 YAML:<\/p>\n<pre><code class=\"yaml\">FIELD_TYPES: {'price': float, 'brand': token}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Sequence -&gt; unrolled<\/strong>. \u0414\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (SASRec, GRU4Rec) RecBole \u0441\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u0442 <code>hist_seq<\/code> \u0438 <code>target_item<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Lazy loading<\/strong> \u0434\u043b\u044f &gt;10 GB \u0434\u0430\u0442:<\/p>\n<pre><code class=\"yaml\">lazy_loading: True<\/code><\/pre>\n<\/li>\n<\/ul>\n<h4>\u0421\u0430\u043c\u043f\u043b\u0435\u0440\u044b \u0438 \u201c\u043a\u043e\u0440\u043c\u0443\u0448\u043a\u0438\u201d<\/h4>\n<pre><code class=\"python\">from recbole.data import (     create_samplers, create_dataloader, data_preparation )  samplers = create_samplers(config, dataset)       # TrainSampler \/ FullSortSampler train_loader, valid_loader, test_loader = create_dataloader(     config, dataset, samplers)<\/code><\/pre>\n<ul>\n<li>\n<p><strong>\u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043d\u0435\u0433\u0430\u0442\u0438\u0432<\/strong>:<\/p>\n<pre><code class=\"yaml\">neg_sampling:   popularity: 1<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 <code>PopularitySampler<\/code> \u2014 item-frequency softmax.<\/p>\n<\/li>\n<li>\n<p><strong>Dynamic Sampler<\/strong> \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0432\u0435\u0436\u0438\u0435 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u044b \u043a\u0430\u0436\u0434\u0443\u044e \u044d\u043f\u043e\u0445\u0443, \u0441\u043f\u0430\u0441\u0430\u044f \u043e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438-leakage.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u044e \u043c\u043e\u0434\u0435\u043b\u044c<\/h4>\n<pre><code class=\"python\">from recbole.model.abstract_recommender import GeneralRecommender from recbole.model.loss import BPRLoss import torch.nn as nn import torch  class MyDotMF(GeneralRecommender):     def __init__(self, config, dataset):         super().__init__(config, dataset)         self.embedding_size = config['embedding_size']         self.user_embedding = nn.Embedding(             dataset.num(self.USER_ID), self.embedding_size)         self.item_embedding = nn.Embedding(             dataset.num(self.ITEM_ID), self.embedding_size)         self.loss_fct = BPRLoss()      def forward(self, interaction):         user = interaction[self.USER_ID]         pos_item = interaction[self.ITEM_ID]         user_e = self.user_embedding(user)         item_e = self.item_embedding(pos_item)         scores = (user_e * item_e).sum(-1)         return scores      def calculate_loss(self, interaction):         pos_score = self.forward(interaction)         neg_items = interaction[self.NEG_ITEM_ID]         neg_e = self.item_embedding(neg_items)         neg_score = (user_e.unsqueeze(1) * neg_e).sum(-1)         return self.loss_fct(pos_score, neg_score)<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code class=\"python\">from recbole.utils import register_model register_model('MyDotMF', MyDotMF)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 YAML \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e <code>model: MyDotMF<\/code>.<\/p>\n<h4>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0435\u0439\u0441:<\/h4>\n<pre><code class=\"bash\">mkdir -p dataset\/shop python - &lt;&lt;'PY' import pandas as pd, pyarrow.parquet as pq df = pq.read_table('orders.parquet').to_pandas() df[['user_id','sku','ts']].to_csv(     'dataset\/shop\/shop.inter', sep='\\t', index=False) PY<\/code><\/pre>\n<p><code>recbole.yaml<\/code>:<\/p>\n<pre><code class=\"yaml\">field_separator: \"\\t\" USER_ID_FIELD: user_id ITEM_ID_FIELD: sku TIME_FIELD: ts  model: SASRec epochs: 20 learning_rate: 1e-3 neg_sampling: ~ LABEL_FIELD: click topk: 20 metrics: ['Recall', 'NDCG', 'MRR'] device: cuda<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a:<\/p>\n<pre><code class=\"python\">from recbole.quick_start import run_recbole run_recbole(dataset='shop')<\/code><\/pre>\n<p><em>RecBole<\/em> \u0441\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043f\u043b\u0438\u0442, \u0437\u0430\u043b\u0438\u043e\u0433\u0438\u0440\u0443\u0435\u0442 <code>Recall@20<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u0447\u0435\u043a-\u043f\u043e\u0439\u043d\u0442 \u0438 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 YAML \u0432 <code>saved\/SASRec-shop-&lt;ts&gt;\/<\/code>.<\/p>\n<h3>\u0424\u0438\u0447\u0438<\/h3>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 neg_sampling \u2014 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442 \u043a NDCG<\/h4>\n<pre><code class=\"yaml\">neg_sampling:   uniform: 1 # \u0438\u043b\u0438   popularity: 1 # \u0438\u043b\u0438   dynamic: 1            # \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 v1.2<\/code><\/pre>\n<p><code>dynamic<\/code> \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c +5 % NDCG@10 vs <code>uniform<\/code>. <\/p>\n<h4>Knowledge-Graph \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0431\u0435\u0440\u0451\u0442\u0435 KGAT\/CFKG\/TransRec, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0444\u0430\u0439\u043b \u0433\u0440\u0430\u0444\u0430:<\/p>\n<pre><code class=\"yaml\">knowledge_graph_file: shop.kg<\/code><\/pre>\n<p>\u0424\u043e\u0440\u043c\u0430\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439: <code>head relation tail<\/code>. RecBole \u0441\u0430\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442 adjacency matrix. <\/p>\n<h4>GPU-OOM \u043b\u043e\u0432\u0443\u0448\u043a\u0430<\/h4>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>train_batch_size<\/code> \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e GPU \u2192 \u0432\u0430\u0448\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432. \u041a\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u043e\u043d\u044f\u0435\u0442\u0435 SASRec \u043d\u0430 <code>A100 40 GB<\/code>, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0441\u043a\u0440\u044b\u0442\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 self-attention \u0440\u0430\u0441\u0442\u0451\u0442 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e \u043e\u0442 <code>max_seq_length<\/code>.<\/p>\n<pre><code class=\"yaml\">train_batch_size: 512     # \u043e\u043a max_seq_length: 200       # \u043e\u043a n_layers: 4               # \u043e\u043a<\/code><\/pre>\n<p>\u0423\u0435\u0445\u0430\u043b\u0438 \u0432 <code>1024\u00d7512\u00d76<\/code> \u2014 \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439, CUDA OOM.<\/p>\n<h4>\u042d\u043a\u0441\u043f\u043e\u0440\u0442 \u0432 \u043f\u0440\u043e\u0434<\/h4>\n<pre><code class=\"python\">torch.save(model.state_dict(), 'lightgcn.pt') # inference model = LightGCN(config, dataset) model.load_state_dict(torch.load('lightgcn.pt', map_location='cpu')) model.eval()<\/code><\/pre>\n<p>\u041d\u0438\u043a\u0430\u043a\u0438\u0445 RecBole-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435: \u0447\u0438\u0441\u0442\u044b\u0439 PyTorch \u0432\u043d\u0443\u0442\u0440\u0438 Docker.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>RecBole \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 80 % \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0440\u0435\u0441\u0451\u0440\u0447\u0430 \u0438 \u00abML-\u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432\u00bb \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0430\u043a\u0435\u0442\u0435: \u0432\u0430\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0430\u0442\u044c, \u043a\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043a\u043e\u0440\u043c\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0443. \u0414\u0430, \u0431\u044b\u0432\u0430\u044e\u0442 \u043a\u0435\u0439\u0441\u044b, \u0433\u0434\u0435 \u043d\u0443\u0436\u0435\u043d Spark\u0438\u043b\u0438 multi-tower \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0434 \u0440\u0435\u043a\u043b\u0430\u043c\u0443 \u2013 \u0442\u043e\u0433\u0434\u0430 \u043f\u043b\u044f\u0448\u0435\u043c \u0440\u0443\u043a\u0430\u043c\u0438. \u041d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0431\u0435\u0439\u0437\u043b\u0430\u0439\u043d\u00bb \u0431\u044b\u0441\u0442\u0440\u0435\u0435 RecBole \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u0430\u043b\u043e \u0447\u0442\u043e \u0443\u043c\u0435\u0435\u0442.<\/p>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441\u00a0\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0438\u043b\u0438\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0438\u0445 \u0432\u00a0\u043f\u0440\u043e\u0434\u0443\u043a\u0442, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u0432\u00a0RecBole\u00a0\u2014 \u043c\u043e\u0449\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430\u00a0PyTorch, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0434\u043e 80% \u0437\u0430\u0434\u0430\u0447 \u0440\u0435\u0441\u0451\u0440\u0447\u0430 \u0438 ML\u2011\u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 90+ \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0435\u0434\u0438\u043d\u044b\u0439 YAML \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0433\u0438\u0431\u043a\u0438\u0439 negative sampling \u0438 \u0447\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438\u00a0\u2014 \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0435\u00a0\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u00a0\u0440\u0443\u0442\u0438\u043d\u0443 \u0438\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u00a0\u043f\u0440\u043e\u0434.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u00a0\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 RecBole \u0438 \u043d\u0435\u00a0\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u0434\u0435\u043b\u0438 \u043d\u0430\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a\u00a0\u043d\u0430\u0448\u0435\u043c\u0443 \u0446\u0438\u043a\u043b\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0443\u0440\u043e\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/sdYp\/\" rel=\"noopener noreferrer nofollow\">Data Science\u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f<\/a>!\u00a0\u2014 <em>10\u00a0\u0438\u044e\u043b\u044f \u0432 18:00<\/em> <\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/otus.pw\/d11I\/\" rel=\"noopener noreferrer nofollow\">Random Forest\u00a0\u2014 \u043c\u043e\u0449\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u00a0ML<\/a>\u00a0\u2014 <em>16\u00a0\u0438\u044e\u043b\u044f \u0432 18:00<\/em> <\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/otus.pw\/uJu3\/\" rel=\"noopener noreferrer nofollow\">ML \u0434\u043b\u044f\u00a0\u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445\u00a0\u2014 \u043f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438 \u0441\u00a0Jupyter Notebook<\/a>\u00a0\u2014 <em>23\u00a0\u0438\u044e\u043b\u044f \u0432 20:00 <\/em> <\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0440\u043e\u043a\u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435: \u043e\u0442\u00a0\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0435\u0439\u0437\u043b\u0430\u0439\u043d\u0430 \u043d\u0430\u00a0\u0441\u0432\u043e\u0451\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u0434\u043e\u00a0\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0432\u00a0inference. \u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c\u00a0\u2014 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u043d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e RecBole \u043c\u043e\u0436\u0435\u0442 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/924426\/\"> https:\/\/habr.com\/ru\/articles\/924426\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466227","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466227"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466227\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}