LoginSignup
9
3

More than 5 years have passed since last update.

tensorflowのpad_sequencesは何をするか?

Posted at

pad_sequencesは何をするか?

  • Text classification with movie reviewsの pad_sequences は何をするか?

    • 要素の合わない配列に対して、0 で埋めるなどして配列のサイズを一致させる。
      • 入力
        • 以下のようにサイズの合わない配列を要素とする二次元配列を入力とする。
       [[1, 2, 3], [3, 4, 5, 6, 7], [9, 10]]
      
      • 出力
        • 前方の要素を 0 埋めしてサイズの一致した2次元配列を返す。
       [[0, 0, 1, 2, 3],
       [3, 4, 5, 6, 7],
       [0, 0, 0, 9, 10]]
      
      • サンプルコード
       from tensorflow import keras
       output = keras.preprocessing.sequence.pad_sequences([[1, 2, 3], [3, 4, 5, 6, 7], [9, 10]])
       print(output)
      
       # 出力は以下
       # [[ 0  0  1  2  3]
       #  [ 3  4  5  6  7]
       #  [ 0  0  0  9 10]]
      
    • 各種設定

      • 穴埋めする値、前方か後方のどちらを穴埋めするか、最大サイズなどを指定できる。マニュアルを参照。
9
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
3