2.1.2. š” First Principle: Tokens, Embeddings, and Prompt Engineering
First Principle: Generative AI models don't "understand" words directly; they process language by breaking it into numerical tokens, representing their meaning as mathematical embeddings, and are guided by carefully crafted prompts.
These are the core mechanics of how we interact with LLMs.
- Tokens: LLMs don't see words; they see tokens. A token is a common sequence of characters. It can be a whole word (like "apple"), a part of a word (like "ing" in "running"), or a punctuation mark. The text you send to an LLM is first broken down into a sequence of tokens.
- Importance: The cost of using LLMs is often based on the number of tokens processed.
- Embeddings: An embedding is a numerical representation of a token or a piece of text in the form of a vector (a list of numbers). This vector captures the semantic meaning of the text. Words with similar meanings will have similar embedding vectors.
- Importance: Embeddings are what allow the model to understand context and relationships between words. They are also fundamental to technologies like semantic search.
- Prompt Engineering: The art and science of designing effective inputs (prompts) to guide a generative AI model to produce the desired output. A well-designed prompt can dramatically improve the quality, relevance, and accuracy of the model's response.
- Importance: The quality of your output is directly dependent on the quality of your input prompt.
Scenario: A team is getting poor, generic responses from an LLM. They are simply asking, "Write about our product."
Reflection Question: How would you use the concept of prompt engineering to advise them to create a better prompt? For example, by providing context, giving examples, and clearly defining the desired format for the output.
š” Tip: Prompting is the new way of "programming" generative AI models. A good prompt is like good code: clear, specific, and provides all necessary context.