Saturday, January 13, 2024

Machine Learning vs Artificial Intelligence

I get asked occasionally what is the difference between machine learning and artificial intelligence. There are a lot of definitions out there, however many seem to be too general to be really useful. Also, let's move beyond the marketing definition of AI, because to a marketer everything with some math is AI. So let's come up with a practical definition such that when we see a model we know if it's ML or AI.

A good definition should leave no ambiguity such that when you see an algorithm or model you can definitely say it is one or the other. 

An example of a vague, general definition is this from Google's Web site:

"Artificial intelligence is a broad field, which refers to the use of technologies to build machines and computers that have the ability to mimic cognitive functions associated with human intelligence, such as being able to see, understand, and respond to spoken or written language, analyze data, make recommendations, and more. 

Although artificial intelligence is often thought of as a system in itself, it is a set of technologies implemented in a system to enable it to reason, learn, and act to solve a complex problem."

Okay, this sounds good as a textbook definition, but can someone use this and look at a convolutional graph neural network and decide if that is ML or AI? Not really.

Google does go on to try and give some more detail:

Artificial intelligence

  • AI allows a machine to simulate human intelligence to solve problems
  • The goal is to develop an intelligent system that can perform complex tasks
  • We build systems that can solve complex tasks like a human
  • AI has a wide scope of applications
  • AI uses technologies in a system so that it mimics human decision-making
  • AI works with all types of data: structured, semi-structured, and unstructured
  • AI systems use logic and decision trees to learn, reason, and self-correct

Machine learning

  • ML allows a machine to learn autonomously from past data
  • The goal is to build machines that can learn from data to increase the accuracy of the output
  • We train machines with data to perform specific tasks and deliver accurate results
  • Machine learning has a limited scope of applications
  • ML uses self-learning algorithms to produce predictive models
  • ML can only use structured and semi-structured data
  • ML systems rely on statistical models to learn and can self-correct when provided with new data

This seems like much more detail from Google, but I don't think it really clears it up for a person looking at an application as to how to categorize that application as either ML or AI. For example, "The goal is to develop an intelligent system that can perform complex tasks." Well, that's pretty vague and can be applied to either AI or ML. Or how about as to what defines ML, "The goal is to build machines that can learn from data to increase the accuracy of the output." Well that can be also said about AI. I can make similar points about the rest of their bulleted points. And this is not to pick on Google, because most definitions of ML vs AI are like this. Here is the definition from Coursera:

"In simplest terms, AI is computer software that mimics the ways that humans think in order to perform complex tasks, such as analyzing, reasoning, and learning. Machine learning, meanwhile, is a subset of AI that uses algorithms trained on data to produce models that can perform such complex tasks."

That's not really any different or better.

And often as stated here in the Coursera definition, part of a definition is just that ML is a subset of AI, but that is not very good in helping us to think about ML vs AI either.

So let's come up with a practical way to categorize ML and AI (as they stand in 2024) such that when we see a model or an application we can say it's either ML or AI.

Let's start by considering the intelligence part of AI. If something is intelligent, whether it's the narrow purposeful AI we have now or AGI, that intelligence requires a level of complexity such that examining the parts of a model individually does not help one to comprehend what the model is doing. There is a level of inscrutability in an AI model - the black box effect. Complete understanding moves beyond human comprehension of how a model works and instead we are left with at best an intuitive grasp as to how it works. For example, before OpenAI and others released their most useful models, there was just an intuition that building larger and larger language models trained on more and more text would work. There was an intuition by some (not everyone) that it would work but not a certainty. And when transformers with attention worked as well as they did, there was genuine excitement and even though they hoped it would work they weren't certain it would. So we can call LLMs - transformer architecture with attention as AI.

In contrast, one can take any of the typical machine learning algorithms packed into scikit-learn from multiple regression to random forest and we can do the math. We know why they work and we can prove why they work. Conversely, generative models and other types of models have a level of complexity that traditional ML models do not have.

That's my first point of differentiation, the level of complexity, size, and inscrutability of the models.  

My second point of differentiation concerns the inter-connectedness of the inputs into the model. In models I consider to be AI, they take into account the relationships and dependencies between inputs. One of the defining characteristics of graph neural networks, convolutional networks, stable diffusion, and large language models is that they specifically look at the relationships in the inputs. Nodes and edges in a graph, sliding windows in a CNN that try to capture the relationship between pixels, or the attention and position methods in large language models that try to recognize the contextual meaning in text are examples.

My last point of differentiation is the information packed into a single input is often enough to understand its relationship in a prediction in machine learning. I'm calling this "single input significance." For example, in a model trying to predict diabetes, where we have a set of predictor variables that includes things like the level of exercise, BMI, age, gender, etc., I can look at any of those variables and understand how they could predict diabetes. In fact, just one of those variables by itself would have some predictive value in predicting diabetes.

The same cannot be said about models like large language models, CNNs, or graph networks. You can't look at a picture of a cat and know that one pixel is predictive of cats, or that one word in a sentence is predictive of meaning without the context, or that one node in a network is predictive. Because of that, I consider these types of models to be AI.

