How to Control LLM Output Randomness with Temperature in Python

In this post, we'll briefly learn what temperature is in the context of large language models, how it controls the randomness of generated text, and how to set it correctly for different tasks in Python. The tutorial covers:

  1. What is Temperature?
  2. How Temperature Works
  3. Installation and Setup
  4. Comparing Temperature Values Side by Side
  5. Low Temperature for Factual and Structured Tasks
  6. High Temperature for Creative Tasks
  7. Temperature and Top-p Sampling
  8. Choosing the Right Temperature
  9. Conclusion

Let's get started.

How to Use System Prompts to Control LLM Behavior

In this post, we'll briefly learn what a system prompt is, why it is the most powerful lever for controlling LLM behaviour, and how to craft effective system prompts for a variety of real-world scenarios in Python. The tutorial covers:

  1. What is a System Prompt?
  2. How System Prompts Work
  3. Installation and Setup
  4. Setting Tone and Persona
  5. Constraining the Output Format
  6. Restricting the Topic Domain
  7. Controlling Response Length and Style
  8. Chaining System and Few-Shot Prompts
  9. Conclusion

Let's get started.

How to Run a Local LLM in Python with Ollama

In this post, we'll briefly learn what Ollama is, how to set it up, and how to run a local large language model (LLM) entirely on your own machine using Python. The tutorial covers:

  1. What is Ollama?
  2. Installation and Setup
  3. Pulling a Model
  4. Basic Chat Completion
  5. Streaming Responses
  6. Multi-turn Conversation
  7. Generating Embeddings
  8. Using the OpenAI-Compatible API
  9. Conclusion

Let's get started.

Semantic Text Similarity with LLM Embeddings in Python

In this post, we'll briefly learn what Semantic Text Similarity is, how LLM Embeddings enable it, and how to measure the semantic closeness between sentences in Python. The tutorial covers:

  1. What is Semantic Text Similarity?
  2. What are LLM Embeddings?
  3. Installation
  4. Loading an Embedding Model
  5. Cosine Similarity Between Two Sentences
  6. Ranking Sentences by Similarity
  7. Batch Similarity with a Query
  8. Similarity Heatmap for a Sentence Set
  9. Conclusion

Let's get started.

How to Use Hugging Face Transformers Pipeline in Python

In this post, we'll briefly learn what the Hugging Face Transformers pipeline is, how it works, and how to apply it to common NLP tasks in Python. The tutorial covers:

  1. What is the Transformers Pipeline?
  2. Installation
  3. Pipeline Task Overview
  4. Text Classification
  5. Text Generation
  6. Question Answering
  7. Named Entity Recognition
  8. Conclusion
  9. Source Code Listing

Let's get started.

LLM Embeddings – A Practical Introduction in Python

    In this post, we'll briefly learn what LLM embeddings are, how they work, and how to generate and use them in Python. The tutorial covers:

  1. What are Embeddings?
  2. How LLMs Generate Embeddings
  3. Types of Embeddings
  4. Generating Embeddings with Sentence Transformers
  5. Generating Embeddings with OpenAI API
  6. Measuring Semantic Similarity
  7. Visualizing Embeddings with TSNE
  8. Conclusion
  9. Source Code Listing

     Let's get started.