RapidMiner

‎09-16-2017 07:15 PM

Keras is a high level neural network API, supporting popular deep learning libraries like Tensorflow, Microsoft Cognitive Toolkit, and Theano.


The RapidMiner Keras extension provides a set of operators that allow an easy visual configuration of Deep Learning network structures and layers. Calculations are pushed into the Python-based backend libraries, so you can leverage the computing power of GPUs and grid environments. 

The extension makes use of an existing Keras installation. This article shows how to do a simple deployment of Keras and how to configure the Keras extension to connect to it.

 

Let's review several options:

 

Anaconda on MacOS

 

Warning: As of version 1.2, TensorFlow no longer provides GPU support on macOS. 

  1. Download and install Anaconda from: https://www.continuum.io/downloads#macos
  2. Create a new environment by typing in command line: conda create –n keras
  3. Activate the created environment by typing in the command line: source activate keras
  4. Install pandas by typing in the command line: conda install pandas
  5. Install scikit-learn by typing in the command line: conda install scikit-learn
  6. Install keras by typing in the command line: conda install -c conda-forge keras
  7. Install graphviz by typing in the command line: conda install –c anaconda graphviz
  8. Install pydotplus by typing in the commandline conda install –c conda-forge pydotplus
  9. In RapidMiner Studio Keras and Python Scripting panels in preferences, specify the path to your new conda environment Python executable.

 

You’re good to go!


Anaconda on Windows

 

Warning: Due to issues with package dependencies, it is not currently possible to install graphviz and pydot in a conda environment on Windows, and consequently to visualise the model graph in the results panel.

 

  1. Download and install Anaconda from: https://www.continuum.io/downloads#windows
  2. Create a new environment with Python 3.5.2 by typing in command line: conda create –n Python35 python=3.5.2
  3. Activate the created environment by typing in the command line: activate Python35
  4. Install pandas by typing in the command line: conda install pandas
  5. Install scikit-learn by typing in the command line: conda install scikit-learn
  6. Install keras by typing in the command line: conda install -c jaikumarm keras=2.0.4
  7. In RapidMiner Studio Keras and Python Scripting panels in preferences, specify the path to your new conda environment Python executable.

 

You’re good to go!

 

 

Windows

 

  1. Download and install Python 3.5.2 from: https://www.python.org/downloads/release/python-352/

Only python 3.5.2 works for windows.

  1. Install numpy with Intel Math Kernel library.
  1. Install pandas from the command line: pip3 install pandas
  2. Install graphviz from the command line: pip3 install graphviz
  3. Install pydot from the command line: pip3 install pydot
  4. Install TensorFlow.
    • If you would like to install TensorFlow with GPU support, please see the instructions here: https://www.tensorflow.org/install/install_windows
    • If you would like to install TensorFlow only with CPU support, from the command line run: pip3 install –upgrade tensorflow
  5. Install Keras from the command line: pip3 install keras

 

You’re good to go!

 

 

 

RapidMiner extension

 

  1. Install the Keras extension from the RapidMiner Marketplace
  2. Install RapidMiner Python Scripting extension from the marketplace if not already installed.
  3. Restart RapidMiner Studio.
  4. Inside your Studio Client go to Settings (Menu) > Preferences and navigate to “Python Scripting” tab/page on the left. Provide path to Python executable and click test to ensure it is successful.
  5. Inside your Studio Client go to Settings (Menu) >Preferences and navigate to “Keras” tab/page on the left. Provide path to Python executable and click test to ensure it is successful.

 

Try out a few sample processes from the “Keras Sample” in the repository view.

 Capture.PNG

 

 

Comments
Learner III hermawan_eriadi
Learner III

Thanks for the answer @pschlunder

I find some problem.. When i run the sample, SP_500_Regression, I find that "Apply Keras Model" can test all the testing examples. It always can't predict 11 last examples.. I try also with another process, it result the same thing.. What's the miss ?

 

What's the number of Loss that represent good result? In my model, I just can get loss 0.2 for the best number with Binary_accuracy or Categorial_Accuracy just <50%. Even when I rise the epoch about 5000. Is it mean that my model not deep enough ?

 

Thanks..

Learner III 56005393_t30l41
Learner III

 

Error. Implement Stacked LSTMs in RapidMiner 

I got error message..

ValueError: Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2

 

 

 

