tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Large Language Models > What is a Large Language Model (LLM)

What is a Large Language Model (LLM)

Author: Venkata Sudhakar

A Large Language Model (LLM) is a type of artificial intelligence model trained on massive amounts of text data to understand and generate human language. LLMs learn statistical patterns across billions of words, sentences, and documents, enabling them to perform tasks such as text generation, summarisation, translation, question answering, and code writing without being explicitly programmed for each task.

LLMs are built on the Transformer architecture, introduced by Google in 2017. They use a mechanism called self-attention to weigh the importance of each word in a sequence relative to all other words, allowing the model to capture long-range dependencies and context. Modern LLMs such as GPT-4, Claude, Gemini, and LLaMA contain billions to hundreds of billions of parameters - numerical weights learned during training that encode knowledge about language and the world.

Interacting with an LLM is done by sending a prompt, which is a piece of text that instructs the model what to do. The model then predicts the most likely continuation of that text, token by token. A token is roughly 4 characters or 0.75 words. The below example shows how to call an LLM using the OpenAI Python SDK to get a simple completion.


It gives the following output,

The capital of France is Paris.

LLMs support a system prompt (which sets the model behaviour and persona) and a user prompt (the actual question or task). You can chain multiple messages to simulate a conversation. The below example shows how to use multi-turn conversation history and control output length using max_tokens.


It gives the following output,

Sure! Here is a simple example:

List names = Arrays.asList("Alice", "Bob", "Charlie");
names.forEach(name -> System.out.println(name));

Tokens used: 97

The temperature parameter controls how creative or deterministic the output is. A value of 0.0 makes the output fully deterministic (always the same answer), while higher values like 1.0 or 1.5 make it more varied and creative. The below example shows how changing temperature affects the output for the same prompt.


It gives the following output,

Low temp (0.1): "Your daily dose of warmth and energy."
High temp (1.5): "Where every sip is a tiny adventure for your soul!"

 
  


  
bl  br