3

Keras의 SimpleRNN에서 텍스트를 학습하려고합니다. Keras에서 Keras SimpleRNN에서 input_shape가 3-d로 지정되었을 때 오류가 발생했습니다.

, 나는 다음과 같이 SimpleRNN에 대한 매우 간단한 매개 변수를 지정 : 나는 input_shape이 (nb_samples, 시간 단계, input_dim), 내 train_x.shape와 동일해야 이해

model = Sequential() 
model.add(SimpleRNN(output_dim=1, input_shape=(1,1,1)) 

그래서 나는 다음과 같은 오류가 발생했다는 것에 놀랐다.

Traceback (most recent call last): 
    File "C:/Users/xxx/xxxx/xxx/xxx.py", line 262, in <module> 
    model.add(SimpleRNN(output_dim=vocab_size, input_shape=train_x.shape)) 
    File "C:\Anaconda3\envs\py34\lib\site-packages\keras\models.py", line 275, in add 
    layer.create_input_layer(batch_input_shape, input_dtype) 
    File "C:\Anaconda3\envs\py34\lib\site-packages\keras\engine\topology.py", line 367, in create_input_layer 
    self(x) 
    File "C:\Anaconda3\envs\py34\lib\site-packages\keras\engine\topology.py", line 467, in __call__ 
    self.assert_input_compatibility(x) 
    File "C:\Anaconda3\envs\py34\lib\site-packages\keras\engine\topology.py", line 408, in assert_input_compatibility 
    str(K.ndim(x))) 
Exception: Input 0 is incompatible with layer simplernn_1: expected ndim=3, found ndim=4 

3 개만 지정되었을 때 keras가 "found ndim = 4"인 이유를 잘 모릅니다! 명확성을 위해

train_x.shape = (73, 84, 400)

vocab_size = 400

. input_shape가 3d 이상으로 공급되는 한 오류가 발생한다는 것을 깨달았습니다.

도움이 될 것입니다. :)

답변

2

n_samples을 모델의 입력 모양에 포함시키지 않아야합니다. 따라서 레이어의 입력 모양에 대해 크기 2의 튜플을 지정해야합니다. 또는 모양의 첫 번째 요소를 None으로 설정해야합니다. 여기 Keras는 입력 모양에 None을 자동으로 추가하여 ndim=4이됩니다. 자세한 내용은 here을 참조하십시오.

또한 당신이 input_dim=400 및 훈련 데이터가 73 텍스트 (아주 작은) 84의 각각은 길이 구성되어 있습니다 (당신은 어휘 단어 중 하나 - 뜨거운 코딩 표현을 사용하는 가정) 나타납니다. 그럼 아마 설정해야합니다 input_shape=(84,400).

+0

입니다. 당신 말이 맞아요! 이것을 이해하기 위해 잠시 나갔다! 당신의 도움을 주셔서 감사합니다!! – snowflake

+0

@snowflake 문제가 해결되면 답변을 수락하는 것이 좋습니다. –

관련 문제