Virtual TechTalk

Hear from Google Cloud Experts:  How to Scale Data Integration to and from Google BigQuery: Watch On-Demand

Watch Now

Large Language Models (LLMs) Tutorial

Your Guide to Generative AI Infrastructure

Large language models (LLMs) are AI implementations that generate text. They are trained on terabytes of data from the internet and private sources, from which the AI learns statistical correlations. This effort provides it with extensive knowledge about the world and, thus, the ability to speak fluently about a wide variety of topics and to complete a variety of different natural language tasks with a single model.

In this article, we provide a brief history of how LLMs were developed, discuss best practices for getting the most out of them, lay out some use cases where they work well, and cover the challenges that they can pose.

Summary of the key concepts for understanding LLMs

The following table summarizes the key concepts that are elaborated upon later in this article: 

Concept Description 
History of LLMs Large language models began with Google Brain’s introduction of the Transformer architecture in 2017, which revolutionized natural language processing. Subsequent breakthroughs have included Google’s BERT, OpenAI’s GPT-3, and the evolution of LLMs like GPT 3.5, culminating in the creation of ChatGPT, a highly versatile conversational AI model, in late 2022.
Best practices and recommendations To optimize the performance of LLMs, employ prompt engineering techniques and consider fine-tuning options such as OpenAI’s gpt-3.5-turbo or Hugging Face’s models like LLaMa-2 with parameter-efficient fine-tuning (PEFT). Integrating your own data using retrieval-augmented generation (RAG) enabled by  Nexla’s data management and workflow orchestration capabilities enhances the adaptability of LLMs and effectiveness across various applications.
Use cases Large language models have a wide variety of applications, serving as chatbots adaptable to specific needs, excelling in a variety of natural language processing (NLP) tasks, and generating synthetic data for diverse purposes. This utility extends to enhancing user experiences, content generation, and supporting AI research and analysis.
Challenges  Memory constraints, slow loading times, hardware accessibility, the risk of misinformation generation, and the limited task generalization of LLMs are all obstacles that need to be addressed to harness their potential fully, emphasizing the need for ongoing research and development.

A brief history of LLMs 

The history of LLMs begins with Google Brain’s introduction of the Transformer architecture in 2017. Compared to its predecessor, the recurrent neural network (RNN), it had the ability to leverage fully parallel processing for more efficient training and to enable the model to reason across long sequences of text. This was revolutionary because it removed significant limitations that stopped researchers from scaling up deep learning models in NLP.

A year later, Google released Bidirectional Encoder Representations from Transformers (BERT), one of the first notable models showcasing the potential of the Transformer architecture. BERT demonstrated that if the Transformer was trained on a large amount of natural language data, it could leverage that knowledge to perform well on a wide variety of natural language processing tasks after being fine-tuned on them. This breakthrough showed, for the first time, the versatility of LLMs and their potential to be customized for different applications.

During this time, OpenAI was working on building the Generative Pre-Trained Transformer (GPT) series. Though the original GPT model did not perform very well—being surpassed by BERT—OpenAI’s commitment to enhancing and scaling it ultimately paid off. With the creation of GPT-3 in 2020, a model using a colossal 175 billion parameters, LLMs showed the ability to tackle a wide variety of tasks within a single model without any fine-tuning. GPT-3 also exhibited a remarkable ability to produce human-like text across a wide array of domains, proving that LLMs could truly serve as one-size-fits-all solutions for natural language understanding and generation.

The releases of InstructGPT, and its successor, GPT 3.5, marked additional important milestones in the evolution of LLMs by using a technique called instruction tuning. Specifically, these models took a novel approach to training by reformatting a high number of natural language tasks to adhere to the GPT training objective (predicting the next word). The result was a model that excelled at a multitude of different tasks.

Finally, the release of ChatGPT in late 2022 represented a transformative development in making LLMs more conversational and interactive. In particular, OpenAI’s addition of a conversational tone and the ability to engage in multi-turn dialogue transformed GPT 3.5 into an extremely versatile chatbot. Overall, it demonstrated the enormous promise of LLMs for chatbots, virtual assistants, and customer service applications.

Today, one can access the innovations of these LLMs from either white-label APIs (e.g., OpenAI, Cohere, Anthropic) or by downloading open-source models from Hugging Face.

Powering data engineering automation for AI and ML applications

Learn how Nexla helps enhance LLM models

Enhance LLM models like GPT and LaMDA with your own data

Connect to any vector database like Pinecone

Build retrieval-augmented generation (RAG) with no code

Best practices and recommendations for using LLMs

Consider the following three strategies when using LLMs in your applications.

A high-level summary of the best practices 
Leverage prompt engineering
Consider fine-tuning for optimal results
Employ retrieval-augmented generation (RAG) to use your own data
Choose the Right LLM

Leverage prompt engineering

