一、赛题描述
赛题:Amazon Cross-Market Recommendation
举办方:University of Amsterdam / University of Massachusetts Amherst / Amazon
AI问题:语义相似度识别
比赛类型:推荐系统
主页:https://xmrec.github.io/wsdmcup/
WSDM的全称是Web Search and Data Mining Conference,由Google Research主办,属于ACM SIGKDD旗下的会议。竞赛通常围绕实际问题,提供数据集和评估指标,鼓励参与者提出创新解决方案。此外,往年的竞赛题目可能涉及推荐系统、搜索引擎优化、数据挖掘等热点领域。
赛题背景
电子商务公司通常跨市场运营;例如亚马逊已将业务和销售扩展到全球18 个市场(即国家/地区)。跨市场推荐涉及通过利用类似的高资源市场的数据向目标市场的用户推荐相关产品的问题,例如利用美国市场的数据改进目标市场的推荐。
然而关键的挑战是数据,例如用户与产品的交互数据(点击、购买、评论),传达了个别市场的某些偏见。因此在源市场上训练的算法在不同的目标市场不一定有效。
赛题目标
在本次WSDM杯挑战赛中,我们提供不同市场的用户购买和评分数据,目标是通过利用来自类似辅助市场的数据来改进这些目标市场中的个人推荐系统。
评估指标
使用NDCG@10进行评估,项目的分数为每个用户排序,前10个项目被考虑进行评估。
二、数据集内容
数据样例和使用Python读取数据的代码样例如下:
评分/Ratings
使用以下代码,考虑一用户对一商品的评分,以下是代码样例:
import pandas as pd
cur_ratings = 'ratings_uk_Books.txt.gz' # specify the url to the file
df = pd.read_csv(cur_ratings, compression='gzip', header=None, sep=' ', names=["userId", "itemId", "rate", "date"] )
以UK市场为例,输出样例如下:
+------------------------------+------------+--------+------------+
| userId | itemId | rate | date |
|------------------------------+------------+--------+------------|
| AFXKARXBL3X3LO5GNN4XAXC7XMPQ | 0061806765 | 3 | 2012-08-20 |
| AH3Z5FFVAQYVQNDBUG2M23ZZBCGA | 0007273754 | 5 | 2013-11-24 |
| AHDFCI7XXY5J7GIDWWE2VSLPQMCQ | 1682307530 | 4 | 2016-06-29 |
| AE5KNHUMUIHXU3FCRBDMTTZT7UYA | 1611097843 | 5 | 2014-05-29 |
| AEEHVF74E2QB7UP7VG4LFSUNXVJA | 0142410586 | 4 | 2020-04-13 |
+------------------------------+------------+--------+------------+
where
userId - ID of the reviewer
itemId - asin or the ID of the product, e.g. B014RDFCFI
rate - rating of the product in the range of 1-5
date - date of the review in the format of YYYY-MM-DD
评价/Reviews
Review files provide a list of json objects, each providing a customer review for a given product. For reading these files you can read line by line and obtain the json dictionary of a specific review as below.
import gzip
example_rev_file = 'reviews_uk_Books.json.gz'
review_lines = []
with gzip.open(example_rev_file, 'rt', encoding='utf8') as f:
review_lines = f.readlines()
print( eval(review_lines[1].strip())[0] )
输出样例:
{
'reviewerID': 'AGIBLPPKMJ7NUQ2MCD3RW2OQXUAQ',
'asin': '0001047868',
'reviewerName': 'christine mcgill',
'reviewText': 'I thourghly enjoyed this classic, read it when I was ten so was greatly surprised that it seemed even better than I remembered.',
'overall': 5.0,
'summary': 'I thourghly enjoyed this classic',
'cleanReviewTime': '2015-09-29',
'reviewTime': '29 September 2015'
}
where
reviewerID - ID of the reviewer equivalent to userId of ratings
asin - ID of the product equivalent to the itemId of ratings, e.g. B014RDFCFI
reviewerName - name of the reviewer
reviewText - text of the review
overall - rating of the product in the range of 1-5
summary - summary of the review
cleanReviewTime - date of the review in the format of YYYY-MM-DD
reviewTime - original review time posted along with the review in the local market calendar
商品元数据/Metadata
Metadata includes product descriptions, price, sales-rank, brand info, and co-purchasing links. For reading, similar to reviews, use the below python code snippet.
import gzip
example_met_file = 'metadata_us_Electronics.json.gz'
meta_lines = []
with gzip.open(example_met_file, 'rt', encoding='utf8') as f:
meta_lines = f.readlines()
print( eval(meta_lines[80].strip()) )
以上代码输出样例:
{'asin': 'B000023VW2',
'title': 'Sangean ANT-60 Short Wave Antenna',
'averageRating': '4.3',
'ratingCount': '698 global ratings',
'amazon_badge': 'Amazon\'s \nChoice for "shortwave antenna"',
'ratingDist': {'5': '67%', '4': '14%', '3': '10%', '2': '3%', '1': '6%'},
'ratingByFeature': {},
'price': '$12.86',
'imgUrl': '{"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX569_.jpg":[369,569],"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX355_.jpg":[230,355],"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX425_.jpg":[276,425],"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX450_.jpg":[292,450],"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX466_.jpg":[303,466],"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX522_.jpg":[339,522],"https://images-na.ssl-images-amazon.com/images/I/71-XmouTyhL._AC_SX679_.jpg":[441,679]}',
'related': {
'sponsored': ['B000NOSCN0', 'B07NRSWB6Q', 'B00008N9M7', 'B0823N6DWV', 'B07NRNVCTV', 'B00QXJMZRS', 'B07SXF87LJ', 'B07P8BW3P2', 'B07YN62TM1', 'B07CNMDTY8', 'B000NOSCN0', 'B00R6VXD6Y', 'B074QLLVC6', 'B00008N9M7', 'B00QXJMZRS', 'B07R284TN5','B01N3POQ92', 'B07P8BW3P2', 'B07R3QG1CR','B000O8SQNG'],
'alsoBought': [],
'alsoViewed': ['B0104MT5HW', 'B00GJ51NVA', 'B08464KCG1', 'B0055Q5FIQ', 'B082B4C7CC', 'B001KC579Q', 'B0141X3B5W', 'B00IDM4N5K', 'B07T6LK1X2', 'B004H912FC', 'B08HCYYW88', 'B07T2FQH6N', 'B0104J57GS', 'B0014T7W8Y', 'B001HX4D84', 'B004QJKO52', 'B01ARN28SQ', 'B07T1F6LDY', '1999830024', 'B00X15M5MC', 'B08BLF7QDV', 'B005OEA88Q', 'B0035X1EC2', 'B01MSMRASH', 'B078JKXCYH', 'B085ZSXF8Z', 'B009ENG6TI','B00BLW627G', 'B001P4LTAU'],
'boughtTogether': ['B000023VW2', 'B005KVJYTW', 'B004H912FC'],
'compared': ['B000023VW2', 'B01I27ZOQM','B082B4C7CC', 'B001PNNXGO', 'B001KC579Q', 'B0055Q5FIQ']
},
'productDetails': {
'Product Dimensions': '5.98 x 8.27 x 0.94 inches',
'Item Weight': '1.41 ounces',
'Manufacturer': 'Sangean',
'ASIN': 'B000023VW2',
'Item model number': 'ANT-60',
'Customer Reviews': ['/*',
'* Fix for UDP-1061. Average customer reviews has a small extra line on hover',
'* https://omni-grok.amazon.com/xref/src/appgroup/websiteTemplates/retail/SoftlinesDetailPageAssets/udp-intl-lock/src/legacy.css?indexName=WebsiteTemplates#40'],
'Best Sellers Rank': '#13 in Radio Antennas',
'Is Discontinued By Manufacturer': 'No',
'Date First Available': 'October 15, 1999'},
'sellerPage': '/stores/SANGEAN/page/E550CD6C-93E0-447F-B3F0-A06E71DF322F?ref_=ast_bln',
'categories': ['Electronics',
'Accessories & Supplies',
'Audio & Video Accessories',
'Antennas',
'Radio Antennas'],
'description': "From the Manufacturer\nShortwave radios brought the world together long before the Internet, and now the Sangean ANT-60 antenna helps maximize your shortwave experience. Ideally suited for today's compact shortwave receiver and fully portable inside its convenient, compact carrying case, the ANT-60 extends to a full 23 feet and enhances the performance and reception of your shortwave radio beyond that of a typical built-in telescoping antenna. An adapter plug is provided for those receivers lacking a standard 1/8-inch (3.5mm) miniplug.",
'overviewFeatures': {},
'features': ['Improves the performance and reception of your shortwave radio',
'Extends to 23 feet and can be easily rewound into its compact case',
'Has 3.5-millimeter mini plug',
'Fits any 3.5-millimeter external antenna jack',
'Includes adapter plug'],
'reviewFilters': []}
Where
asin - ID of the product, e.g. see B000023VW2
title - name of the product
averageRating - the average rate of the product in the time of obtaining the data, float number [1-5]
ratingCount - how many users rate this product
amazon_badge - if there is any badge associated with this product
ratingDist - the distribution of each rating value
related - related products (also bought, also viewed, bought together, compared, and sponsored) are listed
productDetails - a variety of information related to the product, including brand, category, descriptions, features, etc. are all provided in this dictionary. See the product page for further information on each of these fields provided with our data.
已打包数据集范围
已打包电商数据集文件AiS-NLP-Retail-WSDM2021-Amazon-Cross-Market-Recommendation-DataSet-2.6G.zip包括以下商品种类和地区:
商品种类:
Category | Users | Items | Ratings |
---|---|---|---|
Arts Crafts and Sewing | |||
Automotive | |||
Books |
地区:
- Australia (au)
- Brazil (br)
- Canada (ca)
- China (cn)
- Germany (de)
- United Arab Emirates (ae)
- United States (us)
数据集引用要求
@inproceedings{bonab2021crossmarket,
author = {Bonab, Hamed and Aliannejadi, Mohammad and Vardasbi, Ali and Kanoulas, Evangelos and Allan, James},
booktitle = {Proceedings of the 30th ACM International Conference on Information \& Knowledge Management},
publisher = {ACM},
title = {Cross-Market Product Recommendation},
year = {2021}}
三、解决方案样例
以下为发表于 CIKM2021 的论文《Cross-Market Product Recommendation》(跨市场产品推荐)相关的代码。
问题定义与输入
场景:用户已在市场A购买了商品X,需推荐市场B的商品列表。
输入数据:
- 用户行为序列:用户历史购买/点击记录(跨市场)。
- 商品属性:商品ID、类别、描述(通过Embedding编码)。
- 跨市场关联:商品在不同市场的共现关系(如市场A的商品X与市场B的商品Y的频繁共同购买)。
Embedding编码
Embedding编码是人工智能中一种将高维稀疏符号数据(如文本、类别标签、图像等)映射到低维稠密连续向量的技术。它的核心目标是通过数值化表示捕捉数据的语义和结构关系,从而让机器学习模型更高效地处理复杂任务。
为什么需要 Embedding?
传统方法(如 One-Hot 编码)存在以下问题:
- 维度灾难:类别数量极大时(如商品ID有百万级),One-Hot 向量维度极高且稀疏(大部分元素为0),导致模型计算效率低下。
- 无法表达语义:One-Hot 编码仅表示类别是否存在,无法体现语义关联(如“苹果”和“水果”的关系)。
- 冷启动问题:新出现的类别(如新品)缺乏历史数据,难以初始化。
Embedding 解决方案
将类别变量压缩到低维空间(如 50~300 维)。稠密向量包含语义信息(相似事物映射到邻近空间)。减少维度的同时保留关键特征。
Embedding 的核心思想
数学表示:将每个符号(如单词、商品)映射为一个稠密向量 v i ∈R (d) ,其中 d 是嵌入维度。 语义学习:通过训练使语义相关的符号向量距离更近(如“猫”和“狗”比“猫”和“电脑”更接近)。 上下文感知:在特定任务(如推荐)中,向量会根据上下文动态调整(如用户点击行为影响商品Embedding)。
常见应用场景
(a) 自然语言处理(NLP) 词嵌入:将单词映射为向量(如 Word2Vec、GloVe、BERT)。 句子嵌入:将整个句子编码为固定长度向量(如 Sentence-BERT)。 (b) 推荐系统 用户Embedding:表示用户兴趣偏好。 商品Embedding:捕获商品属性和语义特征。 跨领域迁移:利用源领域(如市场A)的Embedding初始化目标领域(如市场B)。 (c) 图像处理 像素压缩:将高分辨率图像映射为低维特征向量。 跨模态表示:联合学习图像和文本的共享语义空间。
代码使用的数据集
本解决方案中的DATA文件夹包含我们实验中使用的清洗后的结构化数据。请注意,我们在发布版本的数据中进行了少量优化调整(例如标准化缺失值、合并重复条目),因此您可能会发现部分数值指标与论文中报告的结果存在 细微差异。
安装开发包
文件:requirements.txt
learn2learn==0.1.6
numpy==1.21.4
pandas==1.3.4
python-dateutil==2.8.2
pytrec-eval==0.5
torch==1.10.0
torchvision==0.11.1
tqdm==4.62.3
执行:pip install -r requirements.txt
跨市场电商数据利用
数据特点:同一商品在不同市场(如美国、德国、印度)的用户行为(点击、购买、评分)存在显著差异。例如: 美国用户可能更倾向购买iPhone,而德国用户更偏好Samsung。不同市场对同一商品的评分标准不同(如墨西哥用户评分普遍偏高)。存在的挑战为:直接迁移源市场模型会导致偏差,需通过适应性调整消除市场间差异。
FOREC模型架构
FOREC(Market Adaptation via Pre-training, Forking, and Fine-tuning)架构通过三阶段实现跨市场适配:
(1) 预训练(Pre-training) 目标:学习市场无关的通用特征表示。 方法: 使用元学习(MAML框架)在多个源市场联合训练基础模型(如Neural Matrix Factorization, NMF)。 模型参数初始化为各市场数据的加权平均,捕捉跨市场共性(如用户兴趣的通用模式)。 (2) 分叉(Forking) 目标:在通用模型基础上构建目标市场专用模型。 方法: 冻结底层参数:保留预训练的通用特征提取层(如用户/物品嵌入层和基础MLP层)。 添加市场头部(MarketHead):在顶层新增若干全连接层,用于学习目标市场的特异性。 冻结策略:仅训练新添加的头部层,避免破坏通用特征。 (3) 微调(Fine-tuning) 目标:针对目标市场数据进行参数优化。 方法: 使用目标市场的用户-商品交互数据,仅更新MarketHead层的参数。 可选:结合少量源市场数据(如热门商品)增强泛化能力。
训练
我们提供了三个训练脚本,用于训练基线模型(单市场模型、GMF、MLP、NMF++ 和 MAML)以及 FOREC 模型。以下是可通过这些脚本进行训练和评估的模型列表:
train_base.py
:用于训练跨市场模型的 GMF、MLP、NMF 及其增强版本(+后缀型号)train_maml.py
:用于训练我们的 MAML 基线模型train_forec.py
:用于训练我们提出的 FOREC 模型
注意事项:
- 由于 MAML 和 FOREC 基于 NMF 架构,需在训练这两个模型前先完成 NMF++ 模型的训练
- NMF 模型需要 GMF 和 MLP 模型已预先训练(该模型通过在这些模型基础上增加额外层进行融合,详见上文 FOREC 架构图中部说明)
自动化训练配置: 我们提供了 Jupyter Notebook (train_all.ipynb
),可自动生成针对任意目标市场与增强源市场组合的完整训练命令。请通过该代码包进行训练流程管理。默认使用服务器端的 Slurm 作业管理系统,但您可修改代码包中的 Bash 脚本生成部分以适配本地环境。所有自动生成的脚本将保存在笔记本创建的 scripts
文件夹中,训练日志则存储于该目录下的 log
子目录。
评估与输出说明: 每个训练脚本均会在验证集和测试集上进行评估(数据划分采用留一法 – 详见 data.py
)。详细评估结果将以 JSON 格式输出至 EVAL
文件夹。我们将在后续提供完整的训练检查点文件和评估结果汇总文件。
源码开源协议
Author:
PhD Candidate at UMass Amherst
8 followers · 4 following
University of Massachusetts Amherst
Amherst, MA
四、参考资料
《Cross-Market Product Recommendation-2109.05929v1.pdf》