chainer.functions.negative_sampling(x, t, W, sampler, sample_size, reduce='sum')[source]

負例サンプリング損失関数。

 

自然言語処理において、特に、言語モデル化において、総語彙数は極めて大きくなり得ます。 ゆえに、埋め込み行列の勾配計算には膨大な時間が必要になります

 

この負例サンプリングを用いる事によって、幾つかの標本化されたサンプル負例の勾配を計算するだけでよいことになります。

目的関数は下記のとおり:

f(x,p)=logσ(xwp)+ kEiP(i)[logσ(xwi)],f(x,p)=log⁡σ(x⊤wp)+ kEi∼P(i)[log⁡σ(−x⊤wi)],

ただし σ()σ(⋅) はシグモイド関数、 wiwi iは単語iiの荷重ベクトル、 pp は正例。.これは確率P(i)から標本化された  kk の例 NN で近似される。

f(x,p)logσ(xwp)+ nNlogσ(xwn).f(x,p)≈log⁡σ(x⊤wp)+ ∑n∈Nlog⁡σ(−x⊤wn).

各 NN のサンプルは 単語分布 P(w)P(w)から求められる。 これは、次のように計算される。 P(w)=1Zc(w)αP(w)=1Zc(w)α, ただし、 c(w)c(w) は 単語 wwのユニグラム(1-gram)数、 αα はハイパーパラメータ、  ZZ は 規格化定数。

 

Parameters:
  • x (Variable) – 入力ベクトルのバッチ
  • t (Variable) – Vector of ground truth labels.グランドトゥルースラベルのベクトル。
  • W (Variable) – 荷重行列。
  • sampler (FunctionType) – 標本化関数。これは、 shapeを引数にとり、このshapeの整数配列を返す。この配列の各要素は単語分布からの標本である。単語の出現頻度のべき分布で構築されたWalkerAlias オブジェクトが推奨されている。
  • sample_size (int) – サンプル数。
  • reduce (str) – 削減オプション。この値は 'sum' か 'noを設定しなければならない。それ以外ではValueError が発生する。
Returns:

A variable holding the loss value(s) calculated by the above equation. If reduce is 'no', the output variable holds array whose shape is same as one of (hence both of) input variables. If it is 'sum', the output variable holds a scalar value.

Return type:

Variable

 

お読みください: Distributed Representations of Words and Phrases and their Compositionality

こちらもお読みください

NegativeSampling.