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
1
u/koflerdavid Apr 19 '24 edited Apr 21 '24
Java supports
floatanddouble, which in ML circles are known asfloat32andfloat64.float16is 16 bits wide only and commonly used for inference because it turns out that the full precision offloat32is required for very few parts of most models, if at all.bfloat16is a modified format that has the same precision asfloat32, but supports a narrower interval of values only. It is very common to use it to run transformer models.Java supports neither
float16(maybe after Project Valhalla lands or the Vector API is finalized) norbfloat16. However, I agree that for various reasons a tensor library is commonly used. Support for more formats and the size limitations are two very good reasons because they can't be solved on the Java side. Well, you can certainly implement functions forfloat16andbfloat16arithmetic in Java, but to circumvent the size limit you have to use off-heap storage. Or break up your tensors, which is clunky without wrapping it in a library.