1. 学ぶ
  2. /
  3. コース
  4. /
  5. Kerasで学ぶMachine Translation

Connected

演習

パート2: to_categorical() 関数を探る

パート1では、one-hot ベクトルの計算で num_classes 引数を使わない compute_onehot_length() 関数を実装しました。

num_classes 引数は、to_categorical() 関数が生成する one-hot エンコード済みベクトルの長さを制御します。語彙が異なる2つのコーパス(テキストの集合)を扱う場合、num_classes を指定しないままにすると、one-hot ベクトルの長さが異なることがあります。

この演習では、compute_onehot_length() 関数と word2index 辞書が用意されています。

指示

100 XP
  • words_1 に対して compute_onehot_length() を呼び出します。
  • words_2 に対して compute_onehot_length() を呼び出します。
  • words_1 と words_2 で得られた one-hot ベクトルの長さを出力します。