プリンキピア

第21章推薦システム

21.3.1. The Matrix Factorization Model21.3.1 行列分解のモデル

Matrix factorization is a class of collaborative filtering models. Specifically, the model factorizes the user-item interaction matrix (e.g., rating matrix) into the product of two lower-rank matrices, capturing the low-rank structure of the user-item interactions.
英語のヒント
行列分解は、協調フィルタリングのモデルの一種である。具体的には、このモデルは、利用者とアイテムのやりとり行列(たとえば評価行列)を二つのより低いランクの行列の積に分解し、利用者とアイテムのやりとりの低ランクの構造をとらえる。
Let 𝐑∈ℝm×n denote the interaction matrix with m users and n items, and the values of 𝐑 represent explicit ratings. The user-item interaction will be factorized into a user latent matrix 𝐏∈ℝm×k and an item latent matrix 𝐐∈ℝn×k, where k≪m,n, is the latent factor size. Let 𝐩u denote the uth row of 𝐏 and 𝐪i denote the ith row of 𝐐. For a given item i, the elements of 𝐪i measure the extent to which the item possesses those characteristics such as the genres and languages of a movie. For a given user u, the elements of 𝐩u measure the extent of interest the user has in items’ corresponding characteristics. These latent factors might measure obvious dimensions as mentioned in those examples or are completely uninterpretable. The predicted ratings can be estimated by
英語のヒント
𝐑∈ℝm×nを、m人の利用者とn個のアイテムからなるやりとり行列とし、𝐑の値は明示的な評価を表すとする。利用者とアイテムのやりとりは、利用者の潜在行列𝐏∈ℝm×kとアイテムの潜在行列𝐐∈ℝn×kに分解される。ここでk≪m,nは潜在因子の大きさである。𝐩uを𝐏のuthの行、𝐪iを𝐐のithの行とする。与えられたアイテムiについて、𝐪iの要素は、映画のジャンルや言語のような特性をそのアイテムがどの程度もっているかを測る。与えられた利用者uについて、𝐩uの要素は、アイテムの対応する特性にその利用者がどの程度関心をもっているかを測る。これらの潜在因子は、これらの例で述べたような明らかな次元を測っていることもあれば、まったく解釈できないこともある。予測される評価は次の式で推定できる。
𝐑ˆ=𝐏𝐐⊤(21.3.1)
where 𝐑ˆ∈ℝm×n is the predicted rating matrix which has the same shape as 𝐑. One major problem of this prediction rule is that users/items biases can not be modeled. For example, some users tend to give higher ratings or some items always get lower ratings due to poorer quality. These biases are commonplace in real-world applications. To capture these biases, user specific and item specific bias terms are introduced. Specifically, the predicted rating user u gives to item i is calculated by
英語のヒント
ここで𝐑ˆ∈ℝm×nは、𝐑と同じ形をした予測評価行列である。この予測規則の大きな問題の一つは、利用者やアイテムのバイアスをモデル化できないことである。たとえば、高めの評価をつけがちな利用者もいれば、質が劣るためにいつも低めの評価を受けるアイテムもある。こうしたバイアスは、現実の応用ではありふれている。これらのバイアスをとらえるため、利用者に固有のバイアス項とアイテムに固有のバイアス項を導入する。具体的には、利用者uがアイテムiにつける予測評価は、次の式で計算される。
𝐑ˆui=𝐩u𝐪i⊤+bu+bi(21.3.2)
Then, we train the matrix factorization model by minimizing the mean squared error between predicted rating scores and real rating scores. The objective function is defined as follows:
英語のヒント
それから、予測された評価の点数と実際の評価の点数の間の平均二乗誤差を最小化することで、行列分解のモデルを訓練する。目的関数は次のように定義される。
argmin𝐏,𝐐,b∑(u,i)∈𝒦∥𝐑ui−𝐑ˆui∥2+λ(∥𝐏∥F2+∥𝐐∥F2+bu2+bi2)(21.3.3)
where λ denotes the regularization rate. The regularizing term λ(∥𝐏∥F2+∥𝐐∥F2+bu2+bi2) is used to avoid over-fitting by penalizing the magnitude of the parameters. The (u,i) pairs for which 𝐑ui is known are stored in the set 𝒦={(u,i)∣𝐑ui is known}. The model parameters can be learned with an optimization algorithm, such as Stochastic Gradient Descent and Adam.
英語のヒント
ここでλは正則化率を表す。正則化項λ(∥𝐏∥F2+∥𝐐∥F2+bu2+bi2)は、パラメータの大きさに罰則を科すことで過学習を避けるために使われる。𝐑uiがわかっている(u,i)の組は、集合𝒦={(u,i)∣𝐑ui is known}に保存される。モデルのパラメータは、確率的勾配降下法やAdamのような最適化アルゴリズムで学習できる。
An intuitive illustration of the matrix factorization model is shown below:
英語のヒント
行列分解のモデルを直観的に図解すると、次のようになる。
Fig. 21.3.1図21.3.1
Illustration of matrix factorization model
英語のヒント
行列分解のモデルの図解
In the rest of this section, we will explain the implementation of matrix factorization and train the model on the MovieLens dataset.
英語のヒント
この節の残りでは、行列分解の実装を説明し、MovieLensのデータセットでモデルを訓練する。
import mxnet as mx
from mxnet import autograd, gluon, np, npx
from mxnet.gluon import nn
from d2l import mxnet as d2l

npx.set_np()