Introduction

In our previous article about Machine Learning Operations (MLOps) and Large Language Model Operations (LLMOps), we discussed what each is, their similarities, and the differences that characterise them. Focusing on LLMOps, now that the general idea is understood, why don’t we have a look at how they can be improved and optimised based on the application and the tasks we want them to perform?

Evaluation Methods

As with every Machine Learning (ML), Deep Learning (DL) and Artificial Intelligence (AI) model, there are certain ways to evaluate the performance of an LLMOp. Starting with the basics, accuracy and precision are very good starting points. Roughly, accuracy measures how often predictions of a model are correct, which is the ratio of the correct predictions over the total number of predictions, while precision is the ratio of the true positive values over the total number of positives (true and false). If this sounds complicated, let us give you a simplified example.

You take 100 people and classify them as diabetic or non-diabetic using ML just by reading their recent blood glucose levels. Let us gather all the results in a table, also known as a ‘confusion matrix’:

Table 1 – An example of a confusion matrix that presents predictions between two classes (‘Diabetic’ and ‘Healthy’) in a population of 100 people.

As you can see, the sum of all categories adds up to 100. Calculating the accuracy and prediction, we find that the accuracy of the model is equal to 36%, while the precision is 53,47%.

Two more advanced but still fundamental evaluation methods are the Recall and F1-score, which are the ratio of true positive results to the actual number of positive cases in the entire dataset and harmonic mean of precision and recall (we will let you do the maths on these. Of course, other factors are also essential. Don’t forget that we are talking about Generative AI (GenAI) after all, so it would be useless without a proper response time. If the response time is not good, it will be as annoying as having lag in an online call. Robustness and reliability are also essential, as they ensure proper function even when the data load is large or an unexpected query has been made. Similarly, proper Resource Utilisation is important, as LLMOps need to generate the best output as fast as possible while keeping the CPU and GPU load low, especially in GPU-accelerated tasks such as AI image generation.

It feels overwhelming, doesn’t it? Keep in mind that these are only the essentials! The true struggle of LLMs is to understand questions that seem pretty essential to us humans, with misinterpretation reaching a difference of 47% (95% in humans and 48% in machines). A true way to evaluate the performance of an LLM is by using tools like HellaSwag. Simply put, HellaSwag presents a model with sentences that make sense and sentences that don’t. The model is presented with the sentences in groups of four, all of which have the same beginning but a different ending. Of these four, only one makes the most sense, which is also labelled as such. The model’s probability of correctly predicting is computed, and if the labelled ending has the highest probability, it is considered a correct prediction. The groups with the correct predictions give us the resulting accuracy (GitHub, n.d.).

Full Steam Ahead!

Transfer learning

So, let’s suppose that you have your LLMOp locked and loaded, ready to fire in a commercial task. After evaluating its performance using the basic methods that we mentioned above, a very smart thing to do is Transfer Learning (TL). Basically, TL takes a developed model or algorithm, which has been tested on a specific topic, and uses it on different data. It might sound counter-intuitive; however, it plays a major role when developing an all-around model. It is no wonder that the GenAI models developed by leading companies such as OpenAI, Microsoft, and Google are so successful. Imagine if they were only able to answer questions related to a single topic. Where is the success in that? By training an LLMOp in different datasets, we can test how versatile our pipeline is and how many different applications it can have (Amazon Web Services, Inc., n.d.c). You don’t believe us? What, you think all Computer Vision (CV) algorithms have the same capabilities regardless of the application? The training between airport security cameras is way different than the training for Augmented Reality (AR) or Extended Reality (XR) goggles that you use to play your favourite games!

Finetuning

TL is more or less a generalisation of the applications an LLMOp model can have. But what about precision and specificity? You can have a functioning model; however, that does not mean that it provides 100% accurate content. One of the most famous NLPs (take a guess) had actually been proven to have such an issue during its early stages. When asked to provide web sources for the content it generated, the results were a mess. Links were leading to non-existent pages, or they were not working at all. The way to fix that is Finetuning, and even though, in theory, it doesn’t sound that difficult, it really makes a difference! Examples of finetuning include:

  • Pre-trained Model Selection, where a specific model is selected based on performance on related tasks and compatibility with the task’s requirements.

  • Hyperparameter tuning, such as the learning rate band atch size.

  • Task-specific adaptation, where the pre-trained model is modified by adding task-specific layers or adjusting the existing layers to better align with the target task.

  • Training with task-specific data, which involves feeding the pre-trained model with data specific to the target task. This allows the model to learn task-specific patterns and nuances that were not explicitly covered in its pre-training phase (Shanepeckham, 2024).

Retrieval-Augmented Generation

Retrieval-Augmented Generation (RAG) is probably one of the coolest ways to boost the performance of an NLP. As you know, LLMOps are trained on massive datasets to provide accurate and ready-for-production content. If one thing is true, it is that a dataset can never be enough to train a machine. Here is where RAG comes in to make the NLP outperform itself each time, and our guess is that you have already used it; you just didn’t know you had (Merritt, 2023)!

Simply put, RAG is the perfect combination between retrieving data and the one the model has been trained on to generate content. RAG is split into three discrete phases. The first phase is called the ‘Retrieval’ phase. During retrieval, the model identifies documents or text from databases that it is already familiar with and is trained in. The second phase is ‘Augmentation’, during which the model uses the retrieved documents or text as an additional source of information, a crucial step in generating more authentic and context-specific content. Last, we have the ‘Generation’ phase, during which the initial query and the augmentation result are combined for the best result (Amazon Web Services, Inc., n.d.b).

RAG is the technology responsible for the consistency of your conversation with your favourite Natural Language Processing (NLP) assistant, as RAG is used to improve the flow and relevance of the dialogue between you and the machine. We said that you probably have used RAG, but you just don’t realise. Roll back to the last time you uploaded a document to your NLP assistant or when you asked it to summarise a text for you!

Figure 1 – Illustration of the three most widely used optimisation methods for LLMOps
Figure 1 – Illustration of the three most widely used optimisation methods for LLMOps

Read more: Understanding Retrieval Augmented Generation (RAG)

LangChain and Model Chaining

LangChain

LangChain is an abbreviation, a combination, if you want, of the words ‘language’ and ‘chain’, and it can have many implementations. It has been established that LLMOps are pipelines on which a Large Language Model (LLM) is trained. Now earlier, we said that a way to ensure a more generic application of an LLMOp is by using TL. As you understand, this would take quite some time, and it can be resourceful, not to mention that the possibility of an error increases if the prompt engineers are not cautious and careful. Of course, there is the space problem, as the hardware for such tasks can sometimes occupy entire rooms! The Internet of Things (IoT) can aid in that, as infrastructure spreads in different areas, it can really make a difference when large spaces are required. And, when an area is remote, Edge Computing can be significant. Is there a reason to face these problems when you can avoid them from the beginning, though?

Instead of solving the unsolved, what can be done is to train different LLMOps in different pipelines and data sets (based on the desired output and ‘specialisation’) and link them together. Then, depending on the context and the prompt, the appropriate pipeline can be used and linked with others (Amazon Web Services, Inc., n.d.a) Simply put, imagine someone being a skilled engineer, electrician, doctor, pilot, plumber, cook, and professional athlete capable of using all of their knowledge at will!

Model Chaining

Similarly to LangChain, Model Chaining provides a more specialised answer or more specific content. While LangChain switches between different pipelines, Model Chaining is based on switching between different models according to the desired task the LLMOp needs to solve. A key element here is the order of execution, as in Model Chaining, each model’s output serves as an input to the next. The big difference, hence, between LangChain and Model Chaining is that, while LangChain optimisation is concurrent, Model Chaining is strictly sequential.

Let’s explain it using an example from everyday life. Pretend that you are cooking a meal. You start by chopping the veggies, then heat the stoves, sear them in a pan, and finally, set the table to serve the dish. Each step depends on the previous one: you can’t cook until the vegetables are chopped, and you can’t really serve until the cooking is done and the table is set. This is a sequential process, where every step happens strictly after the other. Now, imagine you have an assistant in the kitchen. While you’re chopping the vegetables, your helper preheats the oven and sets the table at the same time. These tasks don’t depend on each other, so doing them simultaneously saves time. This is a concurrent process, where independent tasks are being done simultaneously, making the overall process quicker and more efficient.

Figure 2 – Illustration of two approaches that an LLMOp can ‘think’ to generate content
Figure 2 – Illustration of two approaches that an LLMOp can ‘think’ to generate content

Summing Up

In our previous article on MLOps and LLMOps, we discussed the key differences and similarities between the two. After understanding how each works and what principles it is based on, we focused on how to improve the most complex of the two. This doesn’t mean that this is where it stops. In fact, this is only a sample of ways in which LLMOps can be improved. That is, so far, new ways will surely be found while technology advances. One thing is certain. LLMOps are powerful tools, the limits of which are only our skills.

What We Offer

One thing we really know at TechnoLynx is how to innovate. We offer solutions that are custom-tailored for your needs, made on demand, from scratch, and specifically designed for each project. Delivering tech solutions is our specialisation because we truly understand the benefits of AI, dare we say, better than anyone. We are committed to providing cutting-edge solutions in any field, enriching your project with AI solutions while ensuring safety in human-machine interactions. We take pride in managing and analysing large data sets while at the same time addressing ethical considerations.

Our software solutions are precise, empowering many fields and industries using innovative AI-driven algorithms, never resting and always adapting to the ever-changing AI landscape. The solutions we present are designed to increase accuracy, efficiency, and productivity. Feel free to contact us to share your ideas. Let us boost your project!

Continue reading: Understanding Language Models: How They Work

List of references