tensorflow:: ops:: FixedUnigramCandidateSampler

#include <candidate_sampling_ops.h>

学習済みの単語分布に基づいて、候補サンプリング用のラベルを生成します。

まとめ

ユニグラムサンプラーは、データから動的に分布を構築する代わりに、ファイルから読み込んだ、またはメモリ配列として渡された固定ユニグラム分布を使用することができます。また、重みに歪み係数を適用することで分布を歪めるオプションもあります。

語彙ファイルはCSV形式に準じたもので、最後のフィールドには単語に関連付けられた重みを記述する必要があります。

この操作は、各バッチに対して、サンプリングされた候補ラベルのセットを1つ選択します。

バッチごとに候補をサンプリングする利点は、シンプルさと効率的な密行列乗算が可能であることである。欠点は、サンプリングされた候補をコンテキストや真のラベルとは無関係に選択する必要があることである。

議論:

  • スコープ:スコープオブジェクト
  • true_classes: batch_size * num_true の行列。各行には、対応する元のラベル内の num_true 個の target_classes の ID が含まれます。
  • num_true: コンテキストごとの真のラベルの数。
  • num_sampled: ランダムにサンプリングする候補の数。
  • unique: uniqueが真の場合、棄却サンプリングを行い、バッチ内のサンプリングされた候補はすべて一意になるようにします。これには、棄却後のサンプリング確率を推定するための近似計算が必要です。
  • range_max: サンプラーは区間[0, range_max)から整数をサンプリングします。

オプション属性( Attrs参照):

  • vocab_file: このファイル(CSV形式である必要があります)内の有効な各行は、有効な単語IDに対応します。IDはnum_reserved_idsから始まる連番です。各行の最後のエントリは、出現回数または相対確率に対応する値である必要があります。vocab_fileとunigramsのうち、いずれか一方のみをこの操作に渡す必要があります。
  • 歪み:歪みは、単語の出現確率分布を歪めるために使用されます。各重みは、内部の単語分布に加算される前に、まず歪みのべき乗に上げられます。その結果、歪み=1.0では(語彙ファイルで定義されているように)規則的な単語サンプリングが行われ、歪み=0.0では均一な分布となります。
  • num_reserved_ids: ユーザーは、オプションで [0, ..., num_reserved_ids) の範囲に予約済み ID を追加できます。使用例の 1 つは、特別な未知の単語トークンを ID 0 として使用する場合です。これらの ID のサンプリング確率は 0 になります。
  • num_shards: サンプラーを使用すると、元の範囲のサブセットからサンプリングすることで、並列処理によって全体の計算を高速化できます。このパラメータ(「shard」パラメータと併せて)は、全体の計算で使用されるパーティションの数を示します。
  • shard: サンプラーを使用すると、元の範囲のサブセットからサンプリングすることで、並列処理によって全体の計算を高速化できます。このパラメータ('num_shards' と併せて)は、パーティショニングを使用する場合に、サンプラー操作の特定のパーティション番号を示します。
  • unigrams: ユニグラムの出現回数または出現確率のリスト。IDごとに1つずつ、順番に並びます。vocab_fileとunigramsのうち、どちらか一方のみをこの操作に渡してください。
  • seed: seedまたはseed2のいずれかがゼロ以外の値に設定されている場合、乱数生成器は指定されたシード値で初期化されます。それ以外の場合は、ランダムなシード値で初期化されます。
  • seed2: シードの衝突を避けるための2つ目のシード。

返品:

  • Output sampled_candidates: 長さ num_sampled のベクトル。各要素はサンプリングされた候補の ID です。
  • Output true_expected_count: バッチサイズ * num_true の行列。サンプリングされた候補のバッチ内で各候補が出現すると予想される回数を表します。unique=true の場合、これは確率です。
  • Output sampled_expected_count: 長さ num_sampled のベクトル。サンプリングされた候補ごとに、その候補がサンプリングされた候補のバッチ内で出現すると予想される回数を表します。unique=true の場合、これは確率です。

コンストラクターとデストラクタ

FixedUnigramCandidateSampler (const :: tensorflow::Scope & scope, :: tensorflow::Input true_classes, int64 num_true, int64 num_sampled, bool unique, int64 range_max)
FixedUnigramCandidateSampler (const :: tensorflow::Scope & scope, :: tensorflow::Input true_classes, int64 num_true, int64 num_sampled, bool unique, int64 range_max, const FixedUnigramCandidateSampler::Attrs & attrs)

公開属性

operation
sampled_candidates
sampled_expected_count
true_expected_count

パブリック静的関数

Distortion (float x)
NumReservedIds (int64 x)
NumShards (int64 x)
Seed (int64 x)
Seed2 (int64 x)
Shard (int64 x)
Unigrams (const gtl::ArraySlice< float > & x)
VocabFile (StringPiece x)

構造

tensorflow:: ops:: FixedUnigramCandidateSampler:: Attrs

FixedUnigramCandidateSamplerのオプション属性セッター。

公開属性

手術

Operation operation

サンプリングされた候補者

::tensorflow::Output sampled_candidates

サンプリングされた期待値

::tensorflow::Output sampled_expected_count

真の期待値

::tensorflow::Output true_expected_count

公的機能

固定ユニグラム候補サンプラー

 FixedUnigramCandidateSampler(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input true_classes,
  int64 num_true,
  int64 num_sampled,
  bool unique,
  int64 range_max
)

固定ユニグラム候補サンプラー

 FixedUnigramCandidateSampler(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input true_classes,
  int64 num_true,
  int64 num_sampled,
  bool unique,
  int64 range_max,
  const FixedUnigramCandidateSampler::Attrs & attrs
)

パブリック静的関数

ねじれ

Attrs Distortion(
  float x
)

予約済みIDの数

Attrs NumReservedIds(
  int64 x
)

ナムシャード

Attrs NumShards(
  int64 x
)

シード

Attrs Seed(
  int64 x
)

シード2

Attrs Seed2(
  int64 x
)

破片

Attrs Shard(
  int64 x
)

ユニグラム

Attrs Unigrams(
  const gtl::ArraySlice< float > & x
)

語彙ファイル

Attrs VocabFile(
  StringPiece x
)