opened
danhper
username_0
I have a model with two inputs, each encoded using different embeddings.
When I do not used pretrained weights, I get the expected graph:

![good-graph](https://user-images.githubusercontent.com/1436271/32405436-5d9b8934-c1a8-11e7-99a7-86e32a869114.png)


When I use pretrained weights, the graph has an unexpected edge between the LSTM of the first input and the embedding of the second one:
![bad-graph](https://user-images.githubusercontent.com/1436271/32405444-74cdb14a-c1a8-11e7-9a56-e8fb91e91d36.png)

I think `lstm_1` and `embedding_2` should not be connected here.

`model.summary` does not give any information about this connection either:

```

Layer (type)                    Output Shape         Param #     Connected to
==================================================================================================
input_1 (InputLayer)            (None, 50)           0

input_2 (InputLayer)            (None, 50)           0

embedding_1 (Embedding)         (None, 50, 10)       1000        input_1[0][0]

embedding_2 (Embedding)         (None, 50, 10)       1000        input_2[0][0]

lstm_1 (LSTM)                   (None, 100)          44400       embedding_1[0][0]

lstm_2 (LSTM)                   (None, 100)          44400       embedding_2[0][0]

concatenate_1 (Concatenate)     (None, 200)          0           lstm_1[0][0]
                                                                 lstm_2[0][0]

dense_1 (Dense)                 (None, 64)           12864       concatenate_1[0][0]

dense_2 (Dense)                 (None, 1)            65          dense_1[0][0]
==================================================================================================
Total params: 103,729
Trainable params: 103,729
Non-trainable params: 0

```

Here is a small example reproducing the issue:

```python
import numpy as np

from keras.models import Input, Model
from keras.layers import Embedding, LSTM, Dense, concatenate
from keras.callbacks import TensorBoard

PRETRAINED = True

def make_encoder():
    model_input = Input(shape=(50,), dtype="int32")
    weights = [np.random.uniform(size=(100, 10))] if PRETRAINED else None
    x = Embedding(100, 10, weights=weights)(model_input)
    x = LSTM(100)(x)
    return model_input, x

input1, output1 = make_encoder()
input2, output2 = make_encoder()

x = concatenate([output1, output2])
x = Dense(64)(x)
main_output = Dense(1, activation="sigmoid")(x)

model = Model(inputs=[input1, input2], outputs=main_output)
model.compile(optimizer="rmsprop",
              loss="binary_crossentropy",
              metrics=["accuracy"])

data1 = np.random.randint(0, 100, size=(100, 50))
data2 = np.random.randint(0, 100, size=(100, 50))
targets = np.random.randint(0, 2, size=(100,))

model.summary()
model.fit([data1, data2], targets, callbacks=[TensorBoard()])
```

changing `PRETRAINED` to `False` gives the correct graph.

The issue occurs with the latest version of Keras and both Tensorflow 1.3 and 1.4.
After trying older versions of Keras, the issue seems to be present from 2.0.4.
Keras 2.0.3 gives the expected graph.  

Please let me know if I am missing something.

Thank you.
Wrong graph with pretrained embeddings
issue
closed
fchollet
username_1
issue