4 ms·
Non ML/AI coder here: Why does ML/AI work need to be written in a scripting language? Why can’t it be something like C++ etc instead?
by cgb223 5y ago
Non ML/AI coder here:
Why does ML/AI work need to be written in a scripting language?
Why can’t it be something like C++ etc instead?
- cameldrv 5y agoOne reason is that you usually need to try a lot of things before you get something to work. Language productivity is at a premium. You really want some sort of interactive shell where you can do calculations and pull up plots etc. This used to be done with IPython, which evolved into Jupyter.
- mynameisash 5y agoIt doesn't need to / you could theoretically do it in C++. It's just that Python (as with other scripting languages) provides really nice, high-level expressiveness and also has a decent module system. You can write code in the REPL or just write a quick-and-dirty script and test it out without write-compile-run cycles. NumPy is highly optimized for things like matrix math. You get great speed with the C-level module, and you drive it with really simple Python code. So you want to multiply two matrices? The code literally looks no different than multiplying two scalars. That's Python's superpower. I haven't written C++ in nearly 20 years; maybe it's good enough to be able to do ML work. But the heavy lifting library in C/C++ plus the high-level driving Python is a really good fit.
- r-zip 5y agoWell, it is slightly different than multiplying two scalars: c = a * b vs C = A @ B
- WithinReason 5y agoJust one reason is that some Python libraries (numpy, tensorflow, pytorch) allow you to work with high dimensional arrays (3-4 dimensions) without for loops. ML also needs reverse autodifferentiation, which would be a real pain in C++.
- r-zip 5y agoAs another commenter said, speed of experimentation is an important factor. Also, dynamic types are nice when you're dealing with exploratory data work. Combine that with the library ecosystem and Python's ease of use, and there you have it.