Python and AI

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
Post Reply
User avatar
MattyP
Baaaaaa!
Baaaaaa!
Posts: 2905
Joined: Fri Mar 28, 2003 10:23 pm 0
XBL Gamertag: CypherQ
PSN: CypherQ
Location: Hull, East Yorkshire

Python and AI

Post by MattyP »

So my other half has recently started a master's in Data Science and AI at the Uni this year. Big challenge for her as she's never wrote any code before! It's a bit of a career change for her as she was a Senior Marketing Manager until August (long story but she has an opportunity to upskill af the moment!)

Anyhow they are using Python on the course. I've not really touched it before... Anyone use it? What does it give over older languages? Seems to be a bit Java like in that it compiles into bytecode and then runs this through a virtual machine (PVM).

So any thoughts is it something I should be learning
? What does it do over say Java/C#? Just intrigued why people choose this over older more established languages. Can't say I've had a problem getting done what I need to in Java or C# TBH.
A light that burns twice as bright burns half as long.

Steam/Xbox/PSN User Name: CypherQ
Switch - 8177-9514-5116
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Python and AI

Post by Dio »

It's a dynamic type language with good builtin support for list types, very easy to use for writing simple scripts, with a good module system and lots of libraries.

It's very easy to use for "generating things" - much more so than C++ and the like, because whatever format you're reading or writing there'll be some library that handles it and adding the library is as simple as adding "import <library>" into the script and it goes off and gets it. No cocking about with complicated build systems or similar. I've used it to generate diagrams for books and to generate various complex WAV files as input to silly Spectrum tape formats (I've managed to make a real Spectrum load Lords of Midnight in about 45 seconds off a Python-generated WAV). It's also pretty simple to learn to do simple things. Although I think it has distinct limits for how large you can really let projects get - the quality of code doesn't tend to be high and it is not easy to refactor it into cleaner forms with more type and error checking - that's not a problem for scripting.

Python's become one of the standard languages for plugging AI models together again because it's so simple to use - pull in the appropriate AI libs, and again you have all those input and output libs available and you can write Python code that transforms the data accordingly ready for the AI model to process. I haven't actually used PyTorch or similar myself though.
User avatar
MattyP
Baaaaaa!
Baaaaaa!
Posts: 2905
Joined: Fri Mar 28, 2003 10:23 pm 0
XBL Gamertag: CypherQ
PSN: CypherQ
Location: Hull, East Yorkshire

Re: Python and AI

Post by MattyP »

Ah great thanks for the feedback appreciated! :)

Sometimes when you get narrow focussed on things you loose track of the bigger picture in development! TBH I left the development domain a few years ago but most of my career prior to InfoSec stuff was in C++/Java/.Net so loose track of the new trendy languages! Although to be fair Python is apparently 32 years old...so not really new and trendy I guess... however I bet a majority if not all of the Python interpreters and virtual machines are coded up in C/C++ anyway. :D
A light that burns twice as bright burns half as long.

Steam/Xbox/PSN User Name: CypherQ
Switch - 8177-9514-5116
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8444
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: Python and AI

Post by KlaxonCow »

I've lightly touched Python. I needed Blender to kick out my 3D models in a specific "own format" and it uses Python as its scripting language.

It feels like a latter day Pascal or BASIC. Syntactically, it has that sort of attitude. It eschews C curly braces for actual words. Newlines actually end instructions, without semicolons everywhere.

I mean, there are C-isms in there, if you look closely. Dictionaries do use the curly braces and colon for initialisation, kind of like JSON. But it does feel more of the old COBOL school of thought of "make programs read like human language", eschewing C's "maths notation" syntactical sensibilities.

It has and understands tuples, sets, dictionaries, lists, etc. natively.

It's not playing C's "minimalist" game. it's got loads built into the language, rich libraries, etc. - again, the old pre-C school of thought: "look how many out-of-the-box features I have!!". Whereas, if you've read K&R's C Programming Language, they devote the introductory chapter on telling you everything that C doesn't have and what it doesn't do. A chapter featuring my favourite opening line: "C is a relatively low level language; This characterisation is not pejorative". C's sales pitch is that it's "portable ASM" and that it doesn't do stuff and doesn't have things built in, because the whole idea is that it's a minimal framework... and then everything beyond that is libraries. C sells itself on being the "DIY" language.

As I say, Python's not playing that game. It's playing the role of being the modern BASIC interpreter. Of course, we'd never just interpret code anymore, so it's a whole "virtual machine" thing going on but, well, that's just playing the part of a more complex interpreter. In use, the point is that it's dynamic, not a static compile.

It's a scripting language. As I say, a latter day BASIC interpreter. When you just want to get your shit done quick, and don't care too much about performance because, like, CPUs are very fast these days.

The expected pros and cons come out of that. Throw stuff together in 5 minutes. But is this language appropriate for some massive project? Not really. I'm sure you could give it a good go, but it's not really what it's for.

For learning, it's great. That old "human-like sentences" school of thought, of COBOL or Pascal or BASIC. Throw shit together in 5 minutes for a school project? Sorted.

Like, I'd never coded it before and then had to write an export filter for Blender. It wasn't that hard and it didn't take that long.

I'm a big C syntax fan, so I won't be converted. But it's alright. I had to use it, and I could use it, and it was okay. As I say, it put me in mind of being the modern version of Pascal or BASIC. Indeed, you could see the virtual machine as latter day "P code". It's all from that old school of thought. Not the C-like school of thought, where everything - Java, C++, JavaScript, PHP, etc. - is really just a different "flavour" of C.

I've also done AI. If we're talking neural networks, then it's all kind of irrelevant what language is used to implement the network. The neural network itself is its own thing that sits on top of that.

I used C++ when I was doing AI. But it was the '90s and we were using Pentiums, with fuck all GPU support. So, you know, it was all dog slow and, therefore, you wouldn't contemplate doing it anything other than C / C++ or even ASM, because the performance was dreadful even when you were using low level languages.

But, yeah, these days you'd fire all the calculations at a GPU - to do all that lovely "immense parallelism" - and it matters little what programming language you're using, so might as well go for the "throw it together in 5 minutes" scripting language.

If someone's learning to code then Python's a good shout. Just like, if we were back in the '80s, then learning BASIC is where you begin. As with BASIC, you'll eventually want to graduate beyond that, but it's a good place to start to learn the basic concepts to get going.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
User avatar
MattyP
Baaaaaa!
Baaaaaa!
Posts: 2905
Joined: Fri Mar 28, 2003 10:23 pm 0
XBL Gamertag: CypherQ
PSN: CypherQ
Location: Hull, East Yorkshire

Re: Python and AI

Post by MattyP »

Thanks makes sense why they are using it a bit more now!

I'll have a dabble some have an understanding as I guess I might come across it now and and again. However doesn't sound like something I'd code with regularly.
A light that burns twice as bright burns half as long.

Steam/Xbox/PSN User Name: CypherQ
Switch - 8177-9514-5116
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python and AI

Post by gilesgoat »

So .. it's not about an intelligent snake ? .. .. pity ...
Giles the billy goat
"Baa"
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8444
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: Python and AI

Post by KlaxonCow »

Actually, it's named after Monty Python.
Wikipedia wrote:Python's developers aim for it to be fun to use. This is reflected in its name—a tribute to the British comedy group Monty Python — and in occasionally playful approaches to tutorials and reference materials, such as the use of the terms "spam" and "eggs" (a reference to a Monty Python sketch) in examples, instead of the often-used "foo" and "bar".
And this also confirms the essential difference. Python is meant to be fun, easy, quick, simple to learn, etc. - that's the role that it's taking here. Not the best or fastest programming language ever, but the one you fire up to do a quick 5 minute fun project in. Job done.

So, yeah, not remotely surprising that it gets use in educational settings where people are learning to code and it's just small example projects for learning. It's perfect for that sort of thing.
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
TimC
Baaa!
Baaa!
Posts: 254
Joined: Thu Jan 08, 2004 8:57 pm 0
Location: Surrey Hills

Re: Python and AI

Post by TimC »

I work with AWS. We use python extensively as it’s easy to pick up and really easy to integrate with cloud services. It’s portable enough to run well in all the cloud runtime environments we use and fast enough for our needs. We rarely need the performance of complied language or something like Java/C# which both have a steeper learning curve than Python.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python and AI

Post by gilesgoat »

TimC wrote:I work with AWS. We use python extensively as it’s easy to pick up and really easy to integrate with cloud services. It’s portable enough to run well in all the cloud runtime environments we use and fast enough for our needs. We rarely need the performance of complied language or something like Java/C# which both have a steeper learning curve than Python.
Mah .. "I must have too much biased/done cause too many years of C/CPP" .. in terms of "simplicity to pick up/understand" I still think "you can't be that simpler than C" I mean "old K&R C" ..

CPP is a different kind of fish ...

We could say "C maybe is much more difficult to code with BECAUSE it's SIMPLER" .. actually "it's almost nothing" without "tons of libraries of functions".

Maybe "some languages look simpler" while actually they are "under the hood tremendously complicated".

Yes there's a thing about interpreted languages ( or JIT compiled ) about portability/extensibility, but you can't tell me that "C is so complex to learn".
Giles the billy goat
"Baa"
User avatar
pyroxian
Baaaaa!
Baaaaa!
Posts: 1308
Joined: Sat Nov 06, 2004 2:05 pm 0
Location: OX-ford

Re: Python and AI

Post by pyroxian »

No, but it's a pain to do anything in c. I've written scripts to convert xml to csv in about 5 lines of python - in c that would be a lot more!
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Python and AI

Post by gilesgoat »

pyroxian wrote:No, but it's a pain to do anything in c. I've written scripts to convert xml to csv in about 5 lines of python - in c that would be a lot more!
.. unless you'd have a function like ConvertXMLToCSV ( char *xml, char *csv ); that does it ..

It's a "pain" because it's simpler ...
Giles the billy goat
"Baa"
User avatar
pyroxian
Baaaaa!
Baaaaa!
Posts: 1308
Joined: Sat Nov 06, 2004 2:05 pm 0
Location: OX-ford

Re: Python and AI

Post by pyroxian »

gilesgoat wrote:
pyroxian wrote:No, but it's a pain to do anything in c. I've written scripts to convert xml to csv in about 5 lines of python - in c that would be a lot more!
.. unless you'd have a function like ConvertXMLToCSV ( char *xml, char *csv ); that does it ..

It's a "pain" because it's simpler ...
It's a pain because c doesn't give you much out of the box.
If I need to quickly write a script to do something it's much easier doing it in python which pretty much has all the tools I need to get something up and running in _minutes_.

If I want to do something fast though, I'll do it in c / c++ :)
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4597
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Python and AI

Post by Little stoned kiwi »

If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
Post Reply