To sum it all up, I have three characteristics that distinguish between ML and AI models

1) Inscrutability

2) Inter-connectedness

3) Amount of single input significance

So hopefully that helps if someone asks you what is the difference between ML and AI or if you are looking at some models and want to categorize them. 

However, this is my definition as it stands now in 2024. I think moving forward as we head towards AGI, the lines will change as many of the ML techniques will be thought of as one of the many types of tools that an AGI can use. Also, the definition of AGI is burdened with some of the same vagueness of ML vs AI, but it also has the same characteristics I'm outlining here of inscrutability, inter-connectedness, and amount of single input granular significance. 

But there are additional characteristics of AGI - but I will lay out my opinion of what those are in an upcoming post. 

Wednesday, December 27, 2023

Reflections on Sam Altman's "What I Wish Someone Had Told Me"

On Dec 21, Sam Altman wrote a blog post titled "What I Wish Someone Had Told Me." He lists 17 points with relevance as a guide to not only starting but also successfully running a venture. What is interesting about the post is that this is not the normal internet clickbait list of "Top 10 Ideas to Start a Business." You can tell these are ideas that he has been thinking about a lot lately.

Here is his list:

  1. Optimism, obsession, self-belief, raw horsepower and personal connections are how things get started.
  2. Cohesive teams, the right combination of calmness and urgency, and unreasonable commitment are how things get finished. Long-term orientation is in short supply; try not to worry about what people think in the short term, which will get easier over time.
  3. It is easier for a team to do a hard thing that really matters than to do an easy thing that doesn’t really matter; audacious ideas motivate people.
  4. Incentives are superpowers; set them carefully.
  5. Concentrate your resources on a small number of high-conviction bets; this is easy to say but evidently hard to do. You can delete more stuff than you think.
  6. Communicate clearly and concisely.
  7. Fight bullshit and bureaucracy every time you see it and get other people to fight it too. Do not let the org chart get in the way of people working productively together.
  8. Outcomes are what count; don’t let good process excuse bad results.
  9. Spend more time recruiting. Take risks on high-potential people with a fast rate of improvement. Look for evidence of getting stuff done in addition to intelligence.
  10. Superstars are even more valuable than they seem, but you have to evaluate people on their net impact on the performance of the organization.
  11. Fast iteration can make up for a lot; it’s usually ok to be wrong if you iterate quickly. Plans should be measured in decades, execution should be measured in weeks.
  12. Don’t fight the business equivalent of the laws of physics.
  13. Inspiration is perishable and life goes by fast. Inaction is a particularly insidious type of risk.
  14. Scale often has surprising emergent properties.
  15. Compounding exponentials are magic. In particular, you really want to build a business that gets a compounding advantage with scale.
  16. Get back up and keep going.
  17. Working with great people is one of the best parts of life.


Let's dive deeper into some key takeaways and explore their implications.

The Genesis of Great Ventures: Optimism and Obsession

Altman begins with the foundational elements of any successful venture: optimism, obsession, self-belief, raw horsepower, and personal connections. This combination is potent. Optimism fuels the journey, obsession drives the focus, and self-belief acts as a shield against naysayers. You have to be a "true believer" and surround yourself with others who are committed to that vision. Because, if you don't believe in the vision, then no one else will.

From Start to Finish: Cohesion, Commitment, and Long-Term Orientation

While starting is about energy and vision, finishing is about execution. Altman emphasizes the importance of cohesive teams, the right mix of calmness and urgency, and an "unreasonable" commitment to the cause. Importantly, he advises a long-term orientation, advocating for a focus on the big picture and not getting bogged down by short-term opinions.

The Power of Audacious Goals and Incentives

I love this. Do hard stuff. Stuff that everyone else thinks is impossible. That's motivating. Altman highlights that teams are more motivated by these challenging yet meaningful tasks rather than by easy, insignificant ones. He also touches upon the superpower of incentives, advising careful consideration in their setup. This aligns with the idea that what gets measured and rewarded gets done.

Resource Allocation and Communication

Stressing the importance of concentrating resources on high-conviction bets, Altman suggests that it's possible to achieve more by doing less but doing it well. He also underscores the importance of clear and concise communication, a vital skill in any leader's toolkit.

Fighting Bureaucracy and Focusing on Outcomes

Yes! In a call to resist bureaucracy and inefficiency, Altman encourages a culture of fighting against these elements. He reminds us that in the end, outcomes are what count, and good processes shouldn't be used to excuse poor results. Good ideas should not follow a chain of command. Everyone has the potential to generate great ideas.

The Importance of Recruitment and Valuing Superstars

Altman places a high emphasis on recruitment, urging leaders to take risks on high-potential individuals and to value evidence of accomplishment as much as intelligence. He also notes the significant impact superstars can have on an organization, provided their net impact is positive.

The Magic of Fast Iteration and the Laws of Business Physics

