Artificial intelligence (AI) and machine learning (ML) are two fields that work together to create computer systems capable of perception, recognition, decision-making, and translation. Separately, AI is the ability for a computer system to mimic human intelligence through math and logic, and ML builds off AI by developing methods that "learn" through experience and do not require instruction. In the AI/ML Zone, you'll find resources ranging from tutorials to use cases that will help you navigate this rapidly growing field.
I've just released a new version of Aista Magic Cloud that allows you to use natural language to create Hyperlambda backend code, and its accuracy is at 90% after only two days of experimenting with the thing. To appreciate this feat, I suggest you watch the following YouTube video. The way it works is that you start out with a base model. I found Curie to give me the best result. Then you supply OpenAI's API with a bunch of questions and answers. This is the most critical part since the better your questions and answers are, the better your end result will become. I found that extrapolating my questions with variables allowed the model to be able to recognize variables, and substitute these, composing larger blocks of code from smaller blocks more naturally. An example of the above could be, for instance, the following questions, with code snippets solving your questions. Insert company_name and org_no into my customers table in my crm database Insert first_name and last_name into my contacts table in my customers database Insert description into status table in my cms database Etc ... The above might seem ridiculous for a human being, but by extrapolating similar questions such as the above, OpenAI is able to identify variables that it later can find in your natural text as you ask it to solve specific problems. You can even automate the creation of such learning entities by using scripts. I have even seen people using OpenAI and ChatGPT itself to create training material for OpenAI and ChatGPT. Below is an example of a sentence I asked it after training it. Create a Hyperlambda endpoint that inserts name, address and zip into my customers table in my crm database For the above sentence, it produced the following result: Plain Text .arguments name:string address:string city:string country:string data.connect:magic data.create table:customers values name:x:@.arguments/*/name address:x:@.arguments/*/address city:x:@.arguments/*/city country:x:@.arguments/*/country response.status.set:201 return result:Insert was a success The above code is 90% correct. If I had done a better job extrapolating my training data, it would probably perform 100% accurately. Notice how it inserts city and country instead of zip code. Code Is a Classification Problem Another thing I realized after playing around with my training material is that code is a classification problem — at least, this is true for Hyperlambda and OpenAI. This allowed me to use less resource-intensive engines that are less expensive and faster. For instance, I used Curie with a lot of success, which is smaller, less expensive, and faster than DaVinci. This allowed me to submit my training data to OpenAI for roughly $1 and ask questions for roughly 0.3 cents. I tried using Ada, but she failed miserably. I never tried Babbage, though, which might have worked, and is even less expensive than Curie. However, the point is that there are a finite amount of correct solutions within a programming language for a specific problem. For Hyperlambda, this is especially true since it's a super high-level programming level, more like a "5th generation programming language" intended to orchestrate data and not for algorithm-intensive tasks. This allowed me to use classification logic as I trained my model, which of course, produces much more accurate results. Another thing I noticed was that by providing multiple questions to the same snippet of code, I was able to drastically increase the quality, which again is because that code is a classification problem. I had, in total, 691 training snippets; however, there were probably only some 250 different code snippets, implying the same code snippet was reused multiple times for different questions. One thing I intend to change in future versions is to extrapolate much more, allowing Curie to recognize variables more easily in my natural text. Currently, I've got roughly 90% correctly working code. However, due to Hyperlambda's simple syntax, I am certain that I can bring these numbers easily up to 99% accuracy with less than 1,000 training snippets. All in all, the entire process of implementing this into Magic took me two days, with a couple of days thinking about the problems first. If you want to play around with the thing, you can register for a free 90 days cloudlet below and create your own OpenAI API key.
Correctly evaluating model performance is a crucial task while working with machine learning. There are quite a few metrics that we may use to do so. That can be problematic for someone who just started the journey in this field — at least, it was for me. I will start with describing concepts like true/false negatives/positives as they are the base for more complex metrics. Then I will mention and explain metrics like accuracy, precision, recall, or calibration error. I will also explain the basics behind the confusion matrix and a short code snippet on how to build one. Why? Finding resources online and reading them is simple. Everyone can do it, and I did it as well, but I missed an all-in-one glossary for all the stuff. This is my main motivation behind writing this text. First, I will describe all the metrics I came into contact with while working on my previous project. I think that such a metrics glossary will be useful for all the people new to working with machine learning models. Metrics Let's start with true positives and other positive/negative combinations. I will make it in tabular form for easier reading. True/False Positive/Negative Confusion Matrix Less commonly known as Error Matrix, it is a basic visual representation of our model performance. The concept takes its name from the fact that it makes it easy to see whether the system is confusing two or more classes. Moreover, in the case of multiclass, we can easily nothing w a pair of classes is the hardest for the model to differentiate. In most cases, it represents the instances of an actual class in rows while representing the instances of a predicted class in columns. However, there can also be reversed representation when columns are labels and rows are predictions, but it is less frequent. Accuracy It is the basic metric when it comes to model performance. It describes how often our model makes correct predictions — usually, the measurement is expressed in percentage. The problem with accuracy is that it is a very poor metric and is easy to play with. The most notable one is that we can fairly easily achieve high accuracy in quite complex tasks. For example, in the case of anti-money laundering, you can always just return zero — meaning that this person is not laundering money — and for sure, you will achieve accuracy higher than 95 %. As most people are not actually trying to do any money laundering stuff. The question is: does such high accuracy mean that your model is good or that you will need some other metric to verify your model performance? The answer I leave up to you. Furthermore, it is easy to overfit the model when one bases only on accuracy. We may make too many assumptions in our code that apply only to our test set and may not generalize at all. Another problem is that when we incorrectly prepare a test set. It will be too similar to the train set, or part of the test set will be included in the train set. We can once again end up with a quite high accuracy but a poor generalizing model. As for equations for accuracy — we can express them in terms of true positives and true negatives. Thus it can be viewed as a ratio of correct predictions compared to the whole population. TP + TN — Correct predictions P + N — The whole population Precision Checks how many positives were, in fact, identified correctly. Represent the ratio of correctly predicted positive classes to all items predicted as positives. This can be viewed as a ratio of TP to the sum of TP and FP. High precision means that we can easily identify positives. Furthermore, precision helps us to visualize the reliability of the machine learning model in classifying positive classes. TP + FP — Total number of classified positives Recall Less commonly known as sensitivity. It tries to answer the question of what number of actual positives was identified correctly. Represents the ratio of correctly predicted positive classes to all items that are actually positive. Thus it can be expressed as a ratio of TP compared to the sum of TP and FN. High recall means that we are able to correctly identify most of the positives. While low recall means that model is misidentifying positive values. TP + FN — All positive samples Precision and Recall Problem To fully evaluate the model performance, we need to know both metrics. However, the relationship between them is quite complex. Usually, actions that increase precision results in a decrease in the recall, and vice versa; actions that increase recall result in a decrease in precision. Therefore, you have to carefully balance and pick which metric is the most important for your model use case. Confidence Score A number from 0 to 1 (0 to 100 if one is using percentage notation) is used to express how sure our model is of its predictions. In general, the higher the confidence score, the better. A confidence score below 0,5 (50) may indicate random or semi-random predictions. While evaluating accuracy results for the model, you should also take the Confidence Score into consideration. There is no reason why you should need a model with high accuracy but low confidence. Effectively a model totally uncertain of its predictions. We should aim to express the accuracy of our model within a certain confidence score. ROC and AUC Score ROC is an abbreviation for Receiver Operating Characteristic Curve. It is the graphical representation of binary classification prediction ability. Describes the relation between Recall (or true positive rate) and false positive rate (FPR) at various threshold settings. AUC is an abbreviation for Area Under Curve. While AUROC is the abbreviation for Area Under Receiver Operating Characteristic Curve. It is a number from zero to one, which describes the part of the plot located below the ROC curve. It can be used to describe how well our model can distinguish positive samples from negative samples. Depending on the value of AUC, your model will behave differently. For AUC value equal to: 1 — model will correctly predict all the labels. From 0.5 to 1, the higher the AUC, the higher the chance our model will predict results correctly. 0.5 — model is not able to distinguish positives from negatives. 0 — model will incorrectly predict all the labels (it will classify all positives as negatives and vice versa). IUO Intersection over the union in longer form or Jaccard Index. It is a metric for describing the similarities between the two data sets, with a range from 0 to 1 (or 0 to 100 or with percentage notation). The higher the value, the more similar the two populations are. For IOU equal to: 1 — Sets that share all members. 0.5 — Sets share half of the members. 0 — Sets share no members. This metric is heavily used in object detection and segmentation to calculate the degree of overlap between segments. Although it's easy to interpret, it is extremely sensitive to small sample sizes and may give erroneous results, especially with very small samples or data sets with missing observations. It can be expressed via the following equation: Jaccard Index = (the number in both sets) / (the number in either set) * 100 In more mathematical notation: Here you can also see why it is called the intersection over the union, as the first operation is called an intersection, while the second is called a union. Calibration Error It describes how well the predicted output probabilities of the model match the actual probabilities of the ground truth distribution. The Calibration Error can be used to visualize how far are given model results are from real-life results. F1 score Mixes precision and recall into one metric in a form of their harmonic mean, and it is designed to work better for an imbalanced dataset. It is also the default metric used whenever one needs only one metric to show some results. Both precision and recall are given equal weight, so no one of them has a bigger impact than the other. We can expect that if both are high, then F1 will also be high, similar to low values of precision and recall. However, what is important is that if one is high and the other one is low F1 value will be somewhere between. As usual, the higher the metric value, the better our model performance. Which Metric to Choose? Sooner or later, there begins a problem of which metric to present to stakeholders or on which metric we should focus to make our model better. The answer here is simple — It depends. For sure, you should not base model performance evaluation on accuracy alone and take more metrics into consideration. But, on the other hand, if you have to use only one metric to present some results, the F1 score or AUC are very good picks. As for other metrics, their importance greatly depends on your model's purpose and shortcomings: If you assess that errors caused by FNs are more undesirable, then you should focus on Recall. If you assess that both types of errors are undesirable, then focus on F1. If you want your model to be more certain of its prediction, then you should focus on increasing the Confidence Score and reducing Calibration Error. Additionally, if you want to show or see shortcomings of your model, then you can use Confusion Matrix to easily visualize which classes may be problematic. Conclusion There are many metrics that can be used to verify machine learning model performance, and their usage greatly depends on your model use case. However, remember that you should never base anything on Accuracy only and use other metrics to verify that the model is performing as expected. If you need single metrics to show to your stakeholder, the F1 score can be a good pick. Thank you for your time.
An Introduction to Artificial Intelligence When it comes to artificial intelligence, there are two main ideas on the table. Some believe that artificial intelligence will eventually surpass human intelligence, while others believe that artificial intelligence will always be at the service of humans. However, there is one thing both sides can agree on: it is advancing faster and faster every year. Artificial intelligence (AI) is still in its early stages of development, but it has the potential to revolutionize the way humans interact with technology. A simple, general description would be that AI is a process of programming a computer to make decisions on its own. This can be done in a number of ways, but the most common is through the use of algorithms. Algorithms are a set of rules or instructions that can be followed to solve a problem. In the case of AI, algorithms are used to teach the computer how to make decisions. In the past, artificial intelligence was mainly used for simple tasks such as playing chess or solving mathematical problems. However, artificial intelligence is now being used for more complex tasks, such as facial recognition, natural language processing, and even autonomous driving. As artificial intelligence continues to evolve, there is no telling what it will be capable of in the future. With the rapid expansion of AI capabilities, it is important to understand what it is, how it works, and its potential implications. The benefits of AI are enormous. With the ability to make its own decisions, AI has the potential to improve the efficiency of a myriad of industries and provide opportunities for all types of people. In this article, we will talk about GPT-3. What Is GPT-3 and Where Does It Come From? GPT-3 was created by OpenAI, a pioneering AI research company based in San Francisco. They define their goal as “ensuring that artificial intelligence benefits all of humanity.” Their vision for creating artificial intelligence is clear: a type of AI that is not limited to specialized tasks but performs a wide variety of tasks, just like humans. A few months ago, the company OpenAI released for all users its new language model called GPT-3. GPT-3 stands for Generative Pretrained Transformer 3 and consists of generating text from a premise called a prompt. Simply put, it could be called a high-level “auto-completion.” You can, for example, provide two or three sentences on any given topic, and GPT-3 will do the rest. You can also generate conversations and the answers will be based on the context of the previous questions and answers. It is important to emphasize that each answer offered by GPT-3 is only one possibility, therefore it will not be the only possible answer. In addition, if you test the same premise several times, it may offer a different and even contradictory answer. It is therefore a model that returns answers based on what has been previously said and relates it to everything you know to obtain the possible answer that makes the most sense. That means that it is not obliged to give an answer with real data, something we have to take into account. That doesn’t mean that you can’t provide it with data about some work you have done and talk about it, but it will always be necessary to contrast the information. The better the context, the better the answers you will get, and vice versa. OpenAI’s GPT-3 language model has been previously trained to be what it is. Its training consisted of studying a huge amount of information available on the Internet. GPT-3 was fed with all the public books, the entirety of Wikipedia, and millions of web pages and scientific papers available on the Internet. In short, it has absorbed the most important human knowledge that we have published on the Web during our entire history. After reading and analyzing this information, the language model created connections in a 700 GB model located on 48 GPUs of 16 GB each. Just so we understand the dimension of this, the previous OpenAI model, GPT-2, had a weight of 40 GB and analyzed 45 million web pages. The difference is immense because, while GPT-2 had 1.5 billion parameters, GPT-3 has 175 billion parameters. Shall we do a test? I asked GPT-3 to define itself, and this was the result: How to Use It in Playground To be able to play with GPT-3 and make our tests, the only thing we will have to do is to go to their website, register, and add the typical personal information that we usually use in any registration. In one of the sections, it will ask you what you are going to use this AI for, and for these examples, I have selected the personal use option. I would like to point out that, from my experience, the results have been better in English. That does not mean that in the other languages it works badly; in fact, in Spanish it does it very well, but I prefer the result that it provides us in English, the reason why the tests and results that I will show from now on will be in that language. GPT-3 gives us a free gift when we enter. Once you have registered with your email and phone number, you will have $18 to spend totally free, without the need to enter a payment method. Although it may not seem like much, the truth is that $18 is quite a lot. To give you an idea, I have been testing with the AI for five hours, and I have only spent $1. Later, I will explain the prices so that we understand this better. Once we are inside the website, we will have to go to the Playground section. This is where all the magic is going to happen. Prompt + Submit To begin with, what stands out the most on the web is the big text box. This is where we can start typing our prompt (remember, these are our requests and/or instructions) to the AI. It is as simple as typing something, a question in this case, and hitting the submit button below to have GPT-3 answer us and write what we have asked for. Presets Presets are ready-to-use presets for different tasks. They can be found at the top right of the text box. If we click on a few of them, “more examples” will open a new screen where we will have the whole list available. When a preset is chosen, the content of the text area is updated with default text. The settings in the right sidebar are also updated. For example, if we were to use the “Grammar Correction” preset, we should follow the following structure to get the best result. Models The massive dataset used to train GPT-3 is the main reason why it is so powerful. However, bigger does not always mean better. For those reasons, OpenAI offers four main models. There are others, but they themselves recommend that we use the most updated versions, which we are going to talk about now. The available models are called Davinci, Babbage, Curie, and Ada. Of the four, Davinci is the largest and most capable, as it can perform any task that any other engine can perform. We will give an overview of each model and the types of tasks that might be best suited for each. However, keep in mind that while the smaller engines may not be trained with as much data, they are still general-purpose models and, for certain tasks, are very viable and cheaper. Davinci As mentioned above, it is the most capable model and can do everything that any other model can do, often with fewer instructions. Davinci is able to solve logical problems, determine cause and effect, understand text intent, produce creative content, explain character motives, and handle complex summarization tasks. Curie This model attempts to balance power and speed. It can do anything that Ada or Babbage can do, but it is also capable of handling more complex classification tasks and more nuanced tasks such as summarization, sentiment analysis, chatbot applications, and Q&A. Babbage It is slightly more capable than Ada but not as efficient. It can perform all the same tasks as Ada, but can also handle slightly more complicated classification tasks, and is ideal for semantic search tasks that classify how well documents match a search query. Ada Finally, this is usually the fastest and least expensive model. It is best for less nuanced tasks, e.g., parsing text, reformatting text, and simpler classification tasks. The more context you provide Ada with, the better it will perform. Engine Other parameters that we can adjust to get the best response to our prompt are below the most important. Exactly, the model. Let’s explain some of the ones that seem most interesting. One of the most important settings to control the output of the GPT-3 engine is the Temperature. This setting controls the randomness of the generated text. A value of 0 makes the engine deterministic, meaning that it will always generate the same output for a given text input. A value of 1 makes the engine take the most risks and use a lot of creativity. You probably noticed that, in some of the tests you have been able to run yourself, GPT-3 stops in the middle of a sentence. To control the maximum amount of text we will allow to be generated, you can use the “Maximum length” setting specified in tokens. We will explain what this token thing is later. The “Top P” argument is an alternative way to control the randomness and creativity of the text generated by GPT-3, but in this case in relation to the tokens (words) within the probability range depending on where we place it (0.1 would be 10%). The OpenAI documentation recommends using only one function between Temperature and Top P, so when using one of them, make sure the other is set to 1. On the other hand, we have two parameters to penalize the answers that GPT-3 gives us. One of them is the "frequency penalty," which controls the tendency of the model to repeat predictions. It also reduces the probability of words that have already been generated and depends on how many times a word has already occurred in the prediction. The second penalty is the presence penalty. The presence penalty parameter encourages the model to make novel predictions. The presence penalty reduces the probability of a word if it has already appeared in the predicted text. Unlike the frequency penalty, the presence penalty does not depend on the frequency with which words appear in past predictions. Finally, we have the “Best of” parameter which generates several answers to a query. Playground then selects the best one and sends it to us. GPT-3 itself warns us that this will generate several completions to our prompt, and that may cause us to spend more tokens than we had in mind. Historical To finish this section, the third icon next to the “Submit” button, will show us a history of all our requests to GPT-3. This way, if we do not remember a prompt we used to get a very good response, this makes it much easier. Costs and tokens Once the free $18 is over, GPT-3 provides us with a way to continue using its platform, and it is not any kind of monthly subscription or anything like that. The price is directly related to the use we want to give it. In other words, we will be charged by tokens. It is a term used in artificial intelligence related to the cost of generating outputs. A token can be anything from a letter to a sentence. So it is very difficult to know exactly the price of each use we give to the AI. But given that they are usually cents, we will only have to try it a little, and we will soon see what each thing costs us. Although OpenAI only shows us a dozen examples of GPT-3 usage, we can see the tokens that have been spent on each of them to get a better idea of how it works. These are the versions and their respective prices: To give us an idea of what a certain number of words might cost us or to give us an example of how tokens work, we have the following tool called Tokenizer. It informs us that the GPT family of models processes text using tokens, which are common sequences of characters found in the text. The models understand the statistical relationships between these tokens and are chosen in the production of the next token in a sequence of these. In the end, this is at a very low level, so let’s use your example and see how much that same example would cost us. Conclusion From my point of view, it is a tool that you have to know how to use correctly. As I mentioned, GPT-3 does not have to give you the correct data. That means that if you want to use it to do work, answer certain questions or do homework, for example, you have to give a good context (prompt) to the AI so that the result is really close to what you are looking for. One thing that some people may be concerned about is whether this is going to change education, or if certain jobs that exist today related to writing are going to disappear. In my humble opinion, it’s going to happen. Sooner or later, we will all be replaced by an AI. This example is about an AI related to writing, but they exist for programming, drawing, audio, and so on. On the other hand, it opens up a lot of possibilities for many, many jobs and projects, both personal and professional. For example, have you ever wanted to write a horror story? Well, in the list of examples where we find the grammar checker, we have one specifically for it. With all this, I want to say that we are in an early version of AI, and this world still has a lot to grow and offer, but that does not mean that it is not useful right now. We just have to learn how to use it and train it to give us the best possible response.
Chatbots will be your new best friend. — Christine Crandell (Forbes) I would like to express my gratitude to ChatGPT for collaborating with me on this article. I composed this piece by repeatedly posting questions to ChatGPT and refining the responses. This demonstrates the practical application of the ChatGPT model in real life. It's important to note that to effectively utilize ChatGPT, one must be imaginative when crafting questions and provide thorough descriptions to elicit the desired information. I hope you enjoy reading this piece. Chatbots are increasingly being used in a variety of applications, from customer service to online gaming. However, many chatbots struggle to produce responses that are coherent and natural-sounding, which can make them frustrating to use. The ChatGPT model, developed by OpenAI, aims to change that. What Is the ChatGPT Model? The ChatGPT model is a machine-learning model that is designed to generate human-like text for chatbots and other conversational applications. It is trained on a large human conversation dataset, allowing it to produce coherent and natural-sounding responses. It is the largest and most powerful language model currently available, with billions of parameters and the ability to perform a wide range of language tasks. How Does the ChatGPT Model Work? The ChatGPT model uses a transformer architecture, a type of neural network particularly well-suited to natural language processing tasks. It processes input text one word at a time, using the previous words in the input to predict the next word in the output. This allows it to generate responses that are contextually appropriate and flow smoothly. GPT Chat Model and Its Purpose The GPT chat model is a machine learning model developed by OpenAI that is designed to generate human-like text for chatbots and other conversational applications. It is trained on a large dataset of human conversations and uses this training data to generate coherent and natural-sounding responses. What Are Some Potential Applications of the ChatGPT Model? The GPT chat model can be used in a variety of chatbots and conversational applications, such as customer service chatbots, chatbots for online gaming, and chatbots for social media. It can also be used in language translation and text summarisation applications. GPT-3 (Generative Pre-training Transformer 3) is a state-of-the-art language generation model developed by OpenAI. It can generate human-like text that is coherent and informative, and it has a wide range of potential applications. Some examples of how GPT-3 could be used include: Content creation: GPT-3 can be used to generate articles, blog posts, and other types of written content. It can even be trained to write in a specific style or tone. Natural language processing: GPT-3 can understand and respond to human input in natural language, making it useful for tasks like chatbots, language translation, and summarization. Language translation: GPT-3 can be used to translate text from one language to another, potentially improving the accuracy and fluency of machine translation systems. Text summarization: GPT-3 can be used to generate concise summaries of long articles or documents, making it easier for people to quickly digest large amounts of information. Dialogue generation: GPT-3 can be used to generate realistic and engaging dialogue for virtual assistants, chatbots, and other types of conversational interfaces. Text classification: GPT-3 can be used to classify text into different categories or labels, such as spam or non-spam, positive or negative sentiment, or topic categories like politics or sports. Text generation: GPT-3 can be used to generate text that is similar to a given input, allowing it to be used for tasks like poetry generation, song lyric generation, and story generation. Text completion: GPT-3 can be used to complete incomplete sentences or paragraphs, making it useful for tasks like predictive typing or helping people write emails or other documents more quickly. Sentiment analysis: GPT-3 can be used to analyze the sentiment of text, helping businesses and organizations understand how people feel about their products, services, or brand. Knowledge base construction: GPT-3 can automatically generate knowledge base articles or other types of written content, helping organizations build and maintain large collections of information. Content moderation: GPT-3 can be used to automatically detect and flag inappropriate or offensive content, helping businesses and organizations to maintain safe and welcoming online communities. Customer service chatbots: Chatbots powered by the ChatGPT model could be used to handle customer inquiries and resolve issues, providing a more efficient and personalized service. Online gaming chatbots: Chatbots powered by the ChatGPT model could be used to provide in-game support, or to facilitate communication between players. Social media chatbots: Chatbots powered by the ChatGPT model could be used to facilitate communication and interaction between users on social media platforms. Overall, the potential applications for GPT-3 are varied and wide-ranging, and it has the potential to revolutionize many different industries and fields. To use GPT-3, you will need to sign up for an API key from OpenAI and use one of the available programming languages (such as Python or JavaScript) to send requests to the GPT-3 API and process the responses. You can find more information and documentation on how to use GPT-3 on the OpenAI website. Here is a funny code example that demonstrates how the ChatGPT model could be used to generate humorous responses for a chatbot: In this example, the chatbot uses the ChatGPT model to generate a response to the question: "What is the meaning of life?" The chatbot's response might be something like, "The meaning of life is to laugh as much as possible and to be kind to others." Of course, the exact response will depend on the specific training data and parameters used for the ChatGPT model. The example above is just one possible way to use the ChatGPT model to generate humorous responses for a chatbot. Future Strategies for Chatbots As chatbots become increasingly prevalent, we will likely see several new strategies and approaches emerge for using them effectively. Some potential strategies for the future include: Increased integration with other technologies: Chatbots may be integrated with a wider range of technologies, such as virtual reality and augmented reality, to create more immersive and interactive experiences. Increased use of machine learning and artificial intelligence: Chatbots may use more advanced machine learning and artificial intelligence techniques to improve their performance and capabilities. Greater focus on personalization: Chatbots may be designed to personalize their responses more based on individual user preferences and behaviors. Increased use in a wider range of industries: Chatbots may be used in a wider range of industries, including healthcare, education, and financial services, to improve efficiency and provide more personalized service. Limitations and Challenges of the GPT Chat Model While the GPT chat model has made significant progress in generating human-like text, it is not perfect and can still produce responses that are nonsensical or inappropriate. It may also struggle with tasks that require more complex reasoning or understanding of the real world. In addition, the ChatGPT model requires a large amount of training data and computational resources to produce high-quality results, which can be a challenge for some applications. Conclusion Overall, the ChatGPT model has the potential to greatly improve the capabilities of chatbots and other conversational applications, providing more efficient and personalized communication. However, it is important to be aware of its limitations and challenges and to use it in appropriate contexts. As the ChatGPT model continues to be refined and improved, it will likely become an increasingly important tool for a wide range of applications. As chatbots continue to evolve and improve, they have the potential to greatly improve the way we communicate and interact with technology. The ChatGPT model is just one example of the many innovative approaches that are being developed to enhance chatbot performance and capabilities. Whether you are a developer or just interested in the latest technological trends, it is worth keeping an eye on the exciting developments in the world of chatbots. As we continue to explore the potential of ChatGPT and other language generation tools, it is crucial that we remain authentic and responsible in our use of these tools. This means being transparent about the role they play in the writing process and ensuring that the resulting text is of high quality and accurate. This line highlights the importance of being transparent and responsible when using language generation tools like ChatGPT and emphasizes the need to produce high-quality and accurate text. By being authentic and responsible in your use of these tools, you can help to ensure that the resulting text is useful and valuable to readers. References OpenAI website The OpenAI website is a great resource for learning more about the ChatGPT model and other machine-learning technologies developed by OpenAI. You can find information about the company's research and projects, as well as resources for developers and researchers interested in using and contributing to OpenAI's technologies.
This is an article from DZone's 2022 Enterprise AI Trend Report.For more: Read the Report The Knowledge Graph: What It Is, The Rise, and The Purpose A knowledge graph (KG) is a semantic network of an organization, a topic where the nodes are known as the entities and the edges are the relationships. It is a framework comprising a set of related yet heterogeneous data — like image, sound, text, video, numbers, etc. — that gives a semantic interpretation and lets researchers run complex algorithms on graph data to generate insight. The RDF (Resource Description Framework) triplestore, a graph database, stores the data as a network of objects or RDF triples that segregate the information into subject-predicate-object expressions. A simple example of relations among entities is shared in Figure 1 for ease of understanding. Figure 1: Relational knowledge graph Mathematician Leonhard Euler, the father of graph theory, used graphs to calculate the minimum distance the emperor of Prussia had to travel to visit Königsberg. With the revolution of big data, organizations started looking beyond traditional relational databases like RDBMS. The NoSQL movement lets organizations store both structured and unstructured data in data lakes. Different types of databases, like MongoDB for documents and Neo4j for graph databases, came into existence with capabilities of graph storage and processing. However, they were not free from problems as there was a lack of formal data schemas and consistencies to run the complex analytics models. KGs bridged the gap and instantly became the cynosure of all large organizations. There exists a three-fold goal of KGs. First and foremost, a KG helps users by searching to discover information more quickly and easily. Secondly, a KG provides side and contextual information in developing an intelligent recommendation engine. Finally, it can help answer queries and make predictions through Knowledge Graph Question Answering (KGQA). The key basis for generating the answers from the questions are shared below in Table 1. Description Semantic parsing Parses the natural language question SPARQL is used to search the KG Information retrieval Natural language questions are transformed into structured queries to find possible answers Feature and topic graphs are used to retrieve the best answer Embedding Calculates proximity scores between questions and plausible answers Uses the vector modeling approach Deep learning (DL) DL on NLP is applied, like multi-column convolutional neural networks (MCCNNs), for image analysis Bidirectional long short-term memory (BiLSTM) is used to understand the questions better Table 1: Basis of KGQA Developing the Knowledge Graph Automated knowledge acquisition and semantic mapping are the pillars of developing a KG. The process of ontology engineering for knowledge acquisition starts with ontology learning that aims to automatically learn relevant concepts and establish relations among them. To achieve this, first the corpus is parsed to identify the collocations and, subsequently, it retrieves the semantic graph. Entity enrichment takes place by crawling semantic data and merging new concepts from relevant ontologies. Figure 2: Process of entity enrichment Integrating heterogeneous data from structured sources demands mapping the local schemas to the global schema. Global-as-view (GAV), a mediation-based data integration strategy, is implemented where the global schema acts as a view over source schema to convert the global query into a source-specific query. Detecting the semantic type is the first step for automated semantic mapping, which is followed by inferring the semantic relation. Data are initially modeled using RDF and subsequently RDF Schema (RDFS), and Web Ontology Language (OWL) adds semantics to the schema. Semantic information can also be mapped in a hierarchical way through relational vectors. Graph neural networks (GNNs) — like graph convolutional networks (GCNs) or gated graph neural networks — are used for object detection and image classification of graph data. Enterprise Knowledge Graph Organizations of today’s era are in pursuit of discovering the hidden nuggets of information, so they are interlocking all their siloed data by consolidating, standardizing, and reconciling. Thus, an enterprise knowledge graph provides an explicit representation of knowledge from business data in the graph. An integrated data enterprise possesses the power of the web of knowledge that uncovers critical hidden patterns to monetize their data. Figure 3: Steps to develop an enterprise knowledge graph Real-World Knowledge Graphs We are inundated with data in the present world. KGs give meaning and purpose to connected data with several applications, of which a few are shared below. Financial Services Knowledge Graph KGs have wide applications in financial services, ranging from fraud detection and tax calculations to financial reporting and stock price prediction. Fraud rings comprising a few people collectively committing a fraud can easily be identified by examining the topology of the subgraphs. Figure 4: Fraud detection through a knowledge graph Stock price can be predicted by linking the sentiments associated with the news of the respective company. Hedge funds and banks use KGs for better predictions by mapping their existing models with the alternate data provided by KGs. Medical Science Biomedical concepts and relationships are represented in the form of nodes and edges. By applying KGs, medical imaging analysis can be used for disease classification, disease medication and segmentation, report generation, and image retrieval. Textual medical knowledge (TMK) from the Unified Medical Language System (UMLS) is analyzed to generate key medical insights and personalized patient reports. Real-Time Supply Chain Management Supply chain organizations use KGs to optimize the stock of inventories, replenishment, network and distribution management, and transportation management. The connected supply chain KG takes the inputs from the manufacturing KG of production, including personnel, plus the retail KG, which comprises the real-time and forecasted demand for better prediction and management (Figure 5). Figure 5: Constituent components to develop a supply chain knowledge graph Conclusion A knowledge graph has the power to create a virtual world where all entities are connected with a proven relationship. Sophisticated machine learning algorithms are applied to prune those connections where the probability of a relationship is slim. Thus, proven relationships among all objects in the world can be established through a KG. With all the past and present data, a KG produces deep insights by recognizing the patterns. A KG also helps us predict the future with all the relevant data leading to a phenomenon. The future KGs could be even more powerful with the road ahead shared below: Graph of Things (GoT) – GoT is an innovative project that aims to merge both the high-volume streaming data of the Internet of Things (IoT) and the static data of the past. Quantum AI for KG – Quantum AI can leverage the power of quantum computing for running the GNNs on the KG and can achieve the results beyond the capabilities of traditional computing. A world with all the information connected through a KG would indeed be magnificent if the benefits are harnessed for the welfare of society. AI on top of KG, when used with the right intent, will make the world a better place to live. This is an article from DZone's 2022 Enterprise AI Trend Report.For more: Read the Report
Natural language processing (NLP) has come a long way in recent years, and ChatGPT is playing a major role in its evolution. For those unfamiliar, ChatGPT is a chatbot platform that uses the power of artificial intelligence (AI) and machine learning (ML) to enable natural, human-like conversations with users. With ChatGPT, businesses and organizations can provide quick, accurate, and personalized responses to customer inquiries, improving the overall customer experience and streamlining operations. In this article, we'll explore how ChatGPT is revolutionizing the world of NLP, and how it's being used by businesses and organizations across various industries. We'll also delve into the benefits and limitations of ChatGPT, and discuss its potential impact on the future of NLP. What Is ChatGPT? ChatGPT is a chatbot platform developed by OpenAI, a leading research institute focused on advancing the field of AI. It uses a combination of AI and ML to enable natural, human-like conversations with users, and can be integrated into various messaging platforms such as Slack, Facebook Messenger, and WhatsApp. A key feature of ChatGPT is its ability to understand and respond to context. It can analyze the words and phrases used in a conversation, and use this information to provide relevant and accurate responses. For example, if a customer asks a ChatGPT-powered chatbot about the return policy for a product, the chatbot can understand the context of the conversation and provide the relevant information, rather than simply repeating pre-programmed responses. Here's how ChatGPT is revolutionizing the world of NLP: 1. Improved Customer Service One of the major ways that ChatGPT is revolutionizing the world of NLP is through its ability to improve customer service. With ChatGPT, businesses and organizations can provide quick, accurate, and personalized responses to customer inquiries, which can help to improve the overall customer experience. This is particularly useful for businesses that receive a large volume of customer inquiries, as ChatGPT can help to handle these inquiries more efficiently and effectively. 2. Streamlined Operations In addition to improving customer service, ChatGPT can also help businesses and organizations to streamline their operations. By automating certain tasks and processes, ChatGPT can help to save time and reduce the workload for employees. This can allow businesses to focus on more important tasks, and can also help to improve efficiency and productivity. 3. Enhanced Language Processing Capabilities Another way that ChatGPT is revolutionizing the world of NLP is through its enhanced language processing capabilities. With ChatGPT, businesses and organizations can engage in more complex and nuanced conversations with customers, as the chatbot is able to understand and respond to context. This can help to provide a more personalized and human-like experience for customers, and can also help to improve the accuracy and effectiveness of the chatbot's responses. 4. Increased Scalability Another benefit of ChatGPT is its ability to scale. As a cloud-based platform, ChatGPT can handle a large volume of conversations without experiencing any slowdown. This makes it ideal for businesses and organizations that receive a large volume of customer inquiries, as it can help to ensure that all inquiries are handled quickly and efficiently. Conclusion In conclusion, ChatGPT is revolutionizing the world of natural language processing by enabling businesses and organizations to engage in natural, human-like conversations with customers. With its enhanced language processing capabilities and ability to handle complex and nuanced conversations, ChatGPT is helping to improve customer service, streamline operations, and provide a more personalized and human-like experience for customers. While there are certain limitations to ChatGPT, it can be a powerful tool for businesses and organizations looking to improve their customer interactions and optimize their operations. As the field of NLP continues to evolve, it will be interesting to see how ChatGPT and other AI-powered chatbot platforms continue shaping how we communicate and interact with others.
Aloha guys. We are going on about popular interview questions. Today we will solve a few problems with hashing approach. Our first problem is: Top K Frequent Elements Description Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Solution So, we need to return K top elements. Based on this condition, we understand that we should calculate each element's frequency. But how can we do it? Sure let's create a hash map and calculate each element's frequency. The Key will be the element, and the value will be frequency. Ok, for now, we have elements frequency, but how can we get top K elements? For example, we can create our own max heap and get k elements. If you don't want to write your own heap, you can use Java PriorityQueue. When you create a priority queue, you should pass the comparator - we are going to sort by value. After it, we can poll K elements and add them to the result. Go under the hood: Code Java public int[] topKFrequent(int[] nums, int k) { int[] rez = new int[k]; Map<Integer, Integer> map= new HashMap<>(); for(int n : nums){ map.put(n, map.getOrDefault(n, 0) + 1); } PriorityQueue<Map.Entry<Integer, Integer>> pq = new PriorityQueue<>((a,b) -> a.getValue() - b.getValue()); for(Map.Entry<Integer, Integer> entry : map.entrySet()){ pq.add(entry); if (pq.size() > k){ pq.poll(); } } int i = k; while(!pq.isEmpty()){ rez[--i] = pq.poll().getKey(); } return rez; } Was it clear to you guys? I hope so. Our next problem: Product of Array Except Self Description Given an integer array nums, return an array answer such that answer[I] is equal to the product of all the elements of nums except nums[I]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation. Example 1: Input: nums = [1,2,3,4] Output: [24,12,8,6] Example 2: Input: nums = [-1,1,0,-3,3] Output: [0,0,9,0,0] Solution I like this problem. It changed my mind. I thought we could multiply all elements and then divide the result on the current, but unfortunately, we cannot use the division operation. Let's think. What will we have if we multiply elements step by step from left to right except for self? For example [1,2,3,4]: 0. nums = [1, 2, 3, 4] left = [0, 0, 0, 0] 1. it is obvious that for the first element we set 1 because we don't have items to the left and we do not include self. left = [1, 0, 0, 0] 2. Then for the nex element we get prev element * prev left element i = 1. nums[i-1] * left[i-1]. left = [1, 1, 0, 0] 3. Repeat this action till the end. 4. i = 2. nums[i-1] * left[i-1] = 2 * 1 = 1 left = [1, 1, 2, 0] 5. i = 3 nums[i-1] * left[i-1] = 3 * 2 = 1 left = [1, 1, 2, 6] As a result, we have all left products in the array except for self. With the same algo, let's find all the right products. 0. nums = [1, 2, 3, 4] right = [0, 0, 0, 0] 1. it is obvious that for the last element we set 1 because we don't have items to the right and we do not include self. left = [0, 0, 0, 1] 2. Then for the nex element we get prev element * prev left element i = 1. nums[i-1] * left[i-1]. left = [0, 0, 4, 1] 3. Repeat this action till the end. 4. i = 2. nums[i-1] * left[i-1] = 4 * 3 = 12 left = [1, 12, 4, 1] 5. i = 3 nums[i-1] * left[i-1] = 12 * 2 = 24 left = [24, 12, 4, 1] For now, we have products left except self and right except self. We can multiply them and receive a product of the array except for self. 0. left = [1, 1, 2, 6] right = [24, 12, 4, 1] rez = [0, 0, 0, 0] 1. rez = [1* 24, 1 * 12, 2 * 4, 6 * 1] 2. rez = [24, 12, 8, 6] Wow, wisdom, isn't it? Code Java public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] toRight = new int[n]; int[] toLeft = new int[n]; toRight[0] = 1; toLeft[n-1] = 1; for(int i = 1; i < n; i++){ toRight[i] = nums[i-1] * toRight[i-1]; } for(int i = n-2; i >=0; i--){ toLeft[i] = nums[i+1] * toLeft[i+1]; } for(int i = 0; i < n; i ++){ toRight[i] *= toLeft[i]; } return toRight; } Hey. have you ever tried to solve Sudoku? Our next task will help you to do it. Valid Sudoku Description Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes of the grid must contain The digits 1-9 without repetition. Note: A Sudoku board (partially filled) could be valid but is not necessarily solvable. Only the filled cells need to be validated according to the mentioned rules. Example 1: Input: board = [["5","3",".",".","7",".",".",".","."] ,["6",".",".","1","9","5",".",".","."] ,[".","9","8",".",".",".",".","6","."] ,["8",".",".",".","6",".",".",".","3"] ,["4",".",".","8",".","3",".",".","1"] ,["7",".",".",".","2",".",".",".","6"] ,[".","6",".",".",".",".","2","8","."] ,[".",".",".","4","1","9",".",".","5"] ,[".",".",".",".","8",".",".","7","9"]] Output: true Example 2: Input: board = [["8","3",".",".","7",".",".",".","."] ,["6",".",".","1","9","5",".",".","."] ,[".","9","8",".",".",".",".","6","."] ,["8",".",".",".","6",".",".",".","3"] ,["4",".",".","8",".","3",".",".","1"] ,["7",".",".",".","2",".",".",".","6"] ,[".","6",".",".",".",".","2","8","."] ,[".",".",".","4","1","9",".",".","5"] ,[".",".",".",".","8",".",".","7","9"]] Output: false Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid. Solution Based on the description, we see three main requirements for a valid Sudoku: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Let's try to solve this problem step by step. First of all, let's check the row of the Sudoku. We can create a Map or an array, or a Set from 1 to 10 and fill needed cells. If we see this element twice, we will return false — our Sudoku is invalid. The same approach we will use for columns. Just check column values. But how can we handle squares? Looks like we have a matrix 9x9. We have nine elements in a row, nine elements in a column, and nine squares. The main problem here is to correctly determine square elements. We must find the start/end column and the start/end row. For the column, the best idea will be to get a square number (For example, 3), then multiply it by three elements in a row and then divide it by square elements count (9). int startRow = (square * 3) % 9 = 3 * 3 % 9 = 1; With the end row, all will be easier. We just need to add three lines =) Now, let's figure out how to calculate the start column. For square 0, it should be 0. For square 1, it also should be 0. But for square 3, it should be 3, right? Looks like we need to get a square number, divide it by 3 (because we have three columns in a square) and then multiply it by three. For square 0: 0 / 3 * 3 = 0; For square 1: 1 / 3 * 3 = 0; For square 2: 0 / 3 * 3 = 0; For square 3: 3 / 3 * 3 = 1; For square 6: 6 / 3 * 3 = 6; Is it clear? For now, we have three base checks. And we can iterate from 1 to 9 and check 9 rows, 9 columns, and 9 squares. Code Java public boolean isValidSudoku(char[][] board) { for (int i = 0; i < board.length; i++) { boolean isValidLine = isValidRow(board, i); boolean isValidRow = isValidColumn(board, i); boolean isValidSquare = isValidSquare(board, i); if (!isValidLine || !isValidRow || !isValidSquare) { return false; } } return true; } private boolean isValidRow(char[][] board, int line) { int[] dict = new int[10]; for (int i = 0; i < board[line].length; i++) { char cur = board[line][i]; if (Character.isDigit(cur)) { int curInt = cur - '0'; if (curInt < 1 || curInt > 9) { return false; } if (dict[curInt] > 0) { return false; } dict[curInt]++; } } return true; } private boolean isValidColumn(char[][] board, int row) { int[] dict = new int[10]; for (int i = 0; i < board.length; i++) { char cur = board[i][row]; if (Character.isDigit(cur)) { int curInt = cur - '0'; if (curInt < 1 || curInt > 9) { return false; } if (dict[curInt] > 0) { return false; } dict[curInt]++; } } return true; } private boolean isValidSquare(char[][] board, int square) { int[] dict = new int[10]; int startRow = (square * 3) % 9; int endRow = startRow + 3; int startCol = (square / 3) * 3; int endCol = startCol + 3; for (int i = startCol; i < endCol; i++) { for (int j = startRow; j < endRow; j++) { char cur = board[i][j]; if (Character.isDigit(cur)) { int curInt = cur - '0'; if (curInt < 1 || curInt > 9) { return false; } if (dict[curInt] > 0) { return false; } dict[curInt]++; } } } return true; } I know, I know a lot of code. But for now, we know how to check Sudoku. Longest Consecutive Sequence Description Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Example 1: Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. Example 2: Input: nums = [0,3,7,2,5,8,4,6,0,1] Output: 9 Solution Do you remember our topic? It is Arrays and Hashing. Let's think about how we can use it. We should find consecutive elements. For example, 1, 2, 3, 4, or maybe 10, 11, 12. As a brute force solution, we can try to sort an array and check all subsequences. But it will take O(NlogN) time with standard Java sort algorithms. Based on the base example, we understand that if we have 1 in the array, we should check 2. If we have 2 in the array, we have subsequence size two and want to check 3. Do we have it in the array? Let's try to check it, but without sorting. In this case, we need to iterate over the array N*N times. But what if we simply put all array elements into HashSet and then check them there? 1. Put array elements into set 2. Iterate over set 3. Check element and element + 1 4. Do it till the end But looks like this algorithm also will be N*N. It looks so, but let's check a code, and then I will try to explain. Code Java public int longestConsecutive(int[] nums) { int max = 0; Set<Integer> set = new HashSet<>(); for (int num : nums) { set.add(num); } for (Integer i : set) { if (!set.contains(i - 1)) { int prev = i; int curMax = 1; while (set.contains(prev + 1)) { prev++; curMax++; } max = Math.max(max, curMax); } } return max; } Although the time complexity appears to be quadratic due to the while loop nested within the for loop, closer inspection reveals it to be linear. Because the while loop is reached only when i marks the beginning of a sequence (i.e., i-1 is not present in the array), the while loop can only run for N iterations throughout the entire runtime of the algorithm. This means that despite looking like O(N*N) complexity, the nested loops actually run in O(N+N)=O(n) time. All other computations occur in constant time, so the overall runtime is linear.
My journey to co-founding Kubiya.ai was triggered by the very real pain of being a DevOps leader supporting both broader organizational goals along with the day-to-day support of software engineers and others. This is my story (or at least the somewhat interesting parts) of what it was like and how I found a productive approach to managing it all. DevOps Opening Hours: 2:45 p.m. until a Quarter to 3:00 p.m. It’s really not a joke. DevOps have no time. We need to make sure everything is running smoothly from development to production and often beyond. We are busy enhancing CI/CD processes, upgrading and configuring monitoring and alerting systems, and optimizing infrastructure for both cost and security, as well as sitting in lots of meetings. But on top of all that, we need to deal with endless and oftentimes repetitive requests from developers (and others). This was exactly my experience as the head of DevOps at my previous company. The repetitive requests were not only taking up around 70% of my team’s time and energy, it had them mouthing off RTFM every time a dev would ask them a question. In Search of DevOps Self-Serve that Works So I started exploring different solutions for enabling a self-service culture in the organization to reduce the burden of the DevOps team while empowering developers to do more on the operational side. But before exploring the solutions I explored, I want to mention several things that were constantly on my plate as head of DevOps: Planning, building, and managing multiple types of pipelines for the R&D teams which included CI/CD pipelines, self service automation, and infrastructure as code (IAC) Dealing with permissions requests from different personas in the organization while keeping the security team in the loop Taking care of the onboarding and offboarding process of engineers in the company And of course the maintenance of all the different tools to accomplish those tasks While doing all of this, my team had to keep an eye on several Slack channels to answer questions from the tech organization, such as: “Where are my logs?” “Why did my pipeline fail?” “Why did my service stop responding?” Kubernetes questions, cloud questions, and more So we tried several different approaches. Internal Developer Platforms: Loads of Development Internal developer platforms, typically created and maintained by a dedicated team, are a combination of common tools and technologies that can be used by software developers for easier access and management of complex infrastructure and processes. While we considered building a developer platform, there simply was too much planning required to make this a reasonable endeavor. For starters, we had so many tools in use and with a very dynamic organization the number and types of tools were constantly changing making ongoing curation a real challenge. But aside from bringing all these tools together into a single platform, training and adoption was not realistic with a software development team singularly focused on coding the next best thing. We found ourselves struggling to decide how to create such a platform and what features should be included. Naturally we worried about creating a new kind of toil. Even if we reduced the workload coming from developer requests, embracing an internal developer platform looked like it would bring fresh pain with managing the platform lifecycle, adding new features, and as always, supporting different users. Workflow Automation Is Not So Automatic Of course our industry’s standard solution — and one that our tech organization already understood — was to automate everything possible. So, utilizing tools that our developers were already familiar with, such as Jenkins, we created automation for nearly any issue you can think of. As soon as an issue occurred, we were able to create a dedicated pipeline to solve it. The main problem was that developers didn't know where to find these workflows. And even if they knew where to find the workflow, they did not usually know which parameters to fill in. So we were back to the same routine of devs approaching us for help. Permissions were another issue. It was very risky for us to allow large groups to trigger workflows. With so much potential for chaos, deciding who should have authority to run workflows was no easy task. Even granting permissions and approvals on an ad hoc basis with the security team took a lot of time and effort. Permission lifecycles were also problematic, as offboarding a user who left the company required special handling. New workflows required adding permissions and defining who would receive those permissions. Finally, each time an existing workflow was edited to include more actions, a fresh review of both the workflow and associated permissions was required. Chatbot to the Rescue In light of the fact that developer requests came to us via a chat interface (in our case it was Slack), whether by direct messaging me or my team members, or via the on-call channel, I decided to create a chatbot or Slackbot. For permissions management, I connected our chatbot to our company’s identity provider. This allowed the Slackbot to know the role of anyone who approached it. This made it easy to create unique policies for different user roles (defined by the identity provider) in terms of consuming the operational workflows via the Slackbot. For context gathering, the Slackbot would ask the relevant questions, guiding users to provide the details needed to fill in as parameters of the different workflows that already existed for CI/CD tools like Jenkins, cloud infrastructure, and more. Besides solving the lack of domain expertise and lack of interest in operations, our Slackbot acted as a proxy with guardrails for developers. This allowed them to do what they needed without over-permissioning. Most importantly, it reduced my team workload by 70% while eliminating long delays for end users, avoiding long waits in a virtual queue. Trouble in Chatbot Paradise While this was amazing, our Slackbot was still not 100% user-friendly. Users had to choose from a static list of workflows and use predetermined words or slash commands. Our Slackbot was also unable to handle anything not included in its rule-based, canned interactions. As a result, our Dev team would be left empty-handed in cases of "out of scope" requests. The Slackbot maintenance, however, was far worse. With so many workflows to create and so many DevOps cooks in the kitchen, I could not enforce a standard programming language. Whenever one workflow broke, figuring out all the dependencies to find a fix took way too much effort. If I wanted to add a brand-new workflow, it would also require very significant effort and domain expertises. Which brought us all the way back to the same problem of more toil in managing the Slackbot. AI-Driven Virtual Assistants Exploring and experiencing the pros and cons of the various solutions led me to understand that the key to success is finding a solution that benefits both the developers AND DevOps. A system that can ask the developer questions if context is missing, transforming context gathering (which DevOps would normally have to handle) into simple conversations. Using NLU to infer user intent from a phrase fragment and offer to execute the relevant workflows is another area where AI can improve the end-user experience — so even if a developer only knows, for example, a part of the name of a cluster or service, the virtual assistant can figure out what it is that they need. This combination of all of the features of a chatbot — plus the ability to understand or learn the user's intentions (on the fly) even if it’s something new and unfamiliar — keeps workflows flowing. In addition to all this, my conversations with Kubiya.ai customers made it clear that a self-service approach needs to be tied in with security as well. Being able to easily manage user permissions both upfront in the form of policy creation for different users and groups as well as with just-in-time, ad hoc approvals is key to a successful self-serve solution. In summary, my experience building a self-serve culture has shown me that having an efficient system in place is essential for companies who want to move fast as it ensures that all parties — operations, development, security teams — can get their work done with the least amount of toil and friction.
JAX is up and coming in the Machine Learning space with ambitions to make machine learning simple yet efficient. JAX is still a Google and Deepmind research project and not yet an official Google product but has been used extensively internally and adopted by external ML researchers. We wanted to offer an introduction to JAX, how to install JAX, and its advantages and capabilities. What Is JAX for Machine Learning? JAX is a Python library designed for high-performance numerical computing, especially machine learning research. Its API for numerical functions is based on NumPy, a collection of functions used in scientific computing. JAX focuses on accelerating the machine learning process by using XLA to compile NumPy functions on GPUs and uses autograd to differentiate Python and NumPy functions as well as gradient-based optimization. JAX is able to differentiate through loops, branches, recursion, and closures, and take derivatives of derivatives of derivatives with ease using GPU acceleration. JAX also supports backpropagation and forward-mode differentiation. JAX offers superior performance when using GPUs to run your code and a just-in-time (JIT) compilation option to easily speed up large projects, which we will delve into later in this article. Think of JAX as a Python Library that modifies NumPy and Python code with function transformations to enable accelerated machine learning. As a general rule, you should use JAX whenever planning to train with GPUs, compute gradients (autograd), or use JIT code compiling. Why Use JAX? In addition to working with normal CPUs, JAX's main function is the capability to be fully functional with different processing units such as GPUs. This gives JAX a great advantage over similar packages because the use of GPU parallelization enables faster performance than CPUs when it comes to image and vector processing. This is extremely important because when using the NumPy library users can build matrices of exceptional sizes allowing GPUs to be much more time-efficient when processing such data formats. This time difference enables the JAX library to exceed NumPy alone by over 100 times the speed and performance through a couple of key implementations: Vectorization - processing multiple data as single instruction that provides great speedups for linear algebra computations and machine learning Code Parallelization - the process of taking serial code that runs on a single processor and distributing it. GPUs are preferred here since they have numerous processors specialized for computations. Automatic Differentiation - very simple and straightforward differentiation that can be chained multiple times to evaluate higher-order derivatives with ease. How to Install JAX To install the CPU-only version of JAX, which might be useful for doing local development on a laptop, you can run Shell pip install --upgrade pip pip install --upgrade "jax[cpu]" On Linux, it is often necessary to first update pip to a version that supports manylinux2014 wheels. pip installation: GPU (CUDA) To install JAX with both CPU and NVIDIA GPU support, you must first install CUDA and CuDNN, if they haven’t already been installed. Unlike many other popular deep learning systems, JAX does not bundle CUDA or CuDNN as part of the pip package. JAX provides pre-built CUDA-compatible wheels for Linux only, with CUDA 11.1 or newer, and CuDNN 8.0.5 or newer. Other combinations of the operating system, CUDA, and CuDNN are possible, but require building from the source. CUDA 11.1 or newer is required You may be able to use older CUDA versions if you build from the source, but there are known bugs in CUDA in all CUDA versions older than 11.1, so we do not ship prebuilt binaries for older CUDA versions. The supported cuDNN versions for the prebuilt wheels are: cuDNN 8.2 or newer. We recommend using the cuDNN 8.2 wheel if your cuDNN installation is new enough since it supports additional functionality. cuDNN 8.0.5 or newer. You must use an NVIDIA driver version that is at least as new as your CUDA toolkit's corresponding driver version. For example, if you have CUDA 11.4 update 4 installed, you must use NVIDIA driver 470.82.01 or newer if on Linux. This is a strict requirement that exists because JAX relies on JIT-compiling code; older drivers may lead to failures. If you need to use a newer CUDA toolkit with an older driver, for example on a cluster where you cannot update the NVIDIA driver easily, you may be able to use the CUDA forward compatibility packages that NVIDIA provides for this purpose. Shell pip install --upgrade pip # Installs the wheel compatible with CUDA 11 and cuDNN 8.2 or newer. # Note: wheels are only available on Linux. pip install --upgrade "jax[cuda]" https://storage.googleapis.com/jax-releases/jax_cuda_releases.html The jaxlib version must correspond to the version of the existing CUDA installation you want to use. You can specify a particular CUDA and CuDNN version for jaxlib explicitly: Shell pip install --upgrade pip # Installs the wheel compatible with Cuda >= 11.4 and cudnn >= 8.2 pip install "jax[cuda11_cudnn82]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html # Installs the wheel compatible with Cuda >= 11.1 and cudnn >= 8.0.5 pip install "jax[cuda11_cudnn805]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html You can find your CUDA version with the command: Shell nvcc --version Some GPU functionality expects the CUDA installation to be at /usr/local/cuda-X.X, where X.X should be replaced with the CUDA version number (e.g. cuda-11.1). If CUDA is installed elsewhere on your system, you can either create a symlink: Shell sudo ln -s /path/to/cuda /usr/local/cuda-X.X Comparing JAX to NumPy Since JAX is an augmented NumPy, their syntax is very similar, giving users the ability to use the two interchangeably in projects where NumPy or JAX isn’t performing. This is often with smaller projects where the amount of acceleration is negligible in time saved. However, as models get larger, the more you should consider JAX. Multiplying Two Matrices Using JAX vs. NumPy To clearly illustrate the speed difference between these two libraries, we will use both to multiply two matrices by each other and then check the performance differences between CPU only and GPU. We will also check the performance boost that is caused by the JIT compiler. To follow along with this tutorial, install and import the JAX and NumPy libraries (from the previous step). You can test your code on sites such as Kaggle or Google Colab. As with any library, you should import JAX by writing the following lines at the beginning of your code: Python import jax.numpy as jnp from jax import random You can also import the NumPy library in a similar manner: Python import numpy as np Next, we will compare the performance of both JAX and Numpy using the CPU and GPU by multiplying two matrices together in Python. For these benchmarks, lower is better. NumPy on CPU To begin, we will create a matrix of 5,000 by 5,000 using NumPy and test its performance speed-wise. Python import numpy as np size = 5000 x = np.random.normal(size=(size, size)).astype(np.float32) %timeit np.dot(x, x.T) 785 ms per loop A single loop of the code running on NumPy took around 750 ms per loop to run. JAX on CPU Now let’s run the same code, but this time using the JAX library. Python import jax.numpy as jnp size = 5000 x = jnp.random.normal(size=(size, size)).astype(np.float32) %timeit jnp.dot(x, x.T).block_until_ready() 1.43 sec per loop As you can see, comparing JAX and NumPy CPU-only performance shows that NumPy is the faster option. While JAX may not provide the best performance with normal CPUs, it does provide much better performance with GPUs. JAX With GPU Now, let's try to create the same 5,000 by 5,000 matrix, this time using JAX with a GPU instead of the regular CPU: Python import jax import jax.numpy as jnp from jax import random key = random.PRNGKey(0) size = 5000 x = random.normal(key, (size, size)).astype(jnp.float32) %time x_jax = jax.device_put(x) %time jnp.dot(x_jax, x_jax.T).block_until_ready() %timeit jnp.dot(x_jax, x_jax.T).block_until_ready() 80.6 ms per loop As clearly shown when running JAX on a GPU instead of a CPU, we achieve a much better time of around 80ms per loop (around 15 times the performance). This will be even easier to see when using larger matrices or time scales. Just-in-Time Compilation (JIT) Using the jit command, our code will be compiled using a specific XLA compiler, allowing our functions to be efficiently executed. XLA, short for accelerated linear algebra, is used by libraries such as JAX and Tensorflow to compile and run code on the GPU with greater efficiency. So to sum it up, XLA is a specific linear algebra compiler that is capable of compiling code at a much higher speed. We will test our code using the selu_np function, which stands for Scaled Exponential Linear Unit, and check the different time performances between NumPy on a normal CPU, and running JAX on a GPU with JIT. Python def selu_np(x, alpha=1.67, lmbda=1.05): return lmbda * np.where(x > 0, x, alpha * np.exp(x) - alpha) def selu_jax(x, alpha=1.67, lmbda=1.05): return lmbda * jnp.where(x > 0, x, alpha * jnp.exp(x) - alpha) NumPy on CPU To start with, we will create a vector of size 1,000,000 using the NumPy library. Python import numpy as np x = np.random.normal(size=(1000000,)).astype(np.float32) %timeit selu_np(x) 8.3 ms per loop JAX on GPU with JIT Now we will test our code while using JAX and JIT on a GPU. Python import jax import jax.numpy as jnp from jax import random from jax import grad, jit key = random.PRNGKey(0) def selu_np(x, alpha=1.67, lmbda=1.05): return lmbda * np.where(x > 0, x, alpha * np.exp(x) - alpha) def selu_jax(x, alpha=1.67, lmbda=1.05): return lmbda * jnp.where(x > 0, x, alpha * jnp.exp(x) - alpha) x = random.normal(key, (1000000,)) selu_jax_jit = jit(selu_jax) %time x_jax = jax.device_put(x) %time selu_jax_jit(x_jax).block_until_ready() %timeit selu_jax_jit(x_jax).block_until_ready() 153 µs per loop (0.153 milisecond per loop) Lastly, when using the JIT compiler with a GPU, we get a much better performance than using a normal GPU. As you can clearly, see the difference is very apparent, a nearly 5000% speed increase or 50 times faster from NumPy to JAX with JIT! Think of JAX as a modification to NumPy to enable accelerated machine learning with GPUs. Since NumPy can only be compiled CPU, JAX is faster than NumPy if you opt to execute code on GPUs. As a general rule, you should use JAX whenever planning to use NumPy with GPUs or use JIT code compiling. Note: to check the original article from where the examples in this tutorial were used, check the following link: original code. JAX Limitation: Pure Functions JAX transformations and complications are designed for Python functions that are functionally pure. Pure functions cannot change the state of the program by accessing outside variables, and cannot have side effects on functions such as input/output streams like print(). Consecutive runs cause these side effects to not perform as intended. If you are not careful, untracked side effects could throw off the accuracy of your intended computations. Using Google’s JAX In this article, we explained the capabilities of JAX and what advantages it brings to NumPy. We covered how to install the JAX library and its advantages for machine learning. We then went on to import JAX and NumPy. Moreover, we compared JAX with NumPy (which is the most well-known competitor library out there) and revealed the time and performance differences between these two using regular CPUs and GPUs alongside some JIT tests as well and saw drastic speed improvements. If you are an advanced machine/deep learning practitioner, then adding a library such as JAX to your arsenal with its (GPU/TPU) accelerators and its efficient JIT compiler will definitely make life much easier.
Tuhin Chattopadhyay
Founder and CEO,
Tuhin AI Advisory
Thomas Jardinet
IT Architect,
Rhapsodies Conseil
Sibanjan Das
Zone Leader,
DZone
Tim Spann
Developer Advocate,
StreamNative