Live data from Hacker News

Ask HN: How did Python become the lingua franca of ML/AI?

news.ycombinator.com

71–80 of 99 posts

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#71

Python's a lingua franca in AI/NN because it was already a dominant language in scientific computing. Its dominance in scientific computing grew steadily through the 1990s and 2000s, for a few reasons: 1) Python -- specifically CPython -- made it easy to wrap existing, thoroughly tested high performance libraries in Python APIs. So, you got easy access to things like GSL and BLAS and LAPACK, but you get to call numpy…

I was a student in the early 2000s and part of the academic community and have personally seen some of the world's best scientists working on physics or computer science. Not one of them used Python - in fact our professor chose to teach us Haskell and C in the first year of under-graduation. C, C++ or Fortran was quite common for scientific programming.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#72
1. It's extremely easy. Before the so-called revolution and CS people trying to get into it in droves, it was a niche topic dominated by the lifelong-researcher types. They could not be bothered with complex code. Writing code should not get in the way. Then, Lisp dominated the ML/AI scene. Now Python does, for this reason, to some extent. Python being easy is also helpful for non-CS engineering and other science grads to learn quickly.

2. Python has a huge ecosystem. NumPy, SciPy, and now Tensorflow, PyTorch, JAX. These makes lives easier.

3. Python and its ecosystem is FOSS. Students, hobbyists can learn it for free. (Quick anecdote: my uni in India, a very reputed non-IIT one, with sub-optimal funding, two years ago switched to Python + ecosystem for Physics and CS courses- both major and minor. This switch happened directly from C. Before that, Fortran was used. MATLAB, SPSS, etc. was never an option for cash-starved Indian unis. This is pretty much the same all across India. And thus you get a huge talent pool already trained in Python that pass-outs from hard-to-get-into unis.)

4. Python being general purpose also helps vis-a-vis R. R is heavily constrained. You cannot do much in it. R is used in anaalysis and Data Science. I have never seen it being used in ML, DL or RL. You learn Python, you can do non-trivial file manipulation in it. Good luck doing that with R or MATLAB.

5. The amount of people who needs to write code that reaches the metal is very small. I never needed to look under the sheets. I spend my life writing PyTorch, fastai, and TFLite. A friend of mine doing PhD needed to write custom CUDA code and then a wrapper so that it could be accessed from Python. He said that it was a very horrible experience. But the number of such people too little to bring Julia to mainstream. Julia removes the "two-language problem", but most people never need to use anything besides Python.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#73
post #28

Earlier quoted context omitted.

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?

It 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…

Well, it is slightly different than multiplying two scalars:

c = a * b

vs

C = A @ B

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#74
post #28
post #22

Another way to analyze the problem: what other language would it have been, given the moment ml hit? You say compared to other scripting languages'. Let's list them. Ruby: no numeric support Go: unnecessary typing, modest numeric support, shitty generics Bash: ha ha ha Scala, java, c, cpp: not a scripting language, complex Tcl, php: out of favor Rust: hadn't happened yet R: in memory bias, not as simple Other languag…

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?

As 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.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#75

Python's a lingua franca in AI/NN because it was already a dominant language in scientific computing. Its dominance in scientific computing grew steadily through the 1990s and 2000s, for a few reasons: 1) Python -- specifically CPython -- made it easy to wrap existing, thoroughly tested high performance libraries in Python APIs. So, you got easy access to things like GSL and BLAS and LAPACK, but you get to call numpy…

Indeed, Python was already the main scripting language at CERN when I was there during the early 2000's.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#76
post #41

Python's a lingua franca in AI/NN because it was already a dominant language in scientific computing. Its dominance in scientific computing grew steadily through the 1990s and 2000s, for a few reasons: 1) Python -- specifically CPython -- made it easy to wrap existing, thoroughly tested high performance libraries in Python APIs. So, you got easy access to things like GSL and BLAS and LAPACK, but you get to call numpy…

Can you link any source on the python scientific usage in the 90s and early 2000s? I think the dominant language in science at that time was a mishmash of MATLAB, Java, C++, FORTRAN and Perl (In Biology at least, perl was the goto glue language due to its excellent string processing capabilities)