Learner III j_vreugdenhil
Learner III

 Does somebody know an easy method to convert 2d data to 3d using RM for feeding into a RNN or LSTM network? Online i ve found methods using Python but thats something I wasnt looking for.

Learner III hermawan_eriadi
Learner III

Dear @j_vreugdenhil

Try using "Add Core Layer" operator and use Layer Type: Reshape. You can fill the "Target Shape" by dimension you want. Ex: (4,77) for 3 dimension with (Examples, 4 timeslap, 77 attributes).

Learner III j_vreugdenhil
Learner III

Tnx! I ll try this. Will reshape automatically convert my 2d dataset (x examples, 3 features) to a 3d dataset (x examples, each x timesteps, 3 features)?

Learner III hermawan_eriadi
Learner III

Yeah.. try (1,3). in chase only one 1 timesteps.

Newbie pxkst970
Newbie

 

Dear @j_vreugdenhil

I'm having the same issue you've had. I already tried to do "Add Core Layer" using "Reshape" layer type, but still got the same errors. Did you find out how to make it work?

Contributor I dass
Contributor I

Hi everyone, 

Is there any way to implement stack lstm in keras model?It seems like i can't find the 'return_sequence' parameter in the recurrent layer. thank you guys.

 

RM Certified Analyst
RM Certified Analyst

@pxkst970 Until now the only way I have found to make the LSTM works on the RNN operator on RM is to fix the input_shape parameter on the operator Keras Model to (n, 1) where n = number or examples in the RM dataframe.

 

Then inside the Keras Model operator in the target_shape of the Core Layer, reshape from 2D to 3D with the same shape. I suposse that should be many other configurations to make it works but for now I've only found this way.

 

@dass Currently I'm looking too for a stacked LSTM because there's no return_sequences parameters inside the RNN operator.

Learner III Montse
Learner III

Hi @israel_jimenez,

Could you send the XML process? I can't get it to work with the specifications you have said.

 

Regards,

Montse

RM Certified Analyst
RM Certified Analyst

@Montse my bad I've just realize that I've said "n = number of examples" when it should be "number of atributes".

 

It's a very non-sense naive implementation just to review the architecture of the LSTM Keras implementation.

 

Regards.

<?xml version="1.0" encoding="UTF-8"?><process version="8.1.003">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="8.1.003" expanded="true" name="Process">
    <process expanded="true">
      <operator activated="true" class="generate_data" compatibility="8.1.003" expanded="true" height="68" name="Generate Data" width="90" x="45" y="34">
        <parameter key="number_examples" value="10000"/>
        <parameter key="number_of_attributes" value="1"/>
      </operator>
      <operator activated="true" class="subprocess" compatibility="8.1.003" expanded="true" height="82" name="Subprocess" width="90" x="179" y="34">
        <process expanded="true">
          <operator activated="true" class="select_attributes" compatibility="8.1.003" expanded="true" height="82" name="Select Attributes" width="90" x="45" y="34">
            <parameter key="attribute_filter_type" value="single"/>
            <parameter key="attribute" value="label"/>
            <parameter key="invert_selection" value="true"/>
            <parameter key="include_special_attributes" value="true"/>
          </operator>
          <operator activated="true" class="series:windowing" compatibility="7.4.000" expanded="true" height="82" name="Windowing" width="90" x="179" y="34">
            <parameter key="window_size" value="5"/>
          </operator>
          <operator activated="true" class="set_role" compatibility="8.1.003" expanded="true" height="82" name="Set Role" width="90" x="313" y="34">
            <parameter key="attribute_name" value="att1-4"/>
            <parameter key="target_role" value="label"/>
            <list key="set_additional_roles"/>
          </operator>
          <connect from_port="in 1" to_op="Select Attributes" to_port="example set input"/>
          <connect from_op="Select Attributes" from_port="example set output" to_op="Windowing" to_port="example set input"/>
          <connect from_op="Windowing" from_port="example set output" to_op="Set Role" to_port="example set input"/>
          <connect from_op="Set Role" from_port="example set output" to_port="out 1"/>
          <portSpacing port="source_in 1" spacing="0"/>
          <portSpacing port="source_in 2" spacing="0"/>
          <portSpacing port="sink_out 1" spacing="0"/>
          <portSpacing port="sink_out 2" spacing="0"/>
        </process>
      </operator>
      <operator activated="true" class="split_data" compatibility="8.1.003" expanded="true" height="103" name="Split Data" width="90" x="313" y="34">
        <enumeration key="partitions">
          <parameter key="ratio" value="0.7"/>
          <parameter key="ratio" value="0.3"/>
        </enumeration>
      </operator>
      <operator activated="true" class="keras:sequential" compatibility="1.0.003" expanded="true" height="166" name="Keras Model" width="90" x="447" y="34">
        <parameter key="input shape" value="(5, 1)"/>
        <parameter key="optimizer" value="Adam"/>
        <parameter key="momentum" value="0.01"/>
        <enumeration key="metric"/>
        <parameter key="epochs" value="50"/>
        <enumeration key="callbacks"/>
        <process expanded="true">
          <operator activated="true" class="keras:core_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Core Layer" width="90" x="112" y="34">
            <parameter key="layer_type" value="Reshape"/>
            <parameter key="target_shape" value="(5, 1)"/>
            <parameter key="dims" value="1.1"/>
          </operator>
          <operator activated="true" class="keras:recurrent_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Recurrent Layer" width="90" x="246" y="34">
            <parameter key="layer_type" value="LSTM"/>
            <parameter key="no_units" value="32"/>
          </operator>
          <operator activated="true" class="keras:core_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Core Layer (2)" width="90" x="380" y="34">
            <parameter key="activation_function" value="'linear'"/>
            <parameter key="dims" value="1.1"/>
          </operator>
          <connect from_op="Add Core Layer" from_port="layers 1" to_op="Add Recurrent Layer" to_port="layers"/>
          <connect from_op="Add Recurrent Layer" from_port="layers 1" to_op="Add Core Layer (2)" to_port="layers"/>
          <connect from_op="Add Core Layer (2)" from_port="layers 1" to_port="layers 1"/>
          <portSpacing port="sink_layers 1" spacing="0"/>
          <portSpacing port="sink_layers 2" spacing="0"/>
        </process>
      </operator>
      <operator activated="true" class="keras:apply" compatibility="1.0.003" expanded="true" height="82" name="Apply Keras Model" width="90" x="581" y="34"/>
      <connect from_op="Generate Data" from_port="output" to_op="Subprocess" to_port="in 1"/>
      <connect from_op="Subprocess" from_port="out 1" to_op="Split Data" to_port="example set"/>
      <connect from_op="Split Data" from_port="partition 1" to_op="Keras Model" to_port="training set"/>
      <connect from_op="Split Data" from_port="partition 2" to_op="Apply Keras Model" to_port="unlabelled data"/>
      <connect from_op="Keras Model" from_port="model" to_op="Apply Keras Model" to_port="model"/>
      <connect from_op="Apply Keras Model" from_port="labelled data" to_port="result 1"/>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
      <portSpacing port="sink_result 2" spacing="0"/>
    </process>
  </operator>
</process>
RM Certified Analyst
RM Certified Analyst

 

 

I really appreciate any help you can provide

Contributor II jacobcybulski
Contributor II

@dgrzech, I am back at RM Keras. I have been playing with a standard MNIST example and comparing the same model performance against those running on R/R Studio and Python/Anaconda. I have stumbled on an issue while plotting the results using Tensorboard. The common metric used in measuring the classifier is "accuracy" or "acc", which will be then translated by Keras into something more appropriate depending on the output shape, so in MNIST it will be "categorical_accuracy". The RM Keras plugin is trying to be smarter than humans working with Python and R and it eliminates "accuracy" and "acc" as an option for such models. This causes problems with Tensorboard, as then the Python and R generated logs will show as "acc" and "val_acc" panels and the RM logs will be placed in separate panels "categorical_accuracy" and "val_categorical_accuracy". We need to bring the "accuracy" back to the Keras plugin metric options! By the way, the issue can be "fixed" by finding the offending option in XML and changing it there, then the RM Keras logs will rejoin the rest of the world  Smiley Happy

 

Jacob

 

P.S. Interestingly when running MNIST over 30 epochs, compared with R (orange and dark blue) and Python (brown and light blue), RM (purple) consistently produces best validation loss but its validation accuracy places it in the middle. The Python beats all, R is the loser.

Tensorboard - Five Runs.PNG