We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Postgres and the Artificial Intelligence Landscape

00:00

Formal Metadata

Title
Postgres and the Artificial Intelligence Landscape
Title of Series
Number of Parts
637
Author
License
CC Attribution 2.0 Belgium:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Artificial intelligence, machine learning, and deep learning are intertwined capabilities that attempt to solve problems that defy traditional computational solutions — problems include fraud detection, voice recognition, and search result recommendations. While they defy simple computation, they are computationally expensive, involving computation of perhaps millions of probabilities and weights. While these computations can be done outside of the database, there are specific advantages of doing machine learning inside the database, close to where the data is stored. This presentation explains how to do machine learning inside the Postgres database.
179
Thumbnail
20:09
245
253
Thumbnail
30:06
294
350
Thumbnail
59:28
370
419
491
588
Thumbnail
30:18
Virtual machinePresentation of a groupDatabaseMachine learningTask (computing)CognitionFunction (mathematics)Integral domainHypermediaTuring testRoboticsFood energyVideoconferencingArtificial intelligenceComputer networkState of matterFrequencyRoboticsVideoconferencingNatural numberProcess (computing)Virtual machineCognitionSource codeLibrary (computing)Encapsulation (object-oriented programming)Artificial neural networkGreatest elementMachine learningQuicksortCartesian coordinate systemArithmetic meanTerm (mathematics)Turing testVector spacePoint (geometry)InformationImage resolutionRight angleDatabasePresentation of a groupUniform resource locatorComputer hardwareRow (database)Web pageRectanglePerturbation theoryAreaSlide ruleProbability density functionCore dumpCASE <Informatik>Expert systemPattern languageLink (knot theory)BitDecision theoryNumberMereologySubsetDifferent (Kate Ryan album)Network topologyLatent heatPhysical systemTask (computing)TensorField (computer science)SoftwareNeuroinformatikState of matterFocus (optics)Order (biology)Graph coloringDisk read-and-write headDemo (music)Closed set40 (number)UsabilityMathematicsDemoscenePhysicalismSoftware developerComputer animation
State of matterMachine learningWave packetVirtual machineMaizeMultiplication signWeightState of matterMeasurementWave packetTensorReinforcement learningSet (mathematics)ResultantVirtual machinePredictionCASE <Informatik>Musical ensembleLevel (video gaming)Goodness of fitHeat transferUnsupervised learningFeedbackMereologyQuicksortNumberComputer-assisted translationMedical imagingPhysical systemCoefficient of determinationArtificial neural networkVideoconferencingInformationMachine learningFunction (mathematics)Type theoryMechanism designException handlingArrow of timeDemo (music)Key (cryptography)MultiplicationEndliche ModelltheoriePhase transitionGreatest elementSpacetimeNP-hardNetwork topologyDiagramSlide ruleWordRow (database)Morley's categoricity theoremPhysical lawNormal (geometry)Metropolitan area networkBasis <Mathematik>Computer animation
State of matterVirtual machineIntegerPresentation of a groupQuery languageExtension (kinesiology)Installation artBoolean algebraFormal languageShift operatorTensorNumerical digitTable (information)Random numberoutputLimit (category theory)Function (mathematics)DigitizingLengthNumberWave packetParallel portVirtual machineReal numberVolume (thermodynamics)Array data structureRight angleLevel (video gaming)Coefficient of determinationTensorSet (mathematics)WeightGreatest elementWordPoisson-KlammerMachine codeSpeech synthesisIdentifiabilityCausalityDemo (music)Division (mathematics)Line (geometry)Likelihood functionQuicksortPhysical systemComputer fileArtificial neural networkCASE <Informatik>Functional (mathematics)RandomizationPattern recognitionRandom number generationFormal languageGraph coloringTouchscreenTable (information)Function (mathematics)Scripting languageOperator (mathematics)Medical imagingBoolean algebraIntegerPhysical lawDressing (medical)Taylor seriesServer (computing)Presentation of a groupProduct (business)SummierbarkeitReading (process)System callWeb pageSupervised learningNatural numberMultiplication signMultiplicationQuantum stateForestCellular automatonVisualization (computer graphics)Numeral (linguistics)Video gameComputer animation
Function (mathematics)Boolean algebraTensorWeightKey (cryptography)Process (computing)PredictionFormal languageSoftware testingReal numberShift operatorLengthDatabase normalizationTotal S.A.Table (information)Random numberRegulärer Ausdruck <Textverarbeitung>Mathematical analysisAverageClient (computing)Computer hardwareSoftwareMachine learningVirtual machineCalculationSet (mathematics)TensorType theoryVideo gameBitWeightResultantFunctional (mathematics)NumberLibrary (computing)Real numberPhysical systemWave packetClient (computing)PredictabilityRow (database)MathematicsTable (information)Formal languageGreatest elementOpen sourceGraphics processing unit1 (number)Different (Kate Ryan album)QuicksortMatching (graph theory)Random number generationShift operatorAuditory maskingTotal S.A.Computer configurationUniform resource locatorCalculationSoftware testingProcess (computing)Computer fileIntegrated development environmentMechanism designCategory of beingMaxima and minimaCore dumpSimilarity (geometry)SatelliteLevel (video gaming)Goodness of fitSupervised learningServer (computing)Software development kitService (economics)Computer clusterExpressionDigitizingMultilaterationCASE <Informatik>Computer animation
Pattern recognitionComputer chessComputer-generated imageryAttribute grammarAddress spaceDistanceVirtual machineWeightDatabase transactionValidity (statistics)Integrated development environmentMachine learningDatabaseGroup actionConcurrency (computer science)BackupElectric currentType theoryComplex (psychology)Subject indexingVirtual machineResultantReal numberPredictabilityCASE <Informatik>Computer chessDatabase transactionDemosceneTerm (mathematics)1 (number)Figurate numberMusical ensembleWave packetMedical imagingExpert systemMereologyDatabaseDistanceForcing (mathematics)Physical systemMagnetic stripe cardCellular automatonSquare numberNumberLimit (category theory)Computing platformField (computer science)QuicksortWeightComputer programmingAttribute grammarMultiplication signRight angleDecision theoryNeuroinformatikMachine learningProcess (computing)MeasurementSlide ruleGreatest elementBackupWebsiteRepresentation (politics)Demo (music)Validity (statistics)Shared memoryStress (mechanics)HypermediaAngleCondition numberVideoconferencingSoftwareGrass (card game)SmartphoneCartesian coordinate systemConnectivity (graph theory)Group actionPersonal identification numberDot productTask (computing)Address spaceData centerDeep Blue (chess computer)Existential quantificationPattern recognitionHand fanComputer animation
Element (mathematics)Computer animation
Transcript: English(auto-generated)
Hello, everyone. It's a pleasure to be with you today to talk about artificial intelligence. This is a topic that I've been wanting to explore for a while. And fortunately, during the COVID period,
I've had a chance to sort of dive into it and I'm going to share what I've learned in the next 40 to 45 minutes. My name is Bruce Momjian. I am one of the Postgres core team members and also an employee of EnterpriseDB for the past 14 years. This presentation along with dozens of others
is available at this URL right here. So if you'd like to download this presentation, feel free to go to that URL and you will find this presentation there along with many others and recordings of many presentations. So what are we going to talk about today?
We are going to talk about artificial intelligence. This is a very obviously popular topic. A lot of sort of discussion around it. Seems to be a hot area of discussion and research. And I'm going to cover today specifically
what artificial intelligence is. We'll have a little philosophical bend there. And then we're going to dive right into machine learning and deep learning. There's a lot of talks about artificial intelligence, but my goal for this talk was to really break it down and treat exactly what artificial intelligence is.
How does it operate? How does it kind of work? How do you set it up in a very rudimentary way? This is not really a talk of how to sort of develop an AI application. This is more of a foundational topic of sort of what is it and how does it use data? How does it sort of work from a sort of
specific standpoint? Item three, we're going to show you a demonstration of using artificial intelligence with my fate of a database Postgres, of course. And item number four, we're going to talk about the hardware and software efficiency, particularly how to use different software libraries
in general. We'll talk a little bit about tasks that AI is very popular with right now, and then sort of close out about why to use a database. So what is artificial intelligence? This is a quote that I kind of pulled out of Wikipedia. Most of the slides actually have URLs at the bottom.
So if you see blue at the bottom, probably the easiest thing is to download the slide deck and just click on the PDF URL there, and it'll take you right to the page. So again, if you need more information on almost all the slides, they almost, many of them have a URL at the bottom where you can kind of go to get more information.
So the definition that I thought was the best was machines that mimic cognitive functions that humans associate with the human mind, such as learning and problem solving. And that's kind of an interesting point. Mimic cognitive functions. Is it cognitive functions? Is it not cognitive functions?
The jury's still out kind of on that one, but there is sort of an unusual philosophical impact to how you answer that question. And this is, again, a quote that, not a quote, but a sort of phrase that sort of encapsulates the article
that you see there at the bottom from the Atlantic. And the basic concept is that if artificial intelligence is the same as human intelligence, you're basically saying that if the physical world exists, only the physical world exists, only things we can see and touch,
then human intelligence must therefore be a physical process. And it only differs from machine learning, machine intelligence, because it's not naturally developed. So it's more of a source of where it comes from not actually the nature of what it is. It hence differs only in how it's created. And the corollary to that is that human free will
is basically an illusion because it's merely physical processes in your mind and other people's minds that cause these thoughts and feelings and values and so forth. I'm not gonna go any farther than that, but it's kind of an interesting thought about artificial intelligence and how we see it.
Is it mimicking human intelligence or is it really the same thing just created in a different way? And we'll leave it there. There is a long history of artificial intelligence. I used to, I remember I used to have a friend
who worked on fusion energy in the 70s. And they said, I said, when do you think it'll be done? And they said, oh, it's like 10 years away. Well, artificial intelligence is this thing that's always 10 years away, historically in the computer field. There's a pre-computer philosophy about artificial intelligence. Then there was a period where robotics was very important,
where human motion was considered to be sort of the primary focus of artificial intelligence and the Turing test, which had its own sort of cognitive filter that you would go through. The 80s was a big period for expert systems where you took people's experience or experts experience
and you fed that into a computer to create like a decision tree. And then there was a period in the 90s and later called AI winter, where there was a lot of disillusionment over expert systems. Robotics was really not considered to be artificial intelligence in the same way
that people thought of it at that point. And now we're seeing obviously resurgence and we'll be talking about why that is in some of the specific cases that our computers are being used for artificial intelligence going forward. This slide is kind of interesting, obviously the beautiful colors,
but it's interesting because it's trying to sort of show you the layers of artificial intelligence. So there is this large field that is considered to be artificial intelligence. That field obviously goes back to robotics and expert systems
and all the other stuff that went before. And then inside the artificial intelligence is a sub topic called machine learning. And I'm gonna show you specifically what machine learning looks like and how we can create a rudimentary machine learning sort of system as part of this demo. And then finally inside that machine learning
is a smaller subset called deep learning, which is a subset again of machine learning. I'll show you what that actually looks like. If you want more information, there is a three hour video link at the bottom of this slide. And that video is by an MIT professor and he goes into a great amount of detail
of walking you through various machine learning and deep learning kind of problems. So if you really wanna deep dive in this, that video I do recommend as sort of a very good primer on exactly what's going on with machine learning today.
So this is sort of our first slide related machine learning. Further slides are gonna build on this, but I need to highlight a few concepts here. And again, the pattern is the same. We have three basically tensors, the pink little rectangles,
the three sort of piece rectangle is something called a tensor. And the first tensor you see up at the top is what we call the initial state of the tensor. Tensor is a technical term that used for machine learning.
Tensor is kind of the same thing as a vector in mathematics, but it has sort of an unusual mathematical meaning that really doesn't apply here, but that's the term that AI just kind of went with. So that's what we're gonna call it. So that's the tensor in the first state. And you can see it's completely empty.
All of the neurons in this case, the tensor that we're showing right here has three neurons in it, neuron one, neuron two and neuron three. Okay, so this is the whole thing is the tensor and each individual piece is called a neuron. And you can see that the neurons are blank, they're empty
because the initial state of the machine learning is that it doesn't know anything or it hasn't learned anything. Technically in AI speak, it hasn't learned anything. Then in the middle of this slide, you can see the tensor state while it's consuming 10 training data.
And as it's consuming training data, it's actually changing the weight of the three tensors. That's why I have sort of a slash because these values are going up and down as the data is being fed into the various neurons, which are part of the tensor.
And when we get to the demo, I'll actually show you some tensors and some neurons and you can kind of see the weights physically as numbers. But right now we're just gonna do it visually. Once you're done with the training data and you set the weight of your tensors, I'm sorry, the weight of your neurons,
then you get to your live usage. And that is where you feed requests into the tensor. The individual neurons make measurements of the request coming in, apply the weights to it, and then out of it comes a result.
So this is the simplest case of sort of machine learning where we have the initial state. We have a training phase where the neuron weights are set. And then finally we have a request at the bottom where we're sending requests in and we're using the weights that we set in the neurons
to generate AI based results. So there are actually three types of machine learning and I'm gonna visually show them to you as part of this slide. First, we have the unsupervised machine learning.
Now, you don't see this too much, but it has some usefulness and it's probably the simplest case where we've got an initial state, which again is blank, and we feed the training data in, but we have actually no results associated with it. We just have training data going in and weights being set,
but they're not the key to any sort of result value. They're just data. And then we have requests coming in and then a result comes out. You don't see this used too much because it's hard to map it to an actual problem space. The only one I remember seeing somebody explained
is that you wanted, if you had images of cats and dogs, you would somehow feed the data in without telling it whether it's a cat or a dog and the system would kind of identify there's two groups and that's one group, but I don't know what it is and that's another group, but I don't know what it is.
So that's the most common unsupervised learning I've seen. Not used a whole lot because it's a little harder to, but it's good for categorization, I would say, where you don't wanna sort of spend a lot of time setting up your training data. The supervised state is obviously much more common. In this state, again, the initial state's the same,
but in the intermediate during the training phase, we actually have results. So there are results that are being sent into with the training data. So you've got some data and then a result that is associated with that particular data set that each record, let's say, you send something in
and this is actually the correct output to go to that data. Here's another piece of data. Here's the correct output goes with that data. As you can imagine, it's a lot easier to kind of come up with useful cases for this and then obviously when you actually are using it live, you have a better model of weights
and they're kind of easier to get a result to come out. And I'll show you example of this when I show you the demo. The third method is also very popular, very complicated actually. And this is what we call
reinforcement machine learning. It's the same as supervised machine learning, except you'll notice that there is this arrow from the result coming back into one of the neurons or multiple neurons probably,
back into the tensor basically. And in this case, what you're doing is that you're running it just like supervised learning, but you have some type of mechanism so that when the results are coming out and the system has perhaps guessed incorrectly,
you can feed that back into the neurons to improve the weights of the neurons. So this is like supervised learning, except it has a feedback loop associated with it
where you're using the results to improve the future predictability or the future probability that the AI will get it correct. And you can imagine this gets kind of complicated. How much do you have the results feedback? Do they overwhelm what's there before?
And there's a whole bunch of research about how much results should feedback and so forth. But we're not gonna get into that, just the concept of reinforcement makes sense. This is sort of like when you're getting, there's maybe a recommendation engine and it's using some kind of AI.
If it recommends something and you choose, you don't like it, that is some information it could use to try and do better in predicting future videos or books or whatever. So that would be an example of reinforcement learning. Now, I promise to talk about deep learning
and deep learning is really just machine learning taken to another level. So with machine learning, we really had one stage of tensors. And we fed our data in, we had one set of neurons. There may have been millions of neurons, but only one stage of the machine.
And then you had a result coming out. What you have with deep learning is a case where you have multiple machine learning neurons stacked in stages. So you go into the first stage of your tensor,
all the neurons are then basically going through their weights. There's an output that comes out. And then as you can see in this diagram, every single neuron feeds to all of the neurons in the next stage. So if I have three neurons in the first stage and three neurons in the second stage,
I effectively have nine transfers of data because each of the first neuron goes to the second three, the second neuron goes to the second three, the third neuron goes to the second three. And again, then in the second stage, this happens again and the third stage and so forth and then finally you get a result.
Now, this is obviously a very simplistic case. In normal cases, you may have a thousand stages, okay? And you may have thousands of neurons or millions of neurons, right? So you can imagine this gets really computationally expensive,
which is why you see a lot of GPU usage. I'll talk about that later, but see a lot of GPU usage with artificial intelligence because you have, if you're using deep learning, you've got not only the neurons, which may be in the thousands, but then you've got perhaps millions but then you've got maybe hundreds of thousands of stages
that they all have to go through. So you've got a lot of parallel work that needs to go on and this is a good example why a GPU would be good. Again, there's a URL there at the bottom to give you a better idea of kind of what's going on there. So you see deep learning a lot for things that would happen in stages. For example, if you're analyzing an image,
you might have one stage that separates the foreground from the background. And another one that maybe works on the colors and another one that works on the face or looks for a tail or something in an image case
or in vocal AI where it's having to recognize speech you can have one set, one machine learning stage that deals with pitch and volume of the speaker. And another one that tries to identify words
within the speech and another one that kind of acts on the words so you can kind of see why you would have to go through stages to get through a case where you're doing voice recognition. So again, some systems lend themselves to deep learning.
Some of them don't, but again, they can be really very computationally expensive. It's kind of an interesting sort of enhancement of the basic machine learning concept that allows you to tackle much harder problems. So I promised to give you a demo and I am not gonna disappoint.
Here is a demo using Postgres with artificial intelligence. Now, I don't suspect anyone would actually use what I'm doing in production, but I do think that this is gonna give you a good visual of exactly what is going on, what do these weights look like? How would you kind of code it up?
And I picked a really simple problem. I didn't pick identify dogs against the background or voice recognition or anything like that. I just picked a very simple numeric problem. Does an integer value have any non-leading zeros?
Okay, again, you would never do AI for this, but the reason I've given it to you is so that we can see really clearly what's going on. So for example, in the first bullet there, 31903 has a zero in it. In this case, the fifth digit
or the second digit from the right is zero. In the second bullet, the 82392 does not have a zero, okay? And we're gonna use AI to predict given an integer, does it have a zero in it, okay?
So we're kind of thinking about like, okay, how are we gonna do that? Like what would our neurons look like, okay? So to kind of set myself up, I realized that I was gonna be doing some array operations. So I picked something that was very concise,
very easy to understand. I picked a server-side language called PL Perl. Again, very unlikely you would use this particular example, but I think it's illustrative of what we're going to be, of what actually happens in AI. And again, if you wanna follow along, that URL there in blue is actually the script that I used for this presentation.
So if you download that SQL file and just run it through PSQL, you'll actually see the entire demo on your screen and you can play with it, which is kind of interesting. So how am I gonna do this? So what I need to do is I need to generate a tensor. So I'm gonna create a PL Perl function here
called generateTensor. And the tensor is gonna have 11 neurons, okay? So the first neuron, first 10 neurons, indicate how many digits does this number have?
Cause the more digits a number has, the more likely it is that it's going to have a zero in it, right? Cause if it's only two or three digits, it may not have a zero, but if it has like nine digits, well, that's probably maybe more likely there's gonna be a zero in there. So what this actually does is use Perl here
to identify, does this have, you know, X or more digits? So does it have a 10 or more? Does it have three or more or whatever? And based on how many digits it has,
we can then predict the likelihood of the zero being in there, okay? And then the final one is kind of a throwaway one, real easy, is the number divisible by 10? Cause if the number is divisible by 10, we know the last is zero, the right most is zero. So that's sort of an easy one for us, okay?
And then we're gonna map that to true and false, or we're gonna create a Boolean array. If you're not familiar with arrays in Postgres or Boolean, you can look it up, okay? This is basically gonna generate a tensor for us for a given value, okay? Now we have to create a training set, right? Remember that was the, we created our tensors,
there's 11 of them. I'm sorry, we created a neuron which had 11, I'm sorry, create a tensor that had 11 neurons in it, right? Now we need to create our training data. So what I did here is I created a table called training set. It has a Boolean output and it has a tensor array.
That's what the brackets mean. Boolean bracket is a Boolean array. And then I decided to take 10,000 integers, okay? And they're not actually random numbers, they're actually numbers with a random number of digits. It's not quite the same. Cause if you just choose random numbers, you're gonna get a lot of really long numbers.
This gives you a lot of short numbers and long numbers to kind of together. It makes it a little more interesting, okay? And I'm gonna convert that. I'm gonna insert the data into the training set. So I'm now created, you know, effectively 10,000 training data that I have. And this is a supervised learning because in fact,
what we're doing right here on this line is we're saying, is there a zero in that number, right? So we generated these 10,000 numbers. And for each number, we're gonna say, is there a zero there, a non-leading zero? And if there's a non-leading zero, it's true. If there's not a non-leading zero, there's false, okay? Again, you would never do this in real life,
but I think it's gonna be illustrative. Okay, let's look at our training set. What do we see? We see a bunch of numbers there on the left. Some of them long, some of them short. That's what we wanted. We wanted a variable length there.
Then in the second column, we identify whether that number has a zero in it or not. If it's true, there's a zero there. If there's not, there's a false there, okay? And if you verify, you can see the long numbers, or some of them are false, some of them are true. Some of the short numbers are false,
some of the short numbers are true. And then over here on the right, we have the neurons and the tensors, and the 11 neurons for every tensor. So there's 11 true or false there. And again, those tensors match the numbers, depending on how many digits it has. If it has a lot of digits, it has more falses.
If it's a shorter number, it's more trues or something like that. So again, the number of trues and falses in the first 10 indicates how long it is. The last one indicates whether it's a zero at the end, in this case. In this particular set of 10, we don't have any, but you get the idea.
So what else do we need to do? As I told you before, we need to feed the training data in, and we need to set the weights for the neurons, right? Remember that. So what I've actually done here is I've created a function called generate weight, which effect, this is a multi-page function.
These are the variable definitions. This is the body of the function. And what the body of the function does is to take the data you fed in, run through all the rows, and for each neuron in the row of tensors, we're gonna spin through, we're gonna set the weight of how important
that particular neuron is to the result. This is kind of the crux of what's going on in AI. We're actually using the training data with supervised learning, because we know whether it has a zero or not, okay? And we're setting the weights of the neurons
based on how predictive that particular neuron is to producing a result that we want, or a result that we don't want, okay? Some neurons may be very unpredicted, some neurons may be very predictive. You don't know, but that's what the training data is for.
You set up the mechanism, you don't have to worry which neurons are useful. If a neuron is not useful, it won't affect the results. Important neurons will affect the results. That's one of the beauties of AI, and I'll talk about that later when I give the example of fraud detection, which is kind of interesting. We'll talk about that at the end.
This is the rest of it, which basically sets the neuron weights and so forth for the tensors. Again, this is all in the SQL file you can download. Then we have a tensor mask, which has to identify whether the weights should apply to this particular real result data that comes in,
and we'll return the weights where our neuron value matches the desired, if it doesn't match your desired output, we don't care about it, okay? And then we have some internal work. We have to sum the weights. We have to do something called softmax, so that all the weights add up to 100% or one, technically.
So you're looking at weights that have all sorts of different different values. You want the total to be 100% or one so that they're all kind of relative to each other, how important are they? It doesn't matter what the actual weight is.
It's how important is that weight to all the other weights that exist in the system in that particular tensor, and that's what we do here. And then we basically create a table called tensor weights true and tensor weights false, where we're kind of loading the trues and the falses and setting the weights, okay?
And then we actually get some results out from the training data. So these are the actual weights that each of the neurons have gotten within the true tensor and the false tensor. You see they're kind of different, but you have different weights depending on whether you're trying to predict true or false.
Now we're gonna run actual examples. So we've done, we've set up our neurons, we've run through the training data, we've set our weights. Now what we're gonna do is we're going to test the numbers, so I'm gonna send 100 in, and you wanna run it through some weight
and softmax and tensor mask and so forth. And what we end up with is something kind of lackluster. It predicts 22% chance it has a zero in there. Well, it obviously does have a zero in there, so it's pretty wrong. This is not a great example,
just because it is, that's AI, some examples aren't right. Now, if I go to 101, notice when I have 100, 22% that there's a zero in there. When I do 101, it drops to 11%. Why is that? That's because that last neuron
was recording whether this was divisible by 10. Now we know as people that it's divisible by 10, there's a zero there, but system doesn't know that. It has to look at the training data and how predictive was that particular neuron compared to all the other neurons in predicting a zero.
So you can see a small change between 100 and 101 in the sense that this last neuron was true in 100 and false in 101, a small example there. Then we pick a big number. This one also is wrong. It says there's a 68% chance down here
that there's a zero in there. In fact, there's no zero in there at all. Okay, it is what it is. Now we're gonna test 1,000 values. So I'm gonna generate 1,000 values again, a random number of digits, and I'm gonna run it through a common table expression, basically doing the softmax and set the weights for that.
And then I'm gonna analyze it to predict how accurate it was. And I'm gonna end up with this result, okay? Now you can see here in black, a whole bunch of the last couple of rows that we came through, six, this number, this number, and again, predictions of how likely that was
to have a zero or not, and then how accurate it was. And what we get here at the bottom is a prediction of how accurate this particular example was, 72% roughly in accuracy. Not too bad, 15% accurate or plus or minus.
I think that would be if you just randomly did it. So again, this is not a super useful example, but the beauty of it is you can kind of see how all those things kind of came together, the creation of the neurons, the training set, the setting of the weights,
and then kind of coming to a result that's not fantastic, but it's certainly better than random chance. So let's shift gears a little bit and let's get more specific about exactly how this is used in practice.
Again, as I said before, nobody really would be doing what I'm doing. That's, what I'm doing was a great illustrative example, but not something you'd need in real life. In most cases, you're going to use some type of client or server-side library to do artificial intelligence. Now, there are a number of popular ones,
Madlib and MATLAB, which are not the same, are very possible, popular. You've certainly heard of TensorFlow. Weka and scikit, as I remember, are open source. I think also Madlib is, one of them is.
What's interesting is I have two URLs here. One is using scikit at the server-side, which is what I did with PL Perl, except it uses PL Python. That's kind of interesting. And then a client-side example of using scikit as well. So again, you have all these options of what do I want?
Do I want a client-side, do I want server-side? Probably you're going to do it in Python or a scripting language similar. And you see a lot, these are just very, very popular ways of doing AI. Another thing I mentioned earlier is the real benefit of GPUs.
Again, if you're doing particularly deep learning where you've got thousands of tensors that have been feeding another thousands of tensors and maybe going on for hundreds or thousands of stages, the ability to do parallel processing is incredibly useful.
So again, tensors can have millions of neurons, deep learning can have thousands of layers. And because you have to pass each neuron value to all the other ones in the next stage, there's a lot of repetitive calculations. So again, GPUs are very popular in this environment. So let's talk about some specific tasks
that you see with machine learning. These are the common ones I've seen a lot. Chess is one that we used to have when I was a kid, you'd have sort of computers that could play chess. That is an interesting case, but it's a little easier for AI because there's a limited number of squares,
there's a limited number of moves possible. So you can kind of brute force that a little easier. Jeopardy, which was done by IBM's Deep Blue became very popular, although Deep Blue in terms of actual user, real world application has been somewhat of a disappointment.
So that's kind of a cautionary tale. Voice recognition is something you probably, you do on your smartphone all the time. Don't really need to think of it as AI, but it certainly is. Search recommendations certainly have an AI component to it. Video recommendations as well. Image detection, I talked about that.
A lot of AI examples use video image detection. I'm not a big fan of that because it's very hard to see. Images have so many dots. How do you really understand how all those dots are processed? Because it's just sometimes computationally so big, it's hard to really grasp and that's why I used a more simple example.
Weather forecasting, that's a great one where you basically say, okay, we have this weather pattern, these weather conditions. Historically, what has happened when that weather condition has existed, what has happened next? And you feed that data into the computer and then it's like, okay, when 80% of the time when this weather pattern happens,
the result is a new weather pattern and you can kind of see how that would be used in artificial intelligence. Probably the most practical one that I've ever heard is fraud detection, fraud detection for invalid financial transactions. Obviously, there's a great need here
for financial institutions to have this ability. There's a URL there at the bottom by a US bank representative talking about how they use fraud detection. I found it very interesting. What I find really interesting about this particular slide is that if you were given the job of creating an AI machine for fraud detection,
what things would you measure? What would your neurons measure, right? They may measure the charge amount. They may measure whether the transaction was with a magnetic stripe or a chip or a pin or an online charge. It may measure the vendor distance
between the charging, the charges billing address and the vendor. It may be the distance from the last chargee transaction. It may be the country of the vendor. It may be the previous charges to this vendor from the chargee. It may be previous fraud charges from the vendor. Who knows, right?
Like these are all, they all look reasonable to figure out fraud, but which ones are more important? What would the weights be, right? And the beauty of AI is, you may go to an expert and ask the expert, how important are all these things?
Which is this twice as important as that one? Is this one not that important? And the expert may be able to give you rough numbers there, okay? But the beauty of AI is you don't have to do that. You can basically for fraud detection, choose your attributes that may be the ones I mentioned or some other ones.
You would create a machine learning neurons for each attribute, a way of measuring each one. Then you create some training data from the previous fraudulent and non-fraudulent transactions. And you'd have attributes that match the neurons, okay? And whether that transaction was valoring or fraudulent.
So you would probably feed in a whole bunch of valid transactions and a whole bunch of fraudulent transactions. Again, this is supervised learning. You're giving the results to the AI system so it can figure out how important those neurons are for detecting whether something's a fraud or not.
Then you feed the data, training data into the machine to set the weights and based on how much weights are and predicts the validity of the fraudulent transaction. Then you start feeding real data in and you get your results. And then if you're doing reinforcement machine learning, you correct, in incorrect cases,
you're now feeding some of your result data back into the machine learning to improve its predictability. So the beauty of that is you don't have to sort of get an expert, figure out exactly what is most important. You can kind of come from a distance and say, here are some things I think might are important.
Let me feed a whole bunch of data in, let the computer figure out how important each of those are. And then again, feed your real data in to get results and use the results that come back when it's incorrect to reinforce, whether it's correct actually, to reinforce those weights or make adjustments over time.
So finally, we talked about machine learning, deep learning, I showed you a PL-perl example. We talked about fraud detection and all these other things. I think one of the sort of questions in my mind is why would you use a database here?
Like what value does a database bring here? A lot of machine learning is currently done on custom platforms. It's sort of this thing that's sitting on the side of your data center because the technology is still changing and people are installing new software and there's a whole bunch of churn going on in a lot of ways.
But ultimately, once the field kind of settles, you see us a lot in the database industry where something's external and eventually as it's settled, it becomes part of the database itself. Machine learning needs a lot of data. And most of your data is already in your database,
particularly for something like fraudulent transactions. Your data's already there, why would you be downloading it to another system and then bringing it back again? If you can do it in the database itself and particularly, why do that? The advantages of doing the machine learning
in the database are several of them. Certainly you have previous activity as training data is all there. You have seamless access to that data because it's all kind of relationally set up. You can do things very creatively. For example, you could actually check a transaction
for validity before you commit it. You can say, I'm about to commit this transaction. Let me go run it through the AI engine in the same database and see what the result is. If the result says it has a high probability of being fraudulent, maybe I don't wanna commit that transaction.
That's kind of interesting. Of course, when AI is part of your system, it can benefit from database transactions, concurrency, backups, things like that. And there's a huge amount of data types, particularly in Postgres where you have complex data types, full-text search, GIS. GIS is a great example.
Having GIS ability to know how far something is or where something is on the globe is really, it can be really useful. And of course, Postgres can do GPU things as well. So I wanna thank you for being, for listening today. I've left, I'm leaving you with an image, a real image from Phoenix, Arizona.
You can wonder why I chose that image, but I think there's some interesting sort of AI angles to that picture. So I hope you've learned a lot. Again, the slides are available on my website. If you'd like to download them or even download the SQL and run the demo yourself. I've enjoyed speaking to you today
and I'm looking forward to a really good conference. So thank you.