I would like to hear more about this - what particular experiences he is alluding to here. But I think he is continuing on with his points about the ability to iterate quickly as presented as a crucial business skill, with Altman advising that short-term execution should be swift, even if plans are laid out over decades. I don't know if he's exaggerating here with "decades" - but let's say having plans that have a long term focus. He also cautions against fighting the fundamental principles of business, likening them to the laws of physics. I think these fundamental principles he's referring to here are situations where businesses follow paths of doing things out of a sense of inertia and are not being adaptive.

The Power of Compounding and Perseverance

Again I would like to hear more from his personal experiences here with examples, but Altman is touching on the magical properties of compounding exponentials, especially in business growth, and emphasizes the importance of building a business that gains a compounding advantage with scale. The next part isn't particularly unique, but he ends with a reminder of the importance of resilience, urging readers to get back up and keep going.

Working with Great People

Finally, Altman concludes by stating that one of the best parts of life is working with great people. This not only enhances the quality of work but also enriches the journey.

Conclusion

Sam Altman's post moves beyond the initial steps of starting a business, going through the nuances of nurturing and leading a venture. Altman's advice, while rooted in his extensive experience at Y Combinator and OpenAI resonates, providing a balanced mix of strategy and personal growth. I think it's particularly insightful for those on the entrepreneurial path, offering guidance that is both reflective and grounded in practicality.


I tend to follow what Sam Altman follows fairly closely along with others at OpenAI in order to read the tea leaves about the direction that they believe AI is heading towards. Also, you have to respect a guy who has been able to head up one of the most widely successful software launches in history with a staff that is a fraction of the size of other tech giants. And also a person who has helped create such an innovative environment and an environment of true believers where so many people were willing to quit in the failed attempt to force him out


So that is my interpretation about the post and hopefully he will give more in depth explanations in one of his many speaking engagements or interviews, But suffice it to say, Sam Altman's blog post offers a thoughtful and pragmatic perspective on entrepreneurship.

Sunday, December 17, 2023

AI Book Club

I have a new post in my podcast/YouTube channel here. 

I started this podcast almost three years ago, which was significantly before the release of ChatGPT. At the time, there were some open source models out that could be used and Web interfaces like GPT-J and GPT NEO, so there was work being done from Hugging Face, Eleuther.AI and others, but the latest version version from OpenAI was 3.0.

The aim of the podcast was twofold:

1) Measure the progress in large language models 

2) Have some fun with LLMs by using them to have a "discussion" such as people might have in discussing books.

I used different LLMs and did some fine tuning to try and give the AIs unique personalities. I created two different AIs, Marie and Charles, interacting with the program I built - none of which was scripted out other than me having an idea of the topics and questions I wanted to ask. I then ran the text of our conversations through Google's text to voice and video synching Python code that created deep fake renditions for the two video avatars.

All of these versions performed fairly well (at least I thought so at the time), but they did have their shortcomings - many of which I outlined in this video in March of 2022. One of the biggest issues was them making up their own facts about the book we were discussing. At that time, I don't remember anyone using the term "hallucinating" as everyone commonly uses the term now with LLMs, but that's what they were doing.

However, they did create some very original and often times surprising discussion.

In this newest podcast, where we discuss Alice in Wonderland, I added a third AI that I called Beth. LLMs are much better now than when I first started out. Even though everyone likes to talk now about LLM hallucinations. they are much more factually oriented now than what they were two years ago.

Before I was very hesitant to ask them about details about the plot, because they might make up parts of the story that didn't happen, so I would steer the conversation to talking about ideas from the plot, because them being creative about their "interpretation" of what I described works, but it doesn't work if they were creating, for example, characters that never existed in the story.

However, now with the newest LLMs they know the story, they can repeat plot points and comment on them and what they create is not the plot but their "ideas" about the plot and the characters. So it's a much better conversation.

In addition, I'm now taking all of the conversations and creating vector based databases and am working on using MemGPT to give them long term memory so that they can have some continuity over the episodes. This will not only give them consistency I hope, but also because they are making up their own back stories when I ask them what they have been up to, they won't contradict themselves in a current video with something they said they were doing in a previous video.

You can view the latest video or any of the videos here.

Saturday, November 18, 2023

Sam Altman Firing

After I wrote this post, about an hour later it was announced that Sam Altman had been fired. Later Greg Brockman and others have quit. Not to speculate too much about what this will mean over the next days, weeks, and months, but suffice it to say it increases the amount of unpredictability around OpenAI in particular and will have ripple effects across the industry. Those affected the most will be those who built solutions based on OpenAI or organizations building in dependencies on OpenAI.

There are many brilliant people at OpenAI, as long as the brain drain doesn't turn into a flood OpenAI should be okay. Since it seems like it's the deceleration people who have won out at OpenAI, we'll just have to wait and see how that affects their product roadmap.

Sam Altman, Greg Brockman, and others will form new companies, maybe together, maybe separately while raising large amounts of money from investors. Whatever the new venture or ventures will be, I don't think it will dissuade him at all in pursuing AGI. It's his life's work and he will surround himself with those who also want to build AGI.

This will not cause a long delay of the arrival of AGI. The splintering may actually accelerate its arrival. And also, AGI was also not dependent on what happened at OpenAI - there are many people working on AGI.

