MTI TEK
  • Home
  • About
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All Resources
LLMs | Introduction
  1. Introduction
  2. Representation Models (Encoder-Only)
  3. Generative Models (Decoder-Only)
  4. Encoder-Decoder Models
  5. LLMs Tasks Categories
  6. Creating a Language Model

  1. Introduction
    Large Language Models (LLMs) are a class of AI models designed to understand, generate, and interact with human language. These models are built to interact with language in human-like ways (e.g., answering questions, writing essays, holding conversations). Built on the Transformer architecture, LLMs are trained on massive text corpora and learn to capture complex linguistic patterns, semantics, and contextual relationships within language. These models consist of neural networks with billions of parameters — numeric values that capture the model's understanding of language. During training, these parameters are adjusted to optimize performance on language-specific tasks.

    Types of LLMs:
    • Representation Models (Encoder-Only)
    • Generative Models (Decoder-Only)
    • Encoder-Decoder Models

    Applications of LLMs:
    • Text generation: Creative writing, content generation, code completion.
    • Text classification: Spam detection, sentiment analysis.
    • Text clustering: Organizing unstructured data.
    • Semantic search: Context-aware information retrieval, question answering.
    • Summarization: Document and content summarization.
  2. Representation Models (Encoder-Only)
    • Function: Designed for understanding and encoding language rather than generating it.
    • Architecture: Encoder-only Transformer architecture.
    • Model type: Sequence-to-vector (for classification) or sequence-to-sequence (for token-level tasks).
    • Use case: Takes an input sequence and produces a classification, embedding, or other representations.

    These models are commonly used in:
    • Text classification and sentiment analysis.
    • Named entity recognition (NER).
    • Text embeddings and similarity tasks.

    Examples of representation models:
    • BERT (Bidirectional Encoder Representations from Transformers) – Open-source: 110M-340M parameters
    • RoBERTa (Robustly Optimized BERT Pretraining Approach) - Open-source: 125M-355M parameters
    • DeBERTa (Decoding-enhanced BERT with Disentangled Attention) - Open-source: 140M-1.5B parameters
    • DistilBERT - Open-source: 66M parameters (distilled version of BERT)
  3. Generative Models (Decoder-Only)
    • Function: Focused on generating coherent and contextually relevant text.
    • Architecture: Decoder-only Transformer architecture.
    • Model type: Sequence-to-sequence (autoregressive generation).
    • Use case: Takes a text input (prompt) and generates a text output (completion).

    These models are prompt-driven and require clear instructions to produce useful responses. They are not typically task-specific but can be fine-tuned for specific applications.

    These models are commonly used in:
    • Conversational AI and chatbots
    • Code generation and programming assistance
    • Creative writing and content creation
    • Reasoning and problem-solving tasks

    Examples of generative models:
    • LLaMA 3 (Large Language Model Meta AI) - Meta AI - Open-source: 8B-70B parameters
    • GPT-4 (Generative Pre-trained Transformer) - OpenAI - Proprietary: ~1.8T parameters (estimated)
    • Gemini - Google - Proprietary: Multiple variants (Ultra, Pro, Nano)
    • Claude - Anthropic - Proprietary: Multiple variants (Opus, Sonnet, Haiku)
    • Mistral - Mistral AI - Open-source: 7B-8x7B parameters
  4. Encoder-Decoder Models
    • Function: Combine the strengths of both understanding (encoding) and generation (decoding).
    • Architecture: Full Transformer (encoder + decoder stacks).
    • Model type: Sequence-to-sequence.
    • Use case: Effective for tasks that need both comprehension and generation, like translation, summarization, and question answering.

    These models are commonly used in:
    • Translation
    • Text summarization
    • Question answering

    Examples of encoder-decoder models:
    • T5 (Text-to-Text Transfer Transformer) – Google: 220M-11B parameters
    • mT5 (multilingual T5) – Google: 300M-13B parameters
    • BART (Bidirectional and Auto-Regressive Transformers) – Facebook: 140M-400M parameters
  5. LLMs Tasks Categories
    • Generative AI
      Any AI that creates new content (text, code, images). Includes all text generation tasks:
      • Completion
        • Use case: Code completion, writing assistance, autocomplete.
        • Example: "The weather today is" → "The weather today is sunny".
      • Chat / Conversation
        • Use case: Chatbots, virtual assistants, customer service.
        • Example: Q&A with follow-ups, maintaining conversation history and context.
      • Instruction Following
        • Use case: Task automation, content processing, specific task completion.
        • Example: "Summarize this article in 3 sentences" or "Write a Python function to sort a list".
    • Non-Generative Tasks
      • Classification
        • Categorize input into predefined labels.
        • Example: Text → positive/negative/neutral sentiment.
      • Embedding/Encoding
        • Convert text to numerical vectors (dense representations).
        • Use case: Semantic search, RAG systems, similarity matching.
      • Named Entity Recognition (NER)
        • Extract and classify entities from text.
        • Example: Extract person names, locations, organizations, dates.
      • Question Answering
        • Extract or generate answers from given context.
        • Example: Context + Question → Specific answer span or generated response.

    Depending on the task type, different models are more suitable:
    • Classification / Named Entity Recognition (NER) → BERT-family models (e.g., RoBERTa, DistilBERT, DeBERTa)
    • Summarization / Translation → T5, mT5, BART
    • Chat / Code Generation / Instruction Following → LLaMA, GPT-4, Claude, Mistral
    • Embeddings → SentenceTransformers (e.g., all-MiniLM-L6-v2), or BERT for contextual embeddings
    • Retrieval-Augmented Generation (RAG) → Embedding models for retrieval + Generative models for response generation
  6. Creating a Language Model
    • Pre-training
      This is the initial phase where a model learns the structure and patterns of language from a large, diverse dataset.

      Characteristics:
      • Produces foundation models (also called base models).
      • Learns syntax, semantics, world knowledge, and reasoning patterns.
      • Focuses on next-token prediction (for generative models) or masked language modeling (for encoder models).
      • Utilizes unsupervised learning techniques on unlabeled text data.
      • Requires extensive computational resources (GPUs, TPUs, large memory, distributed training).
      • Requires vast amounts of data (typically hundreds of billions to trillions of tokens).
      • Requires significant training time (weeks to months).

    • Fine-tuning
      This step customizes the pre-trained model for specific tasks, domains, or behaviors.

      Types of fine-tuning:
      • Supervised Fine-tuning (SFT): Uses labeled datasets for specific tasks.
      • Instruction Tuning: Trains models to follow human instructions and prompts.
      • Reinforcement Learning from Human Feedback (RLHF): Aligns model outputs with human preferences.

      Characteristics:
      • Produces task-specific or instruction-following models.
      • Involves supervised learning with smaller datasets.
      • Consumes fewer resources compared to pre-training.
      • Shorter training times (hours to days).
      • Enables models to follow instructions.

    Training Techniques
    • Supervised Learning:
      Uses labeled data for tasks like classification and regression.
      Example: Sentiment analysis where text is labeled as positive, negative, or neutral.

    • Unsupervised Learning:
      Uses unlabeled data for discovering patterns and structure.
      Example: Next-token prediction, masked language modeling, or learning text representations.

    • Masked Language Modeling (MLM)
      • Key technique for training representation models like BERT.
      • Randomly masks tokens in input text.
      • The model learns to predict the masked tokens based on bidirectional context.

      Example:
      Input: "[CLS] LLMs are large [MASK] models [SEP]"
      Target: language
      Output: The model predicts "language" for the [MASK] token
    • Autoregressive Language Modeling
      • Key technique for training generative models like GPT.
      • Predicts the next token in a sequence given previous tokens.

      Example:
      Input: "The weather today is"
      Model predicts: "sunny" (next most likely token)
      Then: "The weather today is sunny"
      Model predicts: "and"
      Then: "The weather today is sunny and"
© 2025 mtitek