Live data from Hacker News

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

news.ycombinator.com

51–60 of 99 posts

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

#51
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)

https://aip.scitation.org/doi/pdf/10.1063/1.4822400

I can attest to Python usage in physics exploding after this. What Livermore says, you listen to. They were considered the best of best, after all.

An unknown student making an unknown library, no one cares. But when Livermore says, hey guys, Numeric is interesting, you listen.

Things rolled from there.

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

#52
Numpy, Scipy pandas, etc are a way to use scripty syntax to write CPP code.

Under the hood you get the benefits of CPP: stuff is dense in cache, operations are efficient.

But you can write it without a bunch of types, templates and allocators, which confuse people who aren't used to it. Most numeric code doesn't have a load of types anyway, it's just a few operations on some very large matrices.

Add to that the benefit that you can just ask of python's universe of libraries, which is quite large compared to rivals like MATLAB or R. Want to serve your model as a website? Jam it into Flask. Need crypto lib to grab the data? No problem, just pip it and import.

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

#53

I would put it mostly down to Spark. Originally, it was only available in Scala/Java but then they added Python support courtesy of Py4J. And since Python was massively simpler than Scala it exploded in popularity very quickly becoming the default language. So then you had Data Scientists who were already writing a lot of data transformations in Spark looking around at the rest of the Python ecosystem finding librari…

Spark started getting industry adoption in ~2013-2014 when it became an Apache project.

The roots of Python as a language used for numerical/scientific/data science use cases are much older than that with numpy and spicy back in the 90s, early 2000 followed by pandas and scikit-learn in the late 2000s.

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

#54
post #17

This happened when MIT switched from Scheme to Python some time in the '00s. Python's adaptation increased in the scientific community further and here we are.

The scientific community was already making heavy use of Python by the time that happened. I suspect MIT switched to Python in large part because it was what the STEM faculty there were actually using.

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

#55
post #41

Earlier quoted context omitted.

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)

I'm not sure I could find sources on the web any more easily than you. (Maybe start by looking at references in David Beazley's old talks?) I was in physics at the time, and what happened there was that Python basically enveloped Fortran & C++, letting people use the existing code without getting bogged down in complicated invocations.

https://www.youtube.com/watch?v=4RSht_aV7AU is a recent Beazley talk about that era.

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

#56

I would put it mostly down to Spark. Originally, it was only available in Scala/Java but then they added Python support courtesy of Py4J. And since Python was massively simpler than Scala it exploded in popularity very quickly becoming the default language. So then you had Data Scientists who were already writing a lot of data transformations in Spark looking around at the rest of the Python ecosystem finding librari…

PySpark certainly helped kill Hadoop for data munging, but I would say it only really got going in 2014.

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

#58
post #49

Earlier quoted context omitted.

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.

FWIW I tried looking a few up and standard library seemed hit-or-miss: JavaScript it didn't work: class testClass { constructor() { } callHoHe() { console.log('ho', 'he'); } } let hi = new testClass(); hi.callHoHe(); testClass.callHoHe = () => { console.log('haha'); } let heh = new testClass(); heh.callHoHe(); This ended up just printing 'ho', 'he' twice, For Java people didn't think it was possible: https://stackove…

Pretty close with the JS, just change testClass.callHoHe to testClass.prototype.callHoHe and you're good to go. Agreed about btoa and atob, since they're globally scoped and I'm not sure if they can be overwritten...

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

#59

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?

  class.methodName = newMethod
 
> .. kinda thing, future callers now get your method instead of the original.

Which is as powerful as it is a problem, since doing such kind of monkeypatching will change the behaviour all other instances, including already-created ones, that know nothing about your trick.

Any part of the program can modify any other part of the program in a significant way, making local reasoning and debugging very hard.

So, great for quick-and-dirty single-file scripts/ipython notebooks. Terrible for large systems.

That's the very issue with Python. The way it doesn't enforce sane, clean programming behaviour makes it easy for a beginner/non-programmer to work with it. But a large system with a lot of external libraries is very hard to maintain.

Source: Python user since ~2004

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

#60
I don't think there's a master plan or a design idea about that.

There's an old saying that goes like "Python is the second best language for anything".

Python isn't the best for any kind of task; but you can do almost anything in any field with python and some libraries. It's reasonably easy for a non-programmer to use it.

I think my first experience with GPU programming was using CUDA with C (I think it was kind of customized C in mid-2000s), so Python is not there since forever.

But if you need to do a bit of web scraping/input data manipulation, a bit of "offering a gui" (e.g. a small web server that shows the data), a bit a of matrix/vectorized operations, a bit of model training or even just inference... python has everything and everything is reasonably good. At least some of those operations would be cumbersome in other programming languages.

Try using R for general-purpose programming. Or Java for number crunching/matrix operations. They just suck.

Try finding the "greatest common divisor", functionality-wise, for the many tasks that you need in a ML system (just as many other systems), and you'll find Python.

The drawback is, IMHO, that it doesn't "scale" well. Python makes great proof of concepts and prototypes, but I'll always pick a different stack (possibly with multiple languages and technologies) if I want a long-running, maintainable production system.

Post reply on HN