But why python though?

Hello,

Since I started learning about AI and machine learning I found the main language used for AI is Python, but why do most companies and programmers use Python as the main language for AI knowing that it is prolonged in comparison to other languages (like C)?
isn’t that inefficient?
especially since AI requires a lot of computational power for training.

Python is easier to learn and has a lot of libraries. It might be a bit more inneficient but with todays CPU, GPU, TPUs the difference is not a barrier.

C is a very old and basic language, not object oriented programming. C++ is object programming but C++ is quite complex and hard to learn.

It is easy today to use a library from any modern language.
Write in the syntax more comfortable to your fingers… the syntax is not relevant to the speed you gain experience in any field.
The speed of execution or computing is not related with the time and energy to gain experience in any field.
Python is the syntax of choise for the people that published their works, most of the times, because they do not have real experience in Object Technology sor something better than computer Languages…

Another important thing to realize is that “Just In Time” (JIT) compilation technology has gotten very sophisticated in the last 20 years. The python runtime system (the “interpreter”) can tell which parts of the code are getting executed a lot and then it invokes the JIT compiler to create an optimized machine code version of those sections, so python can be just as fast at runtime as compiled languages like c and C++. Well, you get some overhead cost for invoking the JIT compiler at runtime, but that only happens once at the very beginning of your training. From that point forward, it runs as fast as if you had written the code in c.

Paul, please don’t forget there are a ton of memory management issues you have to deal with. I mean at SG, you must recall the popularity of Java and its importance on ‘garbage disposal’.

We got to be rid of ‘malloc’ and ‘free’ and how we would map all these things.

These were also the more innocent days when, if you left a forgotten trace behind, no one would ‘hack’ or try to crash you.

Unfortunately, I found the mental syntax of Java to be much too complicated.

I mean, really I think Java is also so ‘JIT’ (and having studied formal Finance I learned about this term many years ago, that the Japanese came up with,
rather than building all of a car at once, and then leave it in a lot, they’d build ‘just enough pieces’ and then build on demand).

I also do have actual experience with PIC in-line assembly… (now Microchip and owned by… Whomever).

You don’t want to go down there.

Certain routines you can squeeze, and the better and more experienced programers than I can do that.

And at the end of the day, you impale yourself on the fact, as much as we know (or think we know) today, why do we fall upon the same Von Neuman ISA.

So I will just say, you are closer to ‘bare metal’.

I’d say, is the ‘metal’ the problem you want to solve ?

If you can get your hands on a single RTX 3090, and have thought and patience…

You don’t need 16k of them. That is swagging your d—.

And @paulinpaloalto I didn’t at first delete this post because I ever felt you are ‘swaggering their ----’.

But many others are.

And it is not fun being at ‘chip level’. You are kind of alone (outside of the thousands of minds that designed it that would have no idea what it can do).

Sorry, as CS, question struck me as a bit depressing.

Forgive.

This is actually my first time hearing about JIT. thanks for the info :grinning:

Yes, there are definitely reasons why people prefer high level interpreted languages like python and Java. So the fact that interpreted languages don’t have to be slow because of “on the fly” compilation is actually incredibly important and liberating. It’s not that there is no application for writing in c and assembly language: the people who write the really core libraries like LINPACK need to get every cycle of performance out of it that they can. Also if you’re an operating systems engineer (as I was for most of my career), there are some parts of the kernel (e.g. the lowest levels of exception handling) just have be written in assembly language. The machine instructions that you need to execute just are not accessible even in c. But most programmers can just write in python and things will work very well and have good performance.

Coming up with better computing architectures is also incredibly important, but that is “above our pay grade”. When quantum computers eventually become practical, then the rest of us will have to figure out how to use them. In the meantime, the question is simply what is the most effective way for a wide swath of programmers to get as much performance as we can from the existing hardware we have at our disposal without having to code every single line in machine language. I have actually done that and, just like your experience with PIC, I prefer not to “go there” if I can avoid it. It’s rewarding to understand what really is happening at the lowest level, but once you have the picture it’s a lot easier to let all the hundreds of layers of software underneath us deal with that.

Well, until some other company like CrowdStrike which makes one of those layers we depend on releases their next untested software release and the whole Internet collapses. :scream_cat:

Has one really lived a full programming life if they haven’t produced a real-time interrupt-driven multitasking control system in 8051 assembly language?

Please keep an eye on PEP-0703

Python is a staggering 75 times more energy-intensive than C for equivalent tasks and runs a shocking 71 times slower. In contrast, Rust, C++, Java, and Ada consume energy within a factor of two of C. Given the growing role of computing in overall energy consumption, these efficiency disparities are increasingly significant. However, a troubling trend has emerged in education: a shift from languages like Java to Python. This move is counterproductive from a sustainability standpoint. https://www.sciencedirect.com/science/article/abs/pii/S0167642321000022?via%3Dihub

The effort should concentrate in the backend of python translation to machine language. C is an ancient limited language, CPP is very complex, we need as many people as possible learn programming and AI.

I am for the idea that even python become even simpler, even be a plain natural language (its happening with some AI assistants).

This is the future, one language and an easy one that can be learned by as many as possible! In nature, simple things work!

The beauty of Python is that many of its libraries can easily tap into compiled native code written in systems programming languages such as C, C++, Rust and others. When you use ML libraries such as TensorFlow or PyTorch, it’s not long before execution is transferred away from the interpreter and into native code libraries. Take a look at your Python installation’s site-packages, you will find many compiled libraries (.so, .dll) )!

Secondly, ML is only as good as its training data and more often than not, data cleaning is a must and Python with Pandas is perfect for transforming that data into being suitable for use as model features.

Read during a somewhat rather difficult part of my life, I think you’d really like this short book: https://www.qisforquantum.org/

If we get there (what with all the error correction and required scaling), quantum does something much more than massive paralleization, but the much more difficult part is we have the harder question of ‘what is the right question to ask it’ (?)

If this doesn’t make sense, you will finally get it when you read it. Just because we have the ‘Spruce Goose’ doesn’t imply we have any idea what to do with it.

Also, people have been playing with these ‘neuromorphic things’, or using light rather than raw layer signaling… I think this is interesting because obviously we have a power consumption problem going on here…

This unfortunately is ‘also above my pay grade’, and they don’t let me play with such things-- Just hang out with you guys :wink:

Python became the go-to language for data science and AI for several reasons, despite its relative slowness compared to lower-level languages like C. This popularity stems from its early adoption in the field and has continued due to a combination of factors:

  1. Ease of use and readability: Python’s simple syntax and clear structure make it easier for data scientists and researchers to write and understand code quickly, allowing them to focus on algorithms and models rather than intricate programming details.
  2. Rich ecosystem: Python has a vast collection of libraries and frameworks specifically designed for AI and machine learning, such as TensorFlow, PyTorch, scikit-learn, and NumPy. These tools have been optimized for performance and often use C or C++ under the hood for computationally intensive tasks.
  3. Rapid prototyping: Python’s interpreted nature allows for quick iteration and experimentation, which is crucial in AI research and development.
  4. Community and support: The large Python community provides extensive documentation, tutorials, and support for AI-related tasks.
  5. Integration capabilities: Python easily integrates with other languages and systems, making it versatile for various AI applications.

Regarding efficiency, it’s important to note that while Python itself may be slower than C, many AI libraries in Python are actually implemented in C or C++ for performance-critical operations. This means that the most computationally intensive parts of AI algorithms often run at speeds comparable to C.

For training large AI models that require significant computational power, developers often use distributed computing systems and GPU acceleration, which can mitigate Python’s performance limitations.

That said, some companies do use other languages like C++ or Java for production AI systems where speed is critical. However, Python remains popular for research, prototyping, and many production scenarios due to its balance of ease of use and performance when coupled with optimized libraries.

In AI and machine learning we deal with Statistics and with the help of some libraries of python we can easily handle this type of topics and complex maths calculation as compare to another language like c and c++.

AI is an umbrella term it’s a branch where many fields are converging. Many of AI, ML and DataScience Experts are not necessarily a computer scientist, though you can’t do AI, ML and DS without computers. But the experts are from variety of fields like mathematicians, statisticians, neuroscientists, medical field scientists, Astronomers, Engineers, Doctors, Informations Scientists etc etc. Languages like Python, R, MatLab etc etc are tools for them to stay away from the hardcore software development and programming, but focus on their research on Data and other aspects in an english like language syntax. This could be 1 of the reasons.

Another reason could be the popularity and availability of large set of libraries and tools available in Python. It’s a common perception that think of something you want to do in Python, and you can find a library or program for it out there, ready to be used.

3rd reason could be that it’s accepted as a industry standard among the AI, ML and DS community for their research and projects.

4th, It’s quite efficient in handling complex operations. Plus you don’t have to write the complete program in order to see the outcomes, you can execute and tweak as you go.

And lastly, like any other modern language and despite all it’s downsides, it’s a general purpose language and you can do alot in python with very few lines of code.

From my point of view, I like Python because offers high-level libraries for creating graphics and visualizations that are easy to use.