ragulpr / wtte-rnn

WTTE-RNN a framework for churn and time to event prediction
MIT License
765 stars 187 forks source link

upgraded _keras_unstack_hack to handle arbitrary data size #8

Closed mynameisfiber closed 7 years ago

mynameisfiber commented 7 years ago

I upgraded the _keras_unstack_hack so that it doesn't require explicit implementations for each number of dimensions.

Also, I was holding off on committing this in, but pep8 should be run on the codebase! There are some files that use python3 syntax and some that use python3.

ragulpr commented 7 years ago

Thanks for the contrib, yes that was indeed a hack needed fixing. I did not merge due to Pip-install and pytest encountering

byte-compiling build/bdist.macosx-10.10-x86_64/egg/wtte/wtte.py to wtte.pyc
  File "build/bdist.macosx-10.10-x86_64/egg/wtte/wtte.py", line 17
    a = ab[(*slices, 0)]
            ^
SyntaxError: invalid syntax

Is this due to me running py2? Anyway, I found a workaround:

def _keras_unstack_hack(ab):
    """Implements tf.unstack(y_true_keras, num=2, axis=-1).
       Keras-hack adopted to be compatible with theano backend.
    """
    ndim = len(K.int_shape(ab))
    if ndim == 0:
        print('can not unstack with ndim=0')
    else:
        a = ab[...,0]
        b = ab[...,1]
    return a, b

And will also run pep8. Again, appreciate the effort and please would really appreciate more comments and prs