Whether AGI is delayed or accelerated, it will happen.

Friday, November 17, 2023

Chat GPT Agents

On November 6th, Open AI at its Developer Days announced the release of GPT Apps that allows the user to create custom GPTs that can be shared with "low code" or "no code." This feature is only available for the Chat GPT Plus users. 

During Developer Days, the demos that they did for custom GPTs were very impressive, but let's dive in and look at what creating a "GPT" actually is and what the future implications could be.

What is an Open AI GPT?

First let's describe what it's not. It's not a separate GPT you are creating. You are also not "fine tuning a model." 

On the Open AI screen they simply describe it as customizing a version of ChatGPT for a specific purpose. When you enter the screen to create your GPT, it asks you what kind of GPT you want to create. What then follows is a back and forth of questions that customize the purpose of the GPT. It creates an app name and icon. As you are answering the questions it builds it and you can try it out on the right hand side. This literally takes minutes and is probably the ultimate in a "no code" experience. You can always iterate and conversationally make changes or click the "Configure" tab to make specific edits. It also suggests "conversation starters" to help the user interact with your app.

So it is a fun way to create a very targeted prompt for your purpose that may have been difficult to do. Which might or might not sound impressive, but the experience of doing it is impressive. Plus there are features that put it above just a prompt organizer. For example you can enable searching the Web, using DALL-E to do image creation, and use code interpreter. You can also upload files for the app to use. Using any of these greatly increases the impressiveness of the app. At that point you can share you app with specific people or with the public.

But maybe the most important feature and the one that can separate an app from other apps is the ability use "custom actions." Custom actions allows the app to call APIs. In order to use custom actions turns it from a "no code" to a "low code" experience. 

But if it's this easy and a person can build something pretty cool in minutes what's to stop someone else from being able to do it or to copy it? I think there are two things that can make it unique. 

1) Use file uploads to augment the app's retrieval. If you work at a company and have the Chat GPT Enterprise that emphasizes security, you might create an app centered around your department or initiative, upload some files for it to use, and then share it with others in your company. What's also nice about the Enterprise version, is you can just choose to share it to your organization and not to the public.

2) By using APIs such as those from Zapier, your app can stand out by giving it capabilities that people with no code abilities would not easily be able to duplicate. Plus, If you take it a step further and you have an external API that you own and that information is the central part of the app, your app has that as a barrier.

App Store

One of the other big announcements, is the announcement of an App Store by the end of this month. We'll see when the actual timing is and few details of how the store will work have been released at this time. Many people are comparing it to the introduction of the Apple App Store, but there are important differences. No one knows how the economics of Open AIs App Store will work or if it's a separate cost, but I doubt it's like Apple's. Also, no one knows what the approval process or what requirements there might be. One of the big questions to me, is if it's this easy to create an app, will the App Store be overrun with submissions, duplicates, or near duplicates? Or will some kind of cost or approval barrier prevent that? We don't know the answers to that yet, but will soon - I expect answers to some of these questions before the end of the year.

My Experiment

With it being so easy to create an app, I had to try it out. And if you have Chat GPT Plus, I encourage you to give it a try of building your own app.

I like to run. My idea as a runner was to create a running app that would tell me given a location the best routes in the area. When I travel, I will often not know the best places to run, which entails me doing a lot of googling.

https://chat.openai.com/g/g-C7mXg4svV-run-planner

So if the app is given a location, it will search the Web across many different sites to look at what are popular running routes. It's interesting watching it search different sites for routes - many of these sites wouldn't have occurred to me to search through if I was doing this manually.

Searching Wheeling IL, it gave me a list of possible routes with some having links for more information. It even told me that with Wheeling having variable weather at different times of the year, some of the trails can be slick so check the weather before going out.

I also added to the app the ability to search for upcoming races in the area and to give training plans for different types of races.

The experience was fun and took me probably less than 30 minutes.

Future Implications

It's going to be very interesting to see how the future plays out for all of this.

First, the App Store, there are a lot of questions surrounding it as mentioned above. But also, I had to wonder how does an App Store align with Open AI's "core values." Recently to much media fanfare Open AI changed their "core values" page with the main difference being -

AGI focus

We are committed to building safe, beneficial AGI that will have a massive positive impact on humanity's future.

Anything that doesn’t help with that is out of scope. 

So does having an App Store seem out of scope to building AGI? It seems so to me. Right after they announce their only focus is building AGI, they announce an App Store?

Second, this is another surge in the swell of "low code" and "no code" solutions. This is just going to accelerate as tasks become more automated and expert skills shift downstream or to different use cases.

Third, right now what you can change on the Configure tab is pretty limited. But we can expect that to become much more feature rich in the future. As that part gets built out, it's those new capabilities that could make GPT Apps really take off.

Fourth, one of the other things that Open AI introduced was the Assistant's API that has threading, coding in a sandbox, retrieval, and function calling. Somewhat similarly, what if Chat GPT Apps could themselves be called as autonomous agents? The potential would be endless.

