AI and deep learning define the future of programming, will Kotlin fly or die?


#1

AI technologies in general and deep learning specifically are becoming mainstream and many if not most cloud, embedded and handheld applications are be expected to provide some AI based behavior in the near future. There is an opportunity for Kotlin to become the language of choice for such applications and as such become a mainstream language along with the AI technologies.

Kotlin is an amazing programming language and it’s target, JVM, has maintained it’s place as one of the major execution environments for software code. However programming as we know it is changing by the rising adoption of AI technologies and specifically deep learning based approaches. This is an area where JVM is not strong and cannot compete well due to lack of library support. How can Kotlin benefit from this transition into AI technologies becoming part of main stream software development and how can Kotlin make this transition easier for the software teams?

The deep learning, the dominant branch of AI techniques, can be divided into two steps: i) training deep learning based AI models and ii) running the pretrained models in the final execution environment. For training deep learning models people predominantly use Python because of the extensive library support that Python provides for machine learning applications combined with ability to write complex distributed applications with Python (something required for training models in the cloud). Some examples of what makes Python stand out are the natively implemented machine learning libraries with Python bindings including TensorFlow, Numpy, SciPy, Pandas, SciKit Learn and OpenCV. Building and training deep learning models will be mostly a feature of back-end systems or corporate data pipelines. Data scientists experiment with the models on their desktop but the final models are trained in the cloud. Training the models require efficient numerical libraries that allow compiling of the models to GPUs or other specific hardware. TensorFlow is the most widely used of such deep learning libraries and currently only fully supports Python for training. It’s likely that most cloud, mobile and IoT applications will require some live backend system collecting data and training deep learning models based on the data either live or in batches.

The second part of the deep learning based AI models is the actual usage of the trained models for predictions and intelligent decision making. This can mean speech recognition on a handheld device or movie recommendations in a cloud app. This can mean steering a self driving car based on a video stream or running a chat bot on an iOS, Android and web app. These models will be everywhere. Executing the models is again numerically intensive task and requires support for special purpose libraries that compile the models to special purpose hardware such as GPUs. Because the models are trained with some specific frameworks (e.g. TensorFlow) the execution of the models requires that the execution system supports the same framework or otherwise the workflow would just be painful for the developers. The full support for such framework is not needed for the execution environment but purely support for running the pre-trained models. Typically models are trained in Python but the model execution can occur in Python or C/C++ or some other languages.

How does this relate to Kotlin? Right now JVM is not widely used for deep learning. As such Kotlin cannot currently become widely used as a language for building AI based systems. Because AI based systems will find their way to most everyday software applications, lack of JVM support for deep learning is a disadvantage to Kotlin as a language and an obstacle for wider adoption of the language several years from now. However at the same time there is an arising opportunity for Kotlin. Right now Python is the main language people use for developing deep learning models and deep learning based applications. There is no competition. There is no elegant strongly typed language in the data science space. Granted data scientists like dynamic languages but it’s a different thing playing around with deep learning models on your desktop than developing distributed production systems where dynamic typing becomes a disadvantage. I’d much rather prefer Kotlin as a language for such systems than Python.

With this is mind, how could Kotling become the language that bridges AI and deep learning with modern strongly typed programming. The easiest way would be probably make Kotlin to target Python or Python bytecode. That way the machine learning libraries would not need to be ported for JVM or some other target, something that is likely to not happen or lag behind. The second step would be having a Kotlin to compile to native (LLVM) into code that does not use garbage collector or that allows to not use garbage collector for certain real-time parts of the code. This becomes important when executing the deep learning models on an embedded platforms to perform real-time tasks. You don’t want your drone’s balancing model to stop executing to purge the memory (my friend tried this and it didn’t end up well for the drone). Or you don’t want the next generation of Siri to have pauses in the speech generation. Or you don’t want your self driving car to pause steering to clear the unused objects. Python is not a suitable target language for these real-time applications and most people use C/C++ or Objective C for those cases. For this reason there is a C APIs for deep learning frameworks like TensorFlow to execute pretrained models in embedded environments.

If Kotlin would target Python (source code or bytecode) and native (LLVM) it would have the opportunity to become the strongly typed language that everyone would prefer to use when developing their AI based production software applications allowing to cover both the training of such AI models in the cloud and execution of such models on in the cloud or embedded platforms.


#2

Interesting.

I would also like to use kotlin for AI and deep learning.

The current work on Jetbrains kotlin native is an opportunity for the use cases you are describing. It would allow to use it on environments without JVM.

I’m not sure of the interest of targeting Python source code or byte code. Kotlin, with java ecosystem and great features like coroutines, should be enough to bring people to build or port some library code on it.

What do you think about deeplearning4j?


#3

If you think of why Silicon Valley became the hot spot for software and technology, it’s because things were changing rapidly at the time when this happened and the ecosystem that had most support for doing these new things became the center of attention. The fact that things were moving fast in Silicon Valley attracted doers, innovators and investors all of which supported the exponential growth of Silicon Valley over other metropolitan area. Now that dominance is impossible to challenge or dispute unless new technological revolution comes and takes the spot. The same way Pyhon for some reason has become the defacto language for machine learning and deep learning engineers to build data models. Because of this all new frameworks and all AI startups tend to target Python first. This results in exponential growth of Python machine learning and deep learning support. The fact that things are changing rapidly and that no single library of framework can solve all the problems results in this exponential growth situation. There just isn’t such a strong ecosystem for Java in the machine learning space. JVM was shining in the big data space but hasn’t taken off similarly in the machine learning space.

So no I don’t think JVM can compete because of the nature of dynamics of the exponential growth phenomena. For JVM to catch up would require a massive corporate support similar to what Android had at the time when Apple came up with iOS. Otherwise JVM will stay behind for long.

To illustrate the situation let’s look at Google Trends comparison between TensorFlow and deeplearning4j. It’s not looking good for deeplearning4j. And even if deeplearning4j was catching up it wouldn’t be enough because you would lack all the other supporting libraries of today and all the libraries that are going to come up in the next two years that nobody knows about yet.


#4

did you use scala or java for AI and\or deep learning? if so, kotlin could fit in


#5

Here is an observation. Tensorflow and most other “Python” deep learning frameworks are actually written in C++. Python is used just as a scripting language to “glue” various moving pieces together. Any other scripting language could be used instead, with the corresponding (relatively thin) bridge. Of course, the current momentum is on the Python side. If the past history on innovation and rise/fall of languages teaches us anything, the lesson we can learn is that it does not really matter who came first to the field and it does not even matter who is the leader now.

Kotlin is, without doubt, considerably more productive for any project of non-trivial size due to its static types and emphasis on toolability. Even at 10K+ Python LOCs you start to feel pains of a dynamic language. Python works nicely in slide-ware and in small code snippets of the kind you can put into iPython notebooks, where you can actually execute the code on your data and then enjoy code completion and integrated help on the actual, dynamically resolved object instances. As soon as you start writing the actual non-tirival code, abstracting it into modules, etc, it all starts to fail utterly – code completion and help becomes useless for any non-trivial framework even in state-of-the-art Python IDEs like PyCharm.

The first player in ML field that will realise that Python is roadblock to further scale will reap the benefits. All we can do in Kotlin team is to make sure that when this realisation comes, Kotlin is in good shape to serve as a viable alternative to be considered.


#6

There is a project called Jython that attempts to bring Python to JVM. Another project called JyNI (Jython Native Interface), which is aiming to bring unmodified Python native packages to be callable from Jython. If you look at the list of packages JyNI is attempting to bring to Jython, it’s exactly the set of mathematical and scientific libraries we are talking about. I’ve not looked into the details but JyNI (if it works from any JVM language) or something similar for Kotlin might actually be a working solution.


#7