テンソルフロー::作戦::固定UnigramCandidateSampler

#include <candidate_sampling_ops.h>

学習されたユニグラム分布を使用して候補サンプリングのラベルを生成します。

まとめ

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

語彙ファイルは CSV のような形式である必要があり、最後のフィールドは単語に関連付けられた重みです。

この操作は、バッチごとに、サンプリングされた候補ラベルの単一セットを選択します。

バッチごとに候補をサンプリングする利点は、単純さと効率的な密行列乗算の可能性です。欠点は、サンプリングされた候補がコンテキストや真のラベルとは独立して選択されなければならないことです。

引数:

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

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

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

戻り値:

  • Output sampled_candidates: 長さnum_sampledのベクトル。各要素はサンプリングされた候補のIDです。
  • Output true_expected_count: サンプリングされた候補のバッチ内で各候補が出現すると予想される回数を表す、batch_size * 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

true_expected_count

::tensorflow::Output true_expected_count

公共機能

固定UnigramCandidateSampler

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

固定UnigramCandidateSampler

 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
)

NumReservedIds

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
)