Summary

GPT Apps was just one of the big announcements. The much anticipated Dev Days lived up to the hype for me. And if you have access to Chat GPT Plus, you should try it out. 

As big of a year as Open AI had this year, I'm expecting 2024 to be an even bigger year for them - especially with Sam Altman discussing in an interview that they are working on GPT 5 and openly talking about research in building AGI and "how to build superintelligence."

Tuesday, September 26, 2023

Top 10 Languages/Tools for Data Science in 2023

Let's talk top 10 languages/tools for data science in 2023. Obviously, this is going to be very opinionated and everyone's list is going to be different depending on personal experiences in specific industries. But I want to keep this as generalized as possible as to what I think someone should know in 2023. I'm also keeping this list focused on tools or software used in data science and not concepts or algorithms - I think that would make another great list: "Top 10 Data Science Concepts" and I'll try and do that too in a later post.

So why 10? Why not 5 or 20 or even 11? I'm not a big fan of top 10 lists, because 10 is such an arbitrary cutoff, but we can blame top 10 lists on the fact that we have 10 fingers and that humans generally like round numbers. It has always fascinated me that if we had 8 fingers we would be primarily base 8 and how would society be different if we weren't base 10. 

To further go down the rabbit hole, the origin of base 10 systems developed independently across different civilizations. But it was Indian mathematicians who perfected its use and along with Arabic traders spread it throughout the known world in the 7th century enabling advances in commerce and science.

But back to my top 10 list:

1) Python

You need to know Python in 2023. It is where the most cutting edge development is happening in AI. You need to know it deeply and not just superficially. And you need to be able to write not just in Jupyter Notebooks, but be able to write Python (.py) scripts. It is THE language for machine learning. But it doesn't just excel for machine learning, it excels in ETL and in general process automation. It's also making inroads into front end development with the advent of PyScript in the last year.

It routinely sits across the top of popularity lists and right now is #1 in the TIOBE index - this is due to it's relative simplicity while also being able to accomplish complex tasks. As a general purpose language it can be applied in tasks well beyond data science. Anyone with "Analyst" in their title, even if they aren't doing data science or machine learning, needs to know Python in 2023 if only just to be able to automate parts of their job.

2) Pandas

Know the Python library Pandas. You won't be able to read through any machine learning code without knowing Pandas really well. Plus, knowing Pandas is like having a super power for data manipulation.

3) Matplotlib

You need to be able to wield a charting library and Matplotlib is the most popular. It is hard to find programs, articles, books, or examples that don't include some kind of Matplotlib chart. I find its syntax to not be the cleanest and there are other good libraries like Plotly and Seaborn to name a few, but it's hard to get by without being able to use Matplotlib.

4) SQL

You need to be able to get your data from somewhere right? And most likely some form of SQL knowledge (whether that's Postgres, MS-SQL, MySQL, Oracle, etc) is going to be required (more on NoSql databases below).

5) Scikit-learn

Scikit-learn should be your bread and butter for what you use to solve most business related problems. Its rich library of machine learning and statistical models can be applied to a wide variety of everyday data analytics. Plus, the documentation is superb.

6) PyTorch

PyTorch has been moving fast up on my list and has overtaken TensorFlow for me and for many others. It's "pythonic" nature and object-oriented approach has some appeal. It's also arguably easier to debug and the PyTorch Foundation does an excellent job of maintaining its ecosystem. But it's the fact that it's increasingly in some of the most cutting edge research at some of the most important companies in AI, especially in large language modeling that is really driving its rise.

7) TensorFlow

I personally love TensorFlow and you should know it for neural networks and I like it's overall structure, but it's losing ground in my mind for some of the reasons outlined above.

8) Streamlit

I'm cheating here a little bit, because I could easily put Gradio here (or Dash for that matter). But I think what's important here is that data scientists need a good way to communicate through applications quickly.

9) Selenium

Being a data scientist is about being able to get data and some of that data might not always be available in your database or through an API, so being able to scrape data is a valuable skill.

10) MongoDB

I'm cheating again here, because I think being familiar with NoSQL databases in general whether that's MongoDB or another version is important and knowing its advantages (and disadvantages). And generally knowing MongoDB shows that you are familiar with JSON (BSON in this case) type data and can parse data that has key/value structure. Because that ability to work with MongoDB is some of the same skills you need to work with API data and Python dictionaries. And being able to work with key/value data and dictionaries in Python is a fundamental skill you should have.

So that's it.

What's not on my list? Well, to mention a few: Julia, Mojo, R, Hadoop, Hive, Javascript, C/C++, Rust, Scala, SAS, SPSS, Matlab, Java, NLP packages such as NLTK, spaCy, Excel, and VBA.

I have a lot of respect for Julia as a language, so it's barely not making the list. Same goes with Mojo. But also because Mojo was just released for Linux. It needs to be rolled out to be able run in Mac/Windows, but it may make the list next year. 

I almost put Javascript on the list primarily because as one of the most popular languages it is hard to escape and believing Javascript is just a front end language is wrong. Javascript is everywhere - NodeJS, stored procedures, etc. Plus everyone should know some JS (along with some HTML).