Prompt engineering is the process of changing the format, content, or style of the input instructions you provide to the LLM to help it perform better. For example, you can choose to provide it with some examples of what correct answers look like for your use case in the prompt (this is called in-context learning) or ask it to “think step-by-step” to help it do better on complex reasoning tasks.

When working with LLMs, employ prompt engineering techniques such as in-context learning, crafting prompts that closely resemble NLP tasks used in academia, and exploring chain-of-thought prompts. These approaches enhance the model’s understanding of specific tasks and thus their performance.

Consider fine-tuning for optimal results

To improve performance, explore fine-tuning your model. You can use OpenAI’s fine-tuned models like gpt-3.5-turbo (ChatGPT) or explore fine-tuning models like LLaMa-2 or Mistral-7B with Hugging Face’s fine-tuning capabilities, particularly parameter-efficient fine-tuning (PEFT). These methods allow you to adapt the model to meet your specific requirements:

  • Fine-tuning with OpenAI: OpenAI offers fine-tuning capabilities for three different models: gpt-3.5-turbo (ChatGPT), davinci-002, and babbage-002. While davinci-002 has been essentially completely outclassed by gpt-3.5-turbo—and, as of the time of writing, is actually more expensive despite its weaker performance—the other two models may be valuable to fine-tune. Gpt-3.5-turbo should be used for more complex tasks, whereas babbage-002 will likely suffice for simpler ones. If you’re interested in fine-tuning gpt-3.5-turbo (ChatGPT), OpenAI provides detailed instructions (including code snippets) to do so. Ultimately, fine-tuning will help you make the most of GPT’s capabilities.
  • Utilize PEFT for fine-tuning: PEFT comes in four different flavors: low rank adaptation (LoRA), prompt tuning, prefix tuning, and p-tuning. While LoRA is the most common, it also is notable for its ability to reduce RAM memory consumption during training (the others mainly excel in reducing storage costs). To learn more about how to use this tool, Hugging Face provides an extensive tutorial on PEFT.

Employ retrieval-augmented generation (RAG) to use your own data

One key application of LLMs is integrating your own data to enhance its capabilities. Here are the steps involved:

  • Ingest your existing data: Begin by importing your existing data into the system, such as support documents, how-to guides, wikis, or product reviews. If these are not already in text format, you will need to take steps to convert them, or use tools that support ingestion of multiple document formats such as PDF, DOCX, HTML. In addition, for very long documents, such tools support breaking a large document into smaller chunks. There are many chunking strategies that can be applied to improve the quality of results. Alternatively, if you have image data that you believe would be helpful, you can use a multimodal LLM, which can take as input both images and text while outputting text. GPT-4V is the most prevalent example of this, but there are several open-source alternatives, including LLaVa-1.5, InstructBLIP, MiniGPT, and OpenFlamingo.
  • Create embeddings for your data: Use the OpenAI API or similar tools (e.g., Sentence Transformers) to generate embeddings for your data. Embeddings transform the data into a format that LLMs can effectively work with.
  • Store embeddings in a vector database: Save the generated embeddings in a vector database such as Pinecone, Weaviate, or Redis. This database stores the data in vector form, making it accessible and usable by the LLM.

At query time, you should engage in these steps after a user enters a query:

  • Convert the query to a vector: The user’s query is converted into a vector representation.
  • Perform similarity search: Conduct a similarity search on the query within your vector database to identify relevant data or contexts.
  • Provide user query and results as context: The results from the vector database, along with the user’s query, are provided as context to the LLM.
  • Generate response: With this additional context, the LLM can now utilize your data to generate a more precise and informative response.
Unlock the Power of Data Integration. Nexla’s Interactive Demo. No Email Required!


Choose the Right LLM

Today, there are hundreds of different LLMs you could choose for your use case. To choose between these, you should consider:

  • Open-source vs. API: Some models, including OpenAI’s GPT and Anthropic’s Claude, are only available via paid API. While these models generally rank among the best in terms of model quality and capabilities, they also have low customizability – and will require that you send your data to a third-party. Open-source models (e.g., Meta’s Llama-2, Mistral) provide this customizability and data privacy though tend to perform worse than their closed-source counterparts (though a large part of this is likely because open-source models tend to be smaller).
  • Size: Larger models are able to do more tasks with better performance, while smaller models allow for lower hosting costs, faster speed, and lower memory requirements.
  • Instruction Tuning: As noted earlier, instruction tuning involves training LLMs on a wide variety of different tasks. However, your use case likely differs from the format of these tasks (e.g., you want an LLM that can summarize articles, but want a different output structure than what the LLM is currently providing you). As such, you should select a model that has been fine-tuned on tasks closely aligned with your use case to minimize the amount of data required for teaching the language model to understand your specific application.

Platform recommendations

A platform like Nexla can play a crucial role in the data integration process, enhancing both indexing and runtime operations.

Data indexing