Here CERN usage of Python during those early 2000s.

https://lhcb-comp.web.cern.ch/support/CMT/cmt.htm

https://home.cern/news/press-release/cern/lhc-computing-grid...

https://cds.cern.ch/record/840543/files/lhcc-2005-024.pdf

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#77
post #13

Earlier quoted context omitted.

The most insane thing about Python is how you can override single methods in classes and use the class like normal. One time I was working on getting FIFO working on Windows, and none of the Python built-ins were set up to handle any random process writing to a named pipe that wasn't within the same Python instance. So what I did was I took the closest implementation Python offered, which was in the multiprocessing m…

Monkey patching is a terrible practice outside of unit testing and can lead to extremely difficult to debug bugs. Also monkey patching isn't unique to python.

This was my thought exactly. I understand why someone would want to do it. However, when a problem comes up, good luck debugging it in python.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#78

My last job was at an ML company. Most ML people there cannot build large robust systems and some struggled with the non-algorithmic bits of software. I am sure that some can out there in the world, but for the most part our ML people were very good at creating models and not very good at the development part, especially as the program grew (part of the motivation to hire devs like me in the first place). Python gets…

> Most ML people there cannot build large robust systems and some struggled with the non-algorithmic bits of software.

I have experience working alongside ML people and interviewing them, and have to agree (anecdotally) that this is often the case. Not only that, but they often do not make it a priority to get good at these things.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#79
post #35
post #20

Earlier quoted context omitted.

I should also add a cultural / social reason why Python is used in scientific computing and machine learning much more than JS/Ruby/Perl: Python was the only one of those languages (partially) funded by government research agencies. Guido was a research programmer in the Netherlands at CWI, and then he moved to the US when he was hired by CNRI, a research agency headed by Bob Kahn (loosely connected with DARPA as far…

Perl was originally written at JPL, which is the epitome of government-funded research, and for the first many years of its life most of its numerous contributors were at one or another government-funded research institution, because people who weren't didn't have internet access. Lua does support operator overloading: $ luajit LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/ JIT: ON SSE2 S…

Hm interesting, it's hard to find references to Wall working at JPL, but here's a very non-authoritative one:

https://old.reddit.com/r/perl/comments/5lj9ms/did_larry_wall...

Wikipedia doesn't mention it:

https://en.wikipedia.org/wiki/Larry_Wall

https://en.wikipedia.org/wiki/Perl#Early_versions

That does sound right, since I vaguely recall an interview with Wall talking about JPL.

-----

I think there's still a difference because Python was literally funded as a research project by CNRI, a government research institution. It wasn't created there, and it was funded by different entities afterward, but I think that's the period when contributors with a scientific background like Travis Oliphant, Jim Huginin, and David Beazley started working on Python's libraries and infrastructure.

At best it seems like Wall worked at JPL for a short time and started Perl there. It also matters what kind of research it was. Perl is aimed much more at text processing and not linear algebra, while Python is more general purpose in this respect.

Also, if my memory is right, by early 2000's JPL had jobs in Python, and python.org said JPL was a user. I could be wrong but I don't think Perl ever caught on as much as Python did at JPL.

-----

Yes good point about Lua's metatable mechanism.

Re: Ask HN: How did Python become the lingua franca of ML/AI?

#80

Earlier quoted context omitted.

> The most insane thing about Python is how you can override single methods in classes and use the class like normal. Isn't that true of basically every language supporting class-based OOP and inheritance?

It's called 'monkey patching' and python does make it particularly easy, simply: class.methodName = newMethod .. kinda thing, future callers now get your method instead of the original. This does seem a fair bit easier than other languages make it to do?

> It's called 'monkey patching' and python does make it particularly easy

Inheritance and overriding method in the descendant class is cleaner, and more broadly supported. When you need monkey patching, sure, its nice that most modern dynamic OO languages support it quite naturally. (Ruby even supports scoped monkey patching via refinements, as well as classic monkey patching and per-object overrides.) But this is not at all unique to Python.

Post reply on HN