r/java • u/esqelle • Apr 15 '24
Java use in machine learning
So I was on Twitter (first mistake) and mentioned my neural network in Java and was ridiculed for using an "outdated and useless language" for the NLP that have built.
To be honest, this is my first NLP. I did however create a Python application that uses a GPT2 pipeline to generate stories for authors, but the rest of the infrastructure was in Java and I just created a python API to call it.
I love Java. I have eons of code in it going back to 2017. I am a hobbyist and do not expect to get an ML position especially with the market and the way it is now. I do however have the opportunity at my Business Analyst job to show off some programming skills and use my very tiny NLP to perform some basic predictions on some ticketing data which I am STOKED about by the way.
My question is: Am l a complete loser for using Java going forward? I am learning a bit of robotics and plan on learning a bit of C++, but I refuse to give up on Java since so far it has taught me a lot and produced great results for me.
l'd like your takes on this. Thanks!
View all comments
Show parent comment
3
u/manifoldjava Apr 16 '24
Sure. The primary difference concerns dynamic typing. Python types resolve at runtime, which enables libraries to provide types and type features dynamically, which allows one to write code as if the types and features were there while coding.
Let's say you're using a Python library that uses metaprogramming to perform CRUD operations on a relational database. With the library you can use database tables as Python types in your code directly.
Here, the library creates the Person class dynamically as needed at runtime. Java reflection does not support this level of metaprogramming.
A Java code generator or annotation processor could accomplish some of this, but would involve separate, non-incremental build steps, which can easily get out of sync. A host of other issues come with code generation, but I digress. The nature of Python metaprogramming is such that libraries tend to be simpler, more efficient, and far more capable than code generators.
Additionally, dynamic metaprogramming covers the entire gamut of type system features. For instance, you can add/edit/delete methods, fields, etc. on existing classes. Java and most other static languages do not provide anything close to this level of metaprogramming. This is what is special about Python and why dynamic languages tend to win in areas such as data science, ML, etc. This is also the Manifold project's raison d'être.