Nexla streamlines and simplifies the data indexing process, in particular, ingesting structured and unstructured data, creating embeddings, and storing data in a vector database. This ensures that your data is effectively prepared for use by the LLM.

Runtime operations

Nexla provides real-time data flow capabilities that efficiently augment user queries with context. This enables seamless and dynamic integration of your data with LLMs, enhancing their ability to generate contextually relevant responses:

  • Effective data management with Nexla: In an enterprise context, effective data management is crucial to achieve success with LLMs. Nexla offers a valuable solution for handling disparate and disorganized enterprise data across a large team of users. In particular, it provides compatibility across on-premises and cloud environments, and its no-code and low-code user interface simplifies collaboration and enforces data governance. Without Nexla, a large organization could easily find themselves building thousands of pipelines to access their data.
  • Enhance metadata handling with Nexla: If your data includes various forms of metadata, Nexla is also instrumental in managing this information. You can utilize Nexla to combine multiple fields and create textual data that can be seamlessly passed as input to LLMs, improving the quality of your model’s output.

You can learn more about Nexla’s functionality by starting on this page.

Use cases

LLMs are used in many different ways. Here are the most common use cases:

  1. Chatbots: LLMs can be used as chatbots, with their behavior tailored to specific needs. By using system prompts or fine-tuning, you can reshape the model’s behavior to act as a virtual coach, assist in essay writing, answer customer service questions, and more. This flexibility is invaluable for enhancing user experiences and providing personalized interactions.
  2. NLP tasks: LLMs are adept at a multitude of NLP tasks, including summarization, translation, multi-step reasoning, and essay generation.
  3. Data generation: Generative models powered by LLMs can create synthetic data that closely resembles real-world information. Nexla can be used as a data management platform to store and organize this generated data efficiently. This combination of data generation and management is particularly beneficial for training AI models, ensuring data privacy while facilitating research and analysis.


As “auto-magical” as chatbots may seem to end-users, they come with their own challenges for their operators, especially in large enterprise environments. Here are some of them.

Memory constraints

Due to their enormous size—ranging from 3 billion parameters to over a trillion—LLMs are difficult to fit into memory, resulting in the need for innovative solutions to reduce the amount of space they require. Currently, best practices involve using 4- or 8-bit memory storage to load models into either the CPU or GPU. This is effective because model parameters are stored as 32-bit decimals, which translates to having 23 digits after the decimal. However, anyone multiplying 0.000000004 * 0.00000000002 can tell you that this is essentially zero, so most of those additional digits are unnecessary. The goal of 4-bit and 8-bit is to remove most of these extra digits. 

During training, PEFT is used to reduce the amount of memory needed to update the model’s parameters to better perform on a specific task. 

While these strategies help reduce the vast memory requirements to train and use LLMs, they do not eliminate them fully. Additional work is needed to make LLMs more accessible on inexpensive hardware.

Load time

The large size of LLMs also means that they are slow to load onto CPUs or GPUs to begin with. Even today, it can still take several minutes for a comparatively smaller 7 billion parameter model to load onto a GPU. In an age where customers demand instantaneous results, slow loading times can be a serious threat to product acceptance.

Hardware accessibility

Running LLMs requires specialized hardware: high-end GPUs like NVIDIA’s A100s and H100s. Due to the enormous demand for these hardware resources, they are both scarce and expensive.

Confabulation and misinformation

While LLMs possess an impressive ability to generate human-like text, they are not immune to errors. One concerning challenge is their propensity to make up information, a phenomenon sometimes called “hallucination.” This issue becomes particularly troublesome due to the high confidence and authority with which LLMs present information. Unwary users could easily accept these falsehoods as truth, leading to the spread of misinformation.

Limited task generalization

Despite their remarkable capabilities, LLMs tend to perform exceptionally well only on tasks for which they have been explicitly trained or those that are closely related. Currently, prompt engineering and instruction tuning are used as methods to extend the functionality of LLMs.

Prompt engineering was described earlier in the article. Instruction tuning (also discussed above) extends this framework by training the model on a wide variety of different tasks so that it can learn how to follow a wide variety of instructions. However, while these two techniques are fairly effective, there is a limit to how effectively LLMs can generalize to entirely new tasks. This limitation underscores the need for continued research and development to enhance their adaptability.

Discover the Transformative Impact of Data Integration on GenAI



LLMs have taken the world by storm. Their incredible human-like ability to learn information, synthesize it, and then produce answers to questions has been dramatically augmented after just a few years of rapid gains in research and development. It presents massive opportunities for the creation of chatbots, summarizers, translators, multi-step reasoners, data generators, and more. 

However, they still pose limitations and challenges for enterprises, including their size, tendency to make up information, privacy and security, learning curve, and more. Your enterprise can maximize the capabilities of modern LLMs using techniques like prompt engineering, fine-tuning, PEFT, and effective data management.

Like this article?

Subscribe to our LinkedIn Newsletter to receive more educational content

Subscribe now