Saturday, 18 January 2025

Hour 6 - Overview of Models

Lecture Notes: 


1. Concepts

What is a Model in Machine Learning?

  • A model is a computational representation of a process used to make predictions or generate insights based on input data.
  • In the context of language models, such as those used in Ollama, a model generates text or embeddings based on input prompts.

Key Components of a Model:

  1. Architecture: Defines the structure of the model (e.g., transformers like GPT, BERT).
  2. Parameters: Determines the model's capacity to learn from data (e.g., number of neurons, layers).
  3. Weights: Encoded knowledge the model learns during training.
  4. System Prompt: A predefined instruction guiding the model’s behavior.
  5. Fine-Tuning: Adjusting the model for a specific task by retraining on a domain-specific dataset.

2. Key Aspects

Types of Models in Ollama:

  1. Pre-trained Models: Models trained on large datasets for general-purpose tasks.
    • Example: GPT, Llama, Mistral.
  2. Fine-Tuned Models: Pre-trained models further trained on specific datasets for specialized tasks.
    • Example: A chatbot fine-tuned for customer service.
  3. Custom Models: Created by users with specific system prompts, templates, or datasets.

Why Use Models in Ollama?

  • Enable text generation, summarization, translation, embedding generation, and more.
  • Provide flexibility through CLI for creating, modifying, and deploying models.

3. Implementation

CLI Commands for Working with Models

Command Description Example
ollama run Run a model to generate text based on a prompt. ollama run llama --prompt "Hello!"
ollama create Create a custom model from a base model. ollama create mymodel -f ./modelfile
ollama pull Download a model from Ollama’s repository. ollama pull llama
ollama show Display details of a model. ollama show llama
ollama ls List all available models locally. ollama ls
ollama rm Remove a model. ollama rm llama
ollama cp Copy a model (e.g., for renaming). ollama cp llama llama_custom

4. Real-Life Example

Scenario: Customizing a Model for Technical FAQs

Imagine creating a custom model to answer FAQs for a software company.

  • Base Model: Llama 2.
  • Customization: Add a system prompt that aligns the model with the company’s tone and expertise.

5. Code Examples

Step 1: Pull the Base Model

Download a base model to use as the foundation for your customization.

# Pull a model from Ollama's repository
ollama pull llama

Step 2: Create a Custom Model

Define the behavior of your custom model in a modelfile.

Modelfile (modelfile.txt):

FROM llama
SYSTEM """
You are a technical support assistant for Acme Software.
Provide concise and accurate answers to customer queries.
"""

Use the ollama create command to generate the model.

# Create a custom model
ollama create acme_support -f ./modelfile.txt

Step 3: Run the Custom Model

Test your custom model by running it with a prompt.

# Run the custom model
ollama run acme_support --prompt "What are the system requirements for Acme Pro 3.0?"

Step 4: Show Model Details

Inspect the properties of the newly created model.

# Display model details
ollama show acme_support

6. Example Output

Input Prompt:

"What are the system requirements for Acme Pro 3.0?"

Model Response:

"Acme Pro 3.0 requires Windows 10 or later, 8GB RAM, and 20GB of free disk space. For macOS, it supports version 11.0 or newer."


7. Summary

  • Concepts Covered: Overview of models, their types, and customization in Ollama.
  • Key Aspects: Pre-trained, fine-tuned, and custom models, along with the CLI commands.
  • Implementation: Demonstrated creating, running, and inspecting models.
  • Real-Life Example: Built a custom technical support model.

8. Homework/Practice

  1. Pull a base model and test its default behavior.
  2. Create a custom model with a system prompt of your choice.
  3. Run your custom model to answer specific questions.
  4. Experiment with fine-tuning a model by modifying the modelfile or adding new training data.

This lecture provides a solid foundation in understanding and working with models in Ollama, emphasizing practical usage with CLI commands and real-life applications.

No comments:

Post a Comment

OpenWebUI - Beginner's Tutorial

  OpenWebUI Tutorial: Setting Up and Using Local Llama 3.2 with Ollama Introduction This tutorial provides a step-by-step guide to setting...