Keras One Горячие Входы - PullRequest
0 голосов
/ 21 мая 2018

У меня есть языковая модель, которую я обучаю выводить «следующий символ» с заданной последовательностью до 50 входных символов.

В настоящее время модель завершается ошибкой из-за неверного измерения ввода со следующей ошибкой:

$ python -u neural-lm.py
C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
loading training data generator...
skipped 107 lines where sequence length > padded_seq_length...
loading dev data generator...
skipped 5 lines where sequence length > padded_seq_length...
Traceback (most recent call last):
  File "neural-lm.py", line 29, in <module>
    clnlm.add(Bidirectional(LSTM(units=padded_seq_length, name='lstm_layer_initial', return_sequences=True, recurrent_dropout=0.9, kernel_regularizer=l2, activity_regularizer=l2 ), input_shape=(padded_seq_length, alphabet_length)))
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\models.py", line 497, in add
    layer(x)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\layers\wrappers.py", line 325, in __call__
    return super(Bidirectional, self).__call__(inputs, **kwargs)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 592, in __call__
    self.build(input_shapes[0])
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\layers\wrappers.py", line 445, in build
    self.forward_layer.build(input_shape)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\layers\recurrent.py", line 461, in build
    self.cell.build(step_input_shape)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\layers\recurrent.py", line 1799, in build
    constraint=self.kernel_constraint)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 418, in add_weight
    self.add_loss(regularizer(weight))
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\regularizers.py", line 58, in l2
    return L1L2(l2=l)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\regularizers.py", line 35, in __init__
    self.l2 = K.cast_to_floatx(l2)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\keras\backend\common.py", line 110, in cast_to_floatx
    return np.asarray(x, dtype=_FLOATX)
  File "C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\numpy\core\numeric.py", line 492, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
(tensorflow)

Мой вход указан в соответствии с рекомендациями модели Seqeuntial:

alphabet_length = 28
padded_seq_length = 50
clnlm = Sequential()
clnlm.add(Bidirectional(LSTM(units=padded_seq_length, name='lstm_layer_initial', return_sequences=True, recurrent_dropout=0.9, kernel_regularizer=l2, activity_regularizer=l2 ), input_shape=(padded_seq_length, alphabet_length)))
...

Входные данные предоставлены генератором, но я могу проверить одно горячее кодирование без вывода, и вывод выглядиткак это:

$ python -u lm_utils.py
C:\Users\username\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
_______________________here is an example sentence
________________________________the cat in the hat
_________________________________________________z
_________________________________________________x
_________________________________________________
one_hot:  [[0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 1. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]
(50, 28)
one_hot:  [[0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [1. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]
(50, 28)
one_hot:  [[0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 ...
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 1. 0. 0.]]
(50, 28)
one_hot:  [[0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 ...
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 0.]]
(50, 28)
one_hot:  [[0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 ...
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 1. 0.]]
(50, 28)
(tensorflow)

Я понимаю, что ошибка означает, что один из входов неправильно применяет последовательность к отдельному элементу, что неправильно.Я надеялся, что кто-то может взвесить и дать мне некоторые указания относительно того, что я могу изменить и / или проверить, чтобы двигаться вперед.

...