【论文学习】MIND

585 阅读5分钟

原文链接

简介

论文提出了一个用于新闻推荐的大规模新闻数据集(MIND),从Microsoft News3的用户行为日志中采集的到(数据集链接),包含100万用户以及他们对超过16万篇英语新闻文章的点击行为数据。此外,论文还实现了多种现有的新闻推荐方法,并在MIND上进行测试取得了较好的效果,这些方法之前都是在其他不同数据集上测试的。

数据集

数据集结构

数据集从2019年10月12日至12月22日期间随机采样了一百万用户的至少5条新闻点击记录。为了保护用户隐私,使用一次性salt10映射的匿名ID实现每个用户和生产系统的解耦。用户的行为日志被格式化成印象日志(impression logs),印象日志记录用户在特定时间访问新闻网站首页时显示的新闻文章,及其对这些新闻的点击行为。在新闻推荐中,我们通常需要预测用户是否会点击候选新闻,因此将用户的新闻点击历史添加到他们的印象日志中,以构建标签样本来训练和验证新闻推荐模型。

每个标记样本的格式如下所示:

[uID,t,ClickHist,ImpLog][uID,t,ClickHist,ImpLog]

其中,uID指每个用户的匿名ID,t表示印象数据的时间戳,ClickHist是用户之前点击过的新闻列表(按照点击时间排序),ImpLog包含该印象中新闻的IDs以及它们是否被点击过的标记,即[(nID1,label1),(nID2,label2),...][(nID_1,label_1),(nID_2,label_2),...]nID为新闻ID,label表示该新闻是否被点击过。

数据集详细统计信息如表2和图2所示。 image.png

训练数据和验证数据都是一个压缩文件夹,其中包含四个不同的文件:

文件名简介
behaviors.tsv用户的点击历史和印象日志
news.tsv新闻文章信息
entity_embedding.vec从知识图谱中提取新闻实体的嵌入
relation_embedding.vec从知识图谱中提取的实体之间关系的嵌入

behaviors.tsv

文件内容如下所示: image.png

列名简介
Impression ID一个印象的ID
User ID匿名用户ID
Time印象记录时间,格式为“MM/DD/YYYY HH:MM:SS AM/PM”
History该用户在此印象之前的新闻点击历史(点击新闻的ID列表),按点击时间排序,例子: N121652
Impressions印象中包含的新闻及用户对其的点击行为(1点击,0未点击),印象中的新闻顺序是被打乱的,例子:N129416-0

news.tsv

文件内容如下图所示:

image.png

列名简介
News ID新闻ID
Category分类
Title标题
Abstract简介
URL链接
Title Entities标题实体
Abstract Entites简介实体

“实体”列中的字典键的描述如下:

列名简介
Label维基百科知识图谱中的实体名称
Type该实体在维基百科中的类型
WikidataId维基百科中的实体ID
Confidence实体链接的可信度
OccurrenceOffsets标题或摘要文本中的字符级实体偏移量
SurfaceForms原文本中的原始实体名称

entity_embedding.vec & relation_embedding.vec

文件内容如下所示 image.png

通过TransE方法从子图(从维基百科知识图谱)学到的实体和关系的100维嵌入。

使用示例

以Deep Knowledge-Aware Network for News Recommendation(DKN)为例:

训练模型需要输入两个参数hparamsDKNTextIterator

model = DKN(hparams, DKNTextIterator)

hparams : hyperparameters 超参数

  • 超参数:在开始机器学习之前人为设置的参数。
  • 相对的是模型参数:通过训练得到的模型参数。
hparams = prepare_hparams(yaml_file,
                          news_feature_file = news_feature_file,
                          user_history_file = user_history_file,
                          wordEmb_file=wordEmb_file,
                          entityEmb_file=entityEmb_file,
                          contextEmb_file=contextEmb_file,
                          epochs=epochs,
                          history_size=history_size,
                          batch_size=batch_size)
yaml_file(str):YAML配置文件,训练配置参数

DKN使用dkn.yaml,文件内容如下:

data:
  doc_size: 10 # Each feature length should be fixed at doc_size, if the number of words in document is more than doc_size, you should truncate the document to doc_size words, and if the number of words in document is less than doc_size, you should padding 0. 
  history_size: 50 # Max number of user click history, we will automatically keep the last his_size number of user click history, if users' click history is more than his_size, and we will automatically padding 0 if less than his_size.
  word_size: 12600 # word vocabulary size
  entity_size: 3987 # entity vocabulary size
  data_format: dkn
  
info:
  metrics:
  - auc
  pairwise_metrics:
  - group_auc
  - mean_mrr
  - ndcg@5;10
  show_step: 10000 # print loss every show_step batches
  
model:
  method : classification
  activation:
  - sigmoid
  attention_activation: relu
  attention_dropout: 0.0
  attention_layer_sizes: 100

  dim: 100 # word embedding dim
  use_entity: true # use entity embedding
  use_context: true # use context embedding
 
  entity_dim: 100 # entity embedding dim
  transform: true # add a transform layer for entity and context embeddings
 
  dropout:
  - 0.0
  filter_sizes: # window size of kcnn filters
  - 1
  - 2
  - 3
  layer_sizes: # layer size for final prediction score layer
  - 300
  # model_type: DKN_with_context
  model_type: dkn
  num_filters: 100 # number of filter for each filter_size in kcnn part

train:
  batch_size: 100
  embed_l1: 0.000
  embed_l2: 0.000001
  epochs: 50
  init_method: uniform
  init_value: 0.1
  layer_l1: 0.000
  layer_l2: 0.000001
  learning_rate: 0.0005
  loss: log_loss
  optimizer: adam
  save_model: False
  save_epoch : 2 # save model every save_epoch epochs
  enable_BN : True
  • data:样本数据基本设置
  • info:包括度量和每一步损失显示等设置
  • model:设置分类、激活函数、dropout、层数、word embedding dim(词嵌入的列维度)、kcnn滤波器的窗口大小、最终预测分数层的规模、num_filters(KCNN部分中每个filter_size的过滤器数量)
  • train:训练参数设置:batch_size(一次1 个iteration使用的样本数)、epochs(一次epoch指用训练集的所有样本都训练过一次)、ptimizer(优化方法:adam)、save_model(是否保存模型)、save_epoch(每隔几个epoch保存一次模型)。
其余参数设置
yaml_file = os.path.join(data_path, r'dkn.yaml')
train_file = os.path.join(data_path, r'train_mind_demo.txt')
valid_file = os.path.join(data_path, r'valid_mind_demo.txt')
test_file = os.path.join(data_path, r'test_mind_demo.txt')
news_feature_file = os.path.join(data_path, r'doc_feature.txt')
user_history_file = os.path.join(data_path, r'user_history.txt')
wordEmb_file = os.path.join(data_path, r'word_embeddings_100.npy')
entityEmb_file = os.path.join(data_path, r'TransE_entity2vec_100.npy')
contextEmb_file = os.path.join(data_path, r'TransE_context2vec_100.npy')

epochs = 10
history_size = 50
batch_size = 100
prepare_hparams函数

config为一个字典(dict),由传入的参数构成:

 if kwargs:
        for name, value in kwargs.items():
            config[name] = value

返回 return create_hparams(config)

create_hparams函数

创建模型超参数,返回tf.contrib.training.HParamsTF中的一个超参数对象

print(hparams) image.png

DKNTextIterator DKN模型的数据加载器

DKN需要一种特殊类型的数据格式,其中每个实例包含一个标签、候选新闻文章、和用户点击过的新闻文章。文章由标题词和标题实体表示。单词和实体 是一致的。

迭代器不会将整个数据加载到内存中,而是在每个小的batch中加载数据到内存中,因此确保大文件可以作为输入数据。