# KERAS Nodes yield different result from Python Keras Model

**URL:** <https://forum.knime.com/t/keras-nodes-yield-different-result-from-python-keras-model/12317>\
**Category:** KNIME Extensions\
**Tags:** deep-learning\
**Created:** [October 17, 2018, 9:00am UTC](https://forum.knime.com/t/keras-nodes-yield-different-result-from-python-keras-model/12317 "2018-10-17T09:00:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alec](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Alec](https://forum.knime.com/u/Alec)\
**Post date:** [October 17, 2018, 9:00am UTC](https://forum.knime.com/t/keras-nodes-yield-different-result-from-python-keras-model/12317/1 "2018-10-17T09:00:48Z")

</div>

Dear Community,

I was trying to replicate the following [LSTMs example](https://www.superdatascience.com/deep-learning/) (Part 3 → Recurrent Neural Networks) with the Knime Keras nodes, yet they yield very different results, even though I use 1:1 the same settings as in the python source code.

I spent hours to find out where I went wrong, but I still have no clue. Any idea what I am doing wrong?

[Keras\_Test\_Workflow.knwf](https://forum-cdn.knime.com/uploads/default/original/2X/c/c684bef05c8487c649e56c633b241a19a82fabff.knwf) (1.2 MB)

Thank you a lot for your help!

---

<div class="post-metadata">

**Author:** ![nemad](https://forum-cdn.knime.com/user_avatar/forum.knime.com/nemad/32/53702_2.png) [@nemad](https://forum.knime.com/u/nemad)\
**Post date:** [October 17, 2018, 9:36am UTC](https://forum.knime.com/t/keras-nodes-yield-different-result-from-python-keras-model/12317/2 "2018-10-17T09:36:14Z")

</div>

Hello Alec,

I checked the Learning Monitor of your learner and from the loss plot it seems that the issue might be that we don’t shuffle the training data by default.  
Since 3.6 you can enable shuffling in the _Options_ tab of the _Keras Network Learner_.  
Especially for small tables this can increase performance drastically.

Cheers,  
nemad

PS: There is also a difference in how you apply dropout compared to the python script but if Keras does what it says it does, this should be equivalent.

---

<div class="post-metadata">

**Author:** ![Alec](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@Alec](https://forum.knime.com/u/Alec)\
**Post date:** [October 17, 2018, 11:02am UTC](https://forum.knime.com/t/keras-nodes-yield-different-result-from-python-keras-model/12317/3 "2018-10-17T11:02:21Z")

</div>

Thank you, nemad!  
The shuffling yielded much better results.  
I experimented also with the Dropout Layer: in fact, the dropout seems to work differently if applied as a layer instead being set in the LSTM dialogue. Although the results still differ, this might be simply an effect of different random seeds or something the like - as you pointed out, it is a very small dataset.  
-Alec-

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 2, 2023, 8:48pm UTC](https://forum.knime.com/t/keras-nodes-yield-different-result-from-python-keras-model/12317/4 "2023-06-02T20:48:20Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
