Generative AI, LLM Architecture, and Specification-Driven Software Development
Course Overview and Assessment Structure
- Assessment Weighting for Generative AI Project:
- ≈50% of the deliverable grade is based on the application/website built using generative AI.
- ≈50% of the deliverable grade is based on lab explanations, where students must demonstrate comprehension of the generated code and explain architectural adjustments under modified scenarios.
- Policy on Assessment Tools:
- AI tools are explicitly prohibited for Deliverable 2 to ensure students build fundamental programming knowledge.
Fundamentals of Large Language Models (LLMs)
- Definition of an LLM:
- A Large Language Model is a sophisticated mathematical function designed to predict the most likely subsequent token or word for any given input sequence of text.
- Token Prediction Mechanics:
- The model assigns a dynamic probability distribution across all potential words in its vocabulary rather than selecting a single next word with absolute certainty.
- Chatbot Simulation Architecture:
- A template script is constructed representing a dialogue between a user and a hypothetical AI assistant.
- The user prompt is appended to the dialogue context.
- The LLM repeatedly predicts the next word expected from such an assistant.
- The generated output is incrementally appended to the script and displayed to the user.
- Determinism vs. Randomness:
- The underlying mathematical parameters of an LLM are completely deterministic.
- Variability in responses across identical prompts stems from non-deterministic sampling algorithms that deliberately select lower-probability words at random to make output sound natural.
- Training Scale and Corpus Volume:
- Models are trained by ingesting massive datasets scraped primarily from the public internet.
- GPT-3 Reading Baseline: A human reading continuously 24/7 without stopping would require over 2,600years to read the volume of text used to train GPT-3. Newer, larger models utilize substantially bigger training corpora.
- Parameters and Weights:
- Model behavior is governed by continuous continuous numerical values termed parameters or weights.
- Modern large language models possess hundreds of billions of parameters (>100,000,000,000).
- Parameters are initialized randomly, causing untrained models to produce gibberish.
- Optimization via Backpropagation:
- Training examples range from a few words to thousands of tokens.
- The model receives all tokens of an example except the final word and generates a prediction.
- The backpropagation algorithm compares the predicted probability against the true target word and updates all parameter weights to increase the probability of the correct word while decreasing the probabilities of incorrect words.
- Executed across trillions of training samples, backpropagation enables the model to generalize predictions to novel, unseen text sequences.
- Computational Scale:
- If an execution unit could perform 1,000,000,000 (1×109) additions and multiplications per second, completing the training calculations for the largest language models would require well over 100,000,000years (1×108years).
- Training relies on specialized hardware such as Graphics Processing Units (GPUs) optimized for massive parallel arithmetic operations. Global demand for AI hardware has significantly driven up computer hardware costs.
- Post-Training Alignment:
- Pretraining: The initial phase focused exclusively on predicting the next token across raw internet text.
- Reinforcement Learning with Human Feedback (RLHF): Secondary training phase where human evaluators flag unhelpful, inaccurate, or problematic predictions to refine parameters toward helpful assistant behavior.
- Sequential vs. Parallel Processing:
- Prior to 2017, language models processed text sequentially, analyzing input one word at a time.
- In 2017, researchers at Google introduced the Transformer architecture, which processes all input tokens simultaneously in parallel.
- Vector Embeddings:
- Because optimization algorithms operate strictly on continuous continuous values, each input word is associated with a high-dimensional vector (a long list of numbers).
- These continuous numbers mathematically encode semantic properties and word meanings.
- The Attention Mechanism:
- Attention allows all numerical word vectors in a sequence to dynamically exchange context and adjust their representations simultaneously.
- Example: The continuous values encoding the word "bank" are dynamically modified by surrounding tokens to explicitly represent a "riverbank" rather than a financial institution.
- Feed-Forward Neural Networks:
- Interleaved layers within the transformer that expand the model's operational capacity to retain complex linguistic patterns acquired during pretraining.
- Emergent Behavior and Explainability:
- Data flows through multiple repeating cycles of attention and feed-forward operations until a final transformation layer acts on the final sequence vector to output next-word probabilities.
- Specific output decisions represent an emergent phenomenon resulting from billions of interacting parameters, making exact interpretability and causality extremely difficult to trace.
Architectural Progression: LLMs, Workflows, and Autonomous Agents
- Standalone LLM Characteristics:
- Generates statistically plausible text based strictly on provided prompt context and weights.
- Isolated from external environments, databases, and APIs by default.
- Example: Asking an unintegrated LLM to draft a mentor email works via internal probability models. Asking it to check personal calendar availability fails or results in hallucination due to a lack of calendar data access.
- AI Workflows:
- Sequences of automated programmatic steps where an LLM is integrated with external tools (e.g., calendars, databases, software APIs).
- The LLM ingests external context, processes data, and suggests or executes specific outputs.
- Control Structure: The human user remains the central decision-maker who crafts prompts, evaluates outputs, and manually initiates iteration loops.
- Autonomous AI Agents:
- Systems configured with an overarching goal that independently plan and execute tasks without continuous step-by-step human intervention.
- Operates on the ReAct (Reason and Act) framework, also described as the Think, Act, Observe loop:
- Think: The agent reasons about the current goal state.
- Act: The agent invokes an external tool or generates an intermediary solution.
- Observe: The agent evaluates the results of its action, often leveraging secondary specialized LLMs for evaluation.
- Loop: The agent determines whether to terminate or repeat the cycle to refine its output.
- Control Structure: The LLM functions as the primary operational decision-maker.
Failure Modes, System Risks, and Operational Bottlenecks
- Context Float and Window Exhaustion:
- Continuous agent execution expands the prompt history context size during repetitive loops.
- Reaching context window limits leads to resource exhaustion, elevated token costs, or forced shifting context windows that truncate critical early instructions.
- Infinite Loops:
- Agents can enter unproductive feedback cycles where evaluation criteria are never satisfied, causing unending task iteration.
- Hallucinations:
- The inherent predictive nature of LLMs can generate non-existent facts, invalid code syntax, or false parameters that appear plausible.
- Error Cascades:
- An uncorrected error or hallucinated output generated in early iteration loops is accepted as fact in subsequent steps, compounding errors and corrupting the final solution.
- Tool Misallocation:
- Agents may invoke incorrect tools or API endpoints if tool descriptions provided to the model lack sufficient clarity or context.
- Economic Realities of AI Operations:
- Iterative token consumption rapidly accelerates operational costs.
- Assumptions that AI completely eliminates software engineering labor costs are failing as compute costs equal or exceed developer salaries, prompting a resurgence in developer hiring.
Generative Multimodal AI and Industry Implications
- Multimodal Expansion:
- Generative AI spans text, source code, static images, audio, and high-fidelity synthetic video.
- Synthesis Quality Evolution:
- Video synthesis shifted from early low-quality rendering (e.g., historical viral footage of Will Smith eating spaghetti) to photorealistic visual/audio generation and synthetic gameplay creation (e.g., simulated Fortnite Victory Royale footage).
- Audio tools enable style-transferred musical compositions (e.g., rendering gospel covers of 50 Cent tracks).
- Legal and Ethical Bottlenecks:
- Widespread deployment faces severe challenges regarding Intellectual Property (IP) infringement, training data provenance, copyright ownership, and environmental compute overhead.
AI-Assisted Coding Paradigms and Vibe Coding
- Coding Tooling Spectrum:
- Ranges from simple inline syntax autocomplete to autonomous development environments that scaffold, test, and deploy full applications (e.g., GitHub Copilot, Cursor, Bolt.new).
- Code Volume vs. Productivity Paradox:
- Generating vast quantities of code does not directly equate to software productivity. Uncritical reliance on autocomplete engines significantly increases bug density in repositories.
- The Vibe Coding Methodology:
- A development paradigm where software is built exclusively by directing AI using natural language prompts without writing manual line-by-line source code.
- Debugging occurs by re-prompting the AI agent to alter behavior or modify code rather than inspecting implementation logic directly.
Questions & Discussion: Trade-offs of Vibe Coding
- Pros of Vibe Coding:
- Accessibility: Allows non-technical individuals to build functional digital products without software development experience.
- Execution Speed: Rapid prototyping capabilities (e.g., generating a complete 4-page operational website in ≈2minutes).
- Short-term Cost Reductions: Bypasses immediate software development contracting costs for small-scale applications.
- Cons of Vibe Coding:
- Lack of Quality Assurance: Non-programmers cannot detect structural flaws, hidden runtime bugs, or unhandled exceptions generated by the AI.
- Negligible Skill Acquisition: Users do not develop foundational mental models of computer science or program execution.
- Maintenance Trade-offs: Prioritizes rapid short-term creation over long-term software maintainability.
- Subscription Lock-in: Heavy dependence on proprietary software platforms leads to long-term financial costs.
- Security Vulnerabilities: Generative engines typically fail to incorporate security controls against vulnerabilities like Cross-Site Scripting (XSS) or SQL Injection unless explicitly instructed in the input specifications.
- Skill Atrophy: Experienced engineers risk losing core coding competencies through over-reliance on automated tools.
Specification-Driven Development (SDD)
- Industry Paradigm Shift:
- Major technology organizations (e.g., Microsoft, Amazon, IBM, Galliers) are shifting software engineering processes toward Specification-Driven Development (SDD).
- Raw AI code generation creates bottlenecks in testing and integration; SDD solves this by embedding AI across the full Software Development Life Cycle (SDLC).
- Definition of SDD:
- A software development methodology where a formal, comprehensive implementation specification is authored, validated, and agreed upon prior to code generation.
- Core SDD Lifecycle Stages:
- Capturing Intent:
- Defines core business objectives, user requirements, and functional requirements.
- Requirements must be recorded in structured, machine-readable formats.
- Translating Intent into System Blueprints:
- Converts intent into formal technical specs, high-level architectures, domain models, explicit API contracts, and UML structural diagrams.
- Establishes the single source of truth for the project.
- Generating Work Units:
- Decomposes blueprints into modular, executable development task units to ensure cross-team alignment.
- Implementing and Validating:
- AI agents write source code strictly constrained by the specification blueprints.
- Human engineers validate outputs using manual inspection and automated test suites to resolve discrepancies immediately.
- Demonstration Workflow (Microsoft Copilot Application Generation):
- Step 1: Prompted Copilot to generate a formal specification for a lawn care business website located in Hamilton, New Zealand.
- Step 2: The engine outlined target audiences, site structures, and page specifications (covering residential, commercial, edge trimming, and scheduled garden maintenance).
- Step 3: Iterated on the specification document by adding real-time appointment booking functionality.
- Step 4: Instructed Copilot to build the application, resulting in a minified functional web application (React framework) within minutes.
- Observation: The generated output required human inspection to supply missing operational metadata (e.g., localized contact numbers).
Comprehensive Strengths, Limitations, and Future Outlook
- Strengths of Generative AI Systems:
- High-speed, high-volume boilerplate generation.
- Adherence to rigid structural formats and code templates.
- Multilingual translation capabilities (e.g., rendering code and interface specifications in te reo Māori).
- Automated text editing, document restructuring, and architectural diagram generation.
- Brainstorming and ideation (e.g., rapidly generating novel business models).
- Inherent Limitations:
- Original Insight: Incapable of generating novel concepts outside the parameter distributions acquired from training data.
- Quality and Impact Judgment: Lacks contextual awareness to evaluate structural code quality or real-world strategic fit.
- Systemic Bias: Replicates biases present in pretraining datasets.
- Domain Expertise Gaps: Suffers significant performance drops when applied to niche domain topics with sparse training data.
- Impact on Engineering Employment:
- Junior/entry-level developer positions faced initial market displacement due to automation of routine syntax tasks.
- Senior roles requiring domain expertise, architectural system design, and security verification remain critical.
- Software development is shifting toward managing AI agents, authoring formal specifications, and auditing software safety.