Mark Elliott

62 Followers
52 Following
59 Posts
Applied Linguistics, Assessment, Maths, Edu AI. Mostly other stuff, though. All views my own – free typo with every tooot.
Because we all need some wholesome content sometimes, meet Benji.

What I learned today: you can't use if-conditionals in a Keras custom loss function. I managed to come with a solution...

All the operations in the custom loss function need to be vectorised, so an if-conditional breaks it and throws an exception. The solution is to create Boolean vectors corresponding to each condition, turn their types into float (must be float), multiply each Boolean by the corresponding loss function and sum.

Example:

... and here's an exciting teaser for some of the details – further explanation in the Post thread, full details in the paper.