I also didn't single out NumPy as a specific Python package like I did with Pandas. I just thought it was obvious that you should know NumPy as a Python user and that it is really important. It's an arbitrary decision to not list it separately.

I could have easily put one or both NLP packages of NLTK or spaCy on the list and maybe next time I will. 

As for the languages of C/C++ and Rust, I could make a strong case for one or both to be on the list for performance reasons. C/C++ is really important in the Python/machine learning ecosystem and there's some great things happening with Rust, such as Polars. Rust and Python work really well together and it's going to be interesting to see how the various performance initiatives turn out in AI considering the current work to make Python faster, languages like Julia and Mojo, or interfacing directly with languages like C/C++ or Rust.

I think that for VBA as a language being used in some analytics the writing is on the wall even though there's a lot of VBA code out there. One reason is Microsoft's decision to include Python in Excel is going to supplant many of the VBA use cases. Plus, you can tell Microsoft has not been putting resources into it. The UI and the error messages are terrible. It looks like it was written in the 90's and seems like it hasn't improved or even changed in years. 

Many people will be upset with this, but the trend for R is not good. Its raison d'etre in the 90's was as a reaction to SAS and especially SPSS with their onerous licensing. It became very popular as many people jumped into creating some pretty great statistical packages for it - especially in academic circles. It will continue to have its specialized niches, but it has little future in cutting edge AI research. As a side anecdote, in the data science class I teach, we used to do a very basic introduction to R towards the end with most of the course being Python and other tools. But now the university decided to remove R after evaluating the market, so none of the students coming out of this program will have even a basic familiarity with R.

Excel is not on the list because everyone knows Excel and knowing Excel doesn't make you a data scientist.

I'm leaving off Big Data solutions for now, but if I would put some on the list it would be Spark based ones or proprietary solutions from Snowflake, AWS, Google, Databricks etc. and not MapReduce based solutions that involve Hive or Hadoop. 

I'm also leaving off proprietary machine learning solutions like AWS SageMaker for now.

I also didn't discuss editors or IDEs. I use VS Code primarily because I can have one IDE for any language, but I think there's a lot of good choices and if you use PyCharm or any of the others that is fine. I don't think it matters as long as you are comfortable with it. Or if you want to be really cool use VIM.

So that's the list for 2023. I'll revisit in 2024 to see what has changed.

Saturday, September 23, 2023

Processing Monster Datasets with Polars

Over the last year, I've been turning more and more to the Python module Polars for handling large datasets that couldn't fit into memory on a single machine. Before, I had used the library Dask for these occasions, and what I liked most about Dask is the very close syntax to Pandas, but the bottom line is that Polars is just so incredibly fast and probably a better fit on single machine processing than Dask. The Polars syntax isn't difficult and has syntax similarity to Spark. For single machine processing where I didn't need the overhead and the complexity of distributed processing that Dask and PySpark excel at, Polars is a great alternative.

You can find many speed comparisons between Pandas and Polars such as here and here, but I've found it commonly is about 10-100 times faster. And that includes it being faster than the new-ish 2.0 version of Pandas using Pyarrow.

In my work in medicinal chemistry, I've been processing the ADME (absorption, distribution, metabolism, excretion) characteristics of molecules, the synthesizability of molecules, and their patent availability which can be very compute intensive. Millions of these records can be processed in times that would not be practically achievable with Pandas.

Does that mean that you should just write everything in Polars and not use Pandas anymore? No! First, just using Polars is going to be overkill in some cases when your data size is relatively small and it's even possible it would be slower in some edge cases on small datasets. Second, Pandas dataframes are ubiquitous and you can count on every Python module that has ever been built to be able to work with Pandas dataframes. That is not true with Polars dataframes and in those cases you will have to convert the dataframe from Polars to Pandas.

But what exactly is Polars?

Polars is a high-performance dataframe library for Python written in Rust. And that's the key - that's it's written in Rust. It is designed to provide fast and efficient data processing capabilities, even for large datasets that might not fit into memory. Polars combines the flexibility and user-friendliness of Python with the speed and scalability of Rust, making it a compelling choice for a wide range of data processing tasks, including data wrangling and cleaning, data exploration and visualization, machine learning and data science, data pipelines and ETL.

Polars offers a number of features:

  • Speed: Polars is one of the fastest dataframe libraries available, with performance comparable to Arrow on many tasks. Much of this is due to it being written in Rust and that it can use all of the machine cores in parallel.
  • Scalability: Polars can handle datasets much larger than your available RAM, thanks to its lazy execution model - so it will optionally not need to load all of the data into memory. I have used it to read in a massive dataset that contained all known patented molecules.
  • Ease of use: Polars has a familiar and intuitive API that is easy to learn for users with experience with other dataframe libraries, such as Pandas and PySpark.
  • Feature richness: Polars offers a comprehensive set of features for data processing that parallels those of Pandas or PySpark, including filtering, sorting, grouping, aggregation, and joining.

You can create a Polars DataFrame from a variety of data sources, such as CSV files, Parquet files, and Arrow buffers. Once you have a DataFrame, you can use Polars to perform a wide range of data processing tasks.

For drug discovery, I have used Polars on large data sets to analyze molecular interactions, predict pharmacokinetic properties, and optimize drug design. For example, I have used it to help calculate the binding energy of a molecule to its target where the data sets are large. This can be useful for identifying drug candidates that are likely to have high affinity for their targets.

In these examples below which are common use cases in Pandas, I have the Polars code and then the equivalent Pandas code as a comment underneath when it's different:

import polars as pl
import pandas as pd

# Load data about molecules from a CSV file
df = pl.read_csv('molecules.csv')
# df = pd.read_csv('molecules.csv')

Selecting columns:
# Select specific columns about a molecule
selected_df = df.select(['Id', 'SMILES', "Mol_Wgt', "LogP", "NumHAcceptors", "NumHDonors"])
# Equivalent Pandas code
# selected_df = df[['Protein', 'SMILES', "Mol_Wgt', "LogP", "NumHAcceptors", "NumHDonors"]]
selected_df.head()
Selecting rows:

# Filter the df
filtered_df = df.filter(pl.col('Mol_Wgt') < 500)

# Equivalent Pandas code using .loc
# filtered_df = df.loc[df['Mol_Wgt'] < 500]

Grouping data:

# Group on Protein and calculate the mean Mol Wgt by Protein
grouped_df = df.groupby(by='Protein').agg(pl.col('Mol_Wgt').mean())

# Equivalent Pandas code
# grouped_df = df.groupby(['Protein']].mean()[['Mol_Wgt']]

Sorting rows by a column:

# Group on Protein and calculate the mean Mol Wgt by Protein
sorted_df = df.sort(by='Mol_Wgt')

# Equivalent Pandas code
# sorted_df = df.sort_values('Mol_Wgt')

As you can see, the syntax is not that different and because of the dataframe structure and its expressive syntax. Polars works great for large data sets that can't fit into memory that need processing speed. With all of these considerations, you can see that Polars is a great tool for any data scientist to add.

Tuesday, July 4, 2023

Quantum Computing in Healthcare

In 1981, Richard Feynman gave a talk at a conference called "The Physics of Computation" which was latter detailed in the book Feynman Lectures on Computation.  Feynman observed that the world - its physics is quantum and if one wanted to simulate that physics, a quantum computer would be the way to do that. He then went on and outlined many of the main concepts of what is still used in the field of quantum computing.

However, quantum computing was out of reach then for the technology of the 1980's and even now 40+ years later we are still in a nascent stage of quantum computing. The running joke for a long time has been that quantum computing (as well as for fusion energy) is that we are always just 10 years away. Then 10 years later we are again just 10 years away. But recently, there have been some announcements that lead me to believe that we could be arriving at a massive inflection point in turning theory into extremely practical applications. For example, IBM just recently announced that through a partnership with the University of Chicago and the University of Tokyo they plan on building a 100,000 qubit computer within 10 years. Google subsidiary SandboxAQ is looking to do molecular simulations of interactions for drug discovery. And startups looking to use quantum computing in drug discovery include Aqemia doing structure based design of drug candidates and Qubit Pharmaceuticals using quantum computing to do simulations of molecules.

Before I get into what I think will be some of the biggest applications, a brief discussion of what are the characteristics of quantum computing that make it special when compared to classical computing is warranted. And by classical computing, it is meant the everyday binary computing of 0's and 1's that power everything we do. 

These 0's and 1's (bits) of classical computing are processed through logical operations, such as AND, OR, and NOT gates, to perform computations. However, in quantum computing, we utilize quantum bits, or qubits, which can exist in a superposition of states.

A qubit can represent both 0 and 1 simultaneously, thanks to the property of superposition. This means that a qubit can be in a state that is a combination of 0 and 1 at the same time. For example, a qubit can be 0 and 1 with a certain probability assigned to each state. This allows quantum computers to perform multiple computations in parallel, exponentially increasing their computational power compared to classical computers.

Furthermore, qubits can also exhibit a property called entanglement. When qubits become entangled, the state of one qubit becomes correlated with the state of another qubit, regardless of the distance between them. This entanglement enables quantum computers to perform operations on multiple qubits simultaneously, leading to the potential for massive computational speedups.

To manipulate qubits and perform computations, quantum computers rely on quantum gates. These gates are analogous to the logical gates in classical computing and allow for operations such as changing the probability distribution of a qubit's states or entangling qubits together.

If you want to dive more into the details of quantum computing, IBM has a great resource that goes through the details of how it works and what's really cool is they show that by using their python-based Qiskit language you can get some real experience in quantum computing using their cloud quantum computers. So you can install it and gets some hands on experience and even upload your code on one of their quantum computers to run.

https://www.ibm.com/topics/quantum-computing

Also, here is a great series again from IBM that explains quantum computing.

"Understanding Quantum Information and Computation"

Quantum computing holds great promise for solving complex problems that are computationally infeasible for classical computers. Certain algorithms, such as Shor's algorithm, can factor large numbers exponentially faster on a quantum computer, posing a potential threat to modern cryptographic systems. Quantum computers also excel in optimization, simulation of quantum systems, and machine learning tasks. Specifically quantum computing could be applied to financial modeling, materials design, and transportation scheduling. 

And as a side note, quantum computing can be applied to natural language processing. In October 2021, Cambridge Quantum Computing (CQC) announced the release of the first Quantum Natural Language Processing (QNLP) toolkit and library. This toolkit can translate sentences into quantum circuits. As powerful as transformers/attention models have become with GPT with companies like OpenAI, there will need to be another breakthrough or multiple breakthroughs to reach sophisticated AGI and quantum computing may be one of the factors to enable an acceleration towards artificial super intelligence (ASI).

With all of these possible applications of quantum computing, some of the more intriguing ones are in healthcare. In March of this year, IBM and Cleveland Clinic announced their partnership of the first on-site quantum computer. A few of the applications will include prediction models for cardiovascular disease, drug discovery, and genetics.

It is in these areas of drug discovery and genetics that I believe hold the greatest promise in healthcare.

Drug Discovery

  • Simulation of molecular behavior: Quantum computers can simulate the behavior of molecules at the quantum level with high precision. This capability is crucial for understanding the interactions between drugs and their target molecules, as well as predicting their effectiveness and potential side effects. By providing more accurate and detailed simulations, quantum computers can accelerate the drug discovery process and improve the success rate of drug candidates.
  • Drug optimization and molecular design: Quantum computing can aid in optimizing drug molecules and designing new ones. Quantum algorithms can explore vast chemical space to identify compounds with specific properties, such as high potency, selectivity, and bioavailability. This can potentially lead to the discovery of novel drugs or optimization of existing ones, making the drug development process more efficient and cost-effective.
  • Quantum machine learning for drug discovery: Quantum machine learning algorithms running on quantum computers can analyze large datasets related to drug targets, molecular structures, and biological interactions. These algorithms can extract valuable insights, identify patterns, and make predictions to guide drug discovery efforts. Quantum machine learning has the potential to improve target identification, lead optimization, and personalized medicine.
  • Quantum chemistry calculations: Quantum computers can perform complex quantum chemistry calculations, such as calculating molecular energies, reaction rates, and properties of chemical systems. These calculations are computationally intensive and often intractable for classical computers. By harnessing quantum algorithms, quantum computers can provide more accurate and efficient solutions, enabling researchers to better understand chemical processes and accelerate drug discovery.

Genetics

Considering the large number of base pairs in the human genome, as explained in this paper, an entire genome of a person could be stored in ~34 qubits. And amazingly, doubling the size of the quantum compute could theoretically store the genome of every person on the planet - illustrating the potential of quantum computing is not just its potential speed but its ability to store and process vast amounts of data. This power could revolutionize medicine in genetics in two ways:

  • Genomic data analysis: Quantum computing can help analyze vast amounts of genomic data, such as DNA sequences, gene expression profiles, and genetic variations. Quantum algorithms can enhance the efficiency of processing and analyzing this data, enabling researchers to identify genetic patterns, disease markers, and potential drug targets more accurately and quickly.
  • Precision medicine and personalized therapies: Quantum computing can aid in the development of personalized medicine approaches by analyzing individual genetic data and matching it with specific drug responses. Quantum algorithms can process and analyze large-scale genomic datasets to identify genetic markers that influence drug efficacy, toxicity, and treatment outcomes. This information can guide the development of tailored therapies based on an individual's genetic profile.

For both drug discovery and genetics, combining quantum computing with artificial intelligence would be completely transformative in finding therapies and cures in healthcare.

So what should you do?

What should you do as an organization or as a technical person looking at the possible quantum landscape? Every company should periodically be evaluating their preparedness and long range opportunities, because even though practical applications may not be here yet, there will be a moment when that will change - and the opportunities could be enormous for companies in the right industries who have positioned themselves. For individuals, there is currently a knowledge shortage and I believe there will be a knowledge shortage for a long time regarding quantum computing as it accelerates. So it is never too early to start learning as much as you can about it.

Summary

Quantum computing has great potential, however it is important not to think of it as a replacement for classical computing. Quantum computing has very specific situations where it should be applied just like the GPU in machine learning has its specific uses. And just like GPUs, the ideal machine will be a marriage between quantum computing and classical computing.

However as great as the promise of quantum computing, it is still in its early stages. And although the announcements from IBM to build a 100,000 qubit computer by the end of the decade and announcements from Google and others are encouraging, many technical challenges remain. Building stable and error-resistant qubits, minimizing environmental interference, and developing error-correcting codes are among the significant hurdles researchers are working to overcome. Despite these challenges, quantum computing has the potential to revolutionize many different industries such as healthcare.

We Gave Simulated Xenobots Inheritance. They Got Faster. Then They Plateaued

Biobot Tierra — Inheritance and Adaptation Machine Intelligence · Technical Essays April 2026 We gave a population...