Artificial Intelligence and Expert System

Chapter 9
Neural Networks, Deep Learning, and Generative AI

Post Graduate Program in Computer Science Engineering
Artificial Intelligence and Expert System   •   Post Graduate

9. Neural Networks, Deep Learning, and Generative AI

Introduction and Context

Artificial neural networks have become a central approach to artificial intelligence because they can learn useful representations directly from data. Earlier expert systems relied mainly on explicitly encoded rules and symbolic reasoning. Neural systems instead learn parameters from examples, making them particularly effective when the relevant rules are difficult to state formally—for example, recognizing objects in images, transcribing speech, or predicting the next word in a sentence.

The contemporary development of deep learning has been enabled by large datasets, specialized hardware, improved optimization algorithms, and advances in network architecture. Convolutional neural networks transformed computer vision; recurrent and sequence models supported speech and language processing; and transformer architectures established a general foundation for modern large language models. Generative AI extends these capabilities by producing text, images, code, audio, and other forms of content.

These technologies are powerful but not infallible. Their outputs depend on data quality, objective functions, architecture, deployment context, and human oversight. A postgraduate understanding therefore requires more than knowing how to train a model. It requires the ability to select an architecture, evaluate representations, manage risks, design reliable applications, and understand the organizational consequences of automation.

Learning Objectives

After studying this chapter, students should be able to:

1. Explain the structure and learning process of artificial neural networks.

2. Distinguish representation learning, deep learning, supervised learning, self-supervised learning, and transfer learning.

3. Compare convolutional, recurrent, attention-based, and transformer architectures.

4. Describe foundation models, large language models, prompting, retrieval-augmented generation, and fine-tuning.

5. Design an appropriate workflow for developing and evaluating a generative AI application.

6. Diagnose overfitting, distribution shift, hallucination, bias, and other deployment risks.

7. Apply technical, ethical, and governance principles to real-world AI systems.

From Artificial Neurons to Learned Representations

An artificial neuron computes a weighted combination of inputs and passes the result through an activation function:

`z = w^T x + b`, followed by `a = f(z)`.

Here, `x` is an input vector, `w` is a vector of learnable weights, `b` is a bias, and `f` is an activation function. A layer contains many such units, and a multilayer network composes several transformations. The first layers may detect simple patterns, while later layers combine them into increasingly abstract features.

Common activation functions include the sigmoid, hyperbolic tangent, rectified linear unit (ReLU), and its variants. ReLU, defined as `max(0,z)`, is computationally simple and reduces some difficulties associated with vanishing gradients. The softmax function is commonly used in the output layer for multiclass classification because it converts scores into a probability distribution.

Training normally involves three stages. In the forward pass, the network maps inputs to predictions. A loss function measures disagreement between predictions and target values. During backpropagation, the chain rule computes gradients of the loss with respect to the parameters. An optimization algorithm, such as stochastic gradient descent or Adam, updates those parameters. Repeated passes through training data are called epochs.

A network does not merely memorize labels when it learns a useful representation. It transforms raw observations into features that make the target task easier. Representation learning is therefore a major conceptual contribution of neural methods. In a speech system, for example, early transformations may capture acoustic regularities, while later representations encode phonetic, lexical, and semantic information.

The distinction between parameters and hyperparameters is important. Parameters are learned from data; hyperparameters—such as learning rate, batch size, depth, dropout rate, and regularization strength—are selected by the practitioner. Training, validation, and test sets should be separated so that model selection does not quietly contaminate final evaluation.

Deep Learning as Hierarchical Function Approximation

Deep learning refers broadly to neural models with multiple learned layers. Depth allows a model to represent complex functions through compositions of simpler functions. This often reduces the need for manual feature engineering, although domain knowledge remains important for data collection, target definition, evaluation, and system design.

A model with excessive capacity may fit noise in the training data. This is overfitting, reflected by strong training performance but weaker validation or test performance. Regularization methods include weight decay, dropout, data augmentation, early stopping, and reduction of model complexity. Underfitting occurs when the model cannot capture the relevant structure, perhaps because it is too small, poorly optimized, or trained on inadequate features.

Generalization is affected by distribution shift: the deployment data may differ from the training distribution. A medical model trained at one hospital may encounter different equipment, patient populations, or documentation practices elsewhere. Accuracy on a randomly held-out test set does not guarantee robustness under such shifts. Evaluation should therefore include subgroup analysis, stress testing, temporal validation, and, where possible, prospective monitoring.

Transfer learning addresses the cost of training large models from scratch. A model pretrained on a broad dataset can be adapted to a narrower task. This is useful when labeled task-specific data are limited. Self-supervised learning is especially important because it obtains training signals from the structure of unlabeled data—for example, predicting masked words or missing portions of an image.

Architecture Follows the Structure of the Data

Convolutional Neural Networks

Convolutional neural networks (CNNs) exploit local connectivity and repeated patterns. A convolutional filter slides across an image or feature map, producing a response to a learned pattern. Parameter sharing means that the same filter can detect a feature in different locations. Pooling or strided operations reduce spatial resolution and can increase computational efficiency, although they may discard precise positional information.

CNNs have been used for image classification, object detection, segmentation, medical imaging, industrial inspection, and geospatial analysis. Their inductive bias toward locality and translation-related patterns is advantageous for visual data. However, a CNN may require architectural additions or substantial depth to model long-range relationships.

Recurrent and Sequence Models

Recurrent neural networks process sequences by maintaining a hidden state that summarizes earlier inputs. Standard RNNs can suffer from vanishing or exploding gradients when dependencies extend over long intervals. Long short-term memory networks (LSTMs) and gated recurrent units (GRUs) introduce gates that regulate information retention and forgetting.

Recurrent models remain useful in streaming and resource-constrained settings, but sequential computation limits parallelism. This limitation contributed to the rise of attention and transformer architectures.

Attention and Transformers

Attention allows a model to assign different weights to elements of an input when producing a representation. In self-attention, each token is related to other tokens in the same sequence through query, key, and value representations. The resulting weighted combination can capture relationships between distant elements more directly than a conventional recurrent state.

A transformer typically contains repeated attention and feed-forward blocks, residual connections, normalization, and positional information. Multi-head attention enables the model to examine relationships from several learned subspaces. Transformers can process many sequence positions in parallel during training, although attention costs increase with sequence length in standard implementations.

Transformers are not limited to language. Variants are used for vision, audio, multimodal learning, time series, and biological sequences. Their flexibility has made them a general architecture for foundation models.

Foundation Models and Generative Systems

A foundation model is a broadly pretrained model that can be adapted to many downstream tasks. Pretraining usually involves large and diverse data and an objective that encourages general-purpose representations. Adaptation may occur through prompting, supervised fine-tuning, parameter-efficient fine-tuning, or additional task-specific components.

A generative model learns a distribution or a useful approximation of data and can sample new outputs. Autoregressive language models generate one token at a time based on preceding context. Diffusion models generate data by learning to reverse a gradual noising process and are widely used for image and audio generation. Generative adversarial networks consist of a generator and discriminator trained in opposition, although their use has declined in some applications relative to diffusion and transformer-based methods.

A large language model (LLM) is generally a transformer-based model trained on very large text collections. During pretraining, a causal LLM commonly learns to predict the next token. This objective does not explicitly encode truth, intention, or reasoning, but it can produce rich linguistic and coding behavior because language contains extensive structure. Post-training may include supervised instruction tuning and preference optimization to make outputs more useful and aligned with desired behavior.

Model size alone is not a sufficient measure of quality. Data composition, training procedures, inference settings, context length, evaluation design, cost, latency, and safety controls all matter. Smaller specialized models may be preferable where privacy, speed, or domain accuracy is more important than broad capability.

Prompting, Retrieval, and Adaptation

Prompting is the design of instructions and context supplied to a model. A prompt may specify a role, task, constraints, output format, examples, and criteria for uncertainty. Zero-shot prompting provides no examples; few-shot prompting includes demonstrations. Decomposition prompts can ask the model to perform subtasks, although intermediate reasoning should not automatically be treated as reliable evidence.

Effective prompts are precise rather than merely elaborate. They define the source of authority, distinguish instructions from untrusted content, require structured output where appropriate, and state what the model should do when information is missing. Prompt testing should use a representative evaluation set rather than a few impressive examples.

Retrieval-augmented generation (RAG) combines a language model with an external retrieval system. A typical pipeline embeds documents and stores vectors in an index; a user query is embedded and matched to relevant passages; those passages are inserted into the model context; and the model generates an answer grounded in the retrieved material. RAG is valuable when information changes frequently or is proprietary and should not be encoded solely in model parameters.

RAG quality depends on document segmentation, metadata, embedding choice, query rewriting, retrieval depth, reranking, context limits, and citation behavior. Retrieval failure cannot be repaired reliably by generation alone. A production system should evaluate both retrieval recall and answer faithfulness.

Fine-tuning changes model parameters using task-specific examples. Full fine-tuning can be expensive and may cause catastrophic forgetting or data leakage. Parameter-efficient methods such as adapters and low-rank adaptation modify a small portion of the effective parameter space. Fine-tuning is appropriate when the desired behavior, style, or task mapping is stable and sufficiently represented in training data. RAG is often preferable when the principal need is access to changing factual content.

Controlling Hallucinations and Evaluating Reliability

A hallucination is an output that is unsupported, fabricated, or misleadingly confident. In language systems, fluent generation can conceal the absence of evidence. Hallucinations may arise because the model optimizes likely continuation rather than verified truth, because the prompt is ambiguous, because retrieval supplies irrelevant passages, or because the task exceeds the model's competence.

Control is best treated as a system problem rather than a single prompting trick. Useful measures include:

  • grounding responses in authoritative retrieved sources;
  • requiring citations or evidence spans;
  • restricting answers to a defined knowledge base;
  • using structured outputs and schema validation;
  • asking the system to abstain when evidence is insufficient;
  • applying rule-based and model-based verification;
  • routing high-risk cases to human experts; and
  • monitoring errors after deployment.

Evaluation should match the use case. Classification tasks may use precision, recall, F1, calibration, and subgroup performance. Generative systems require measures such as factuality, faithfulness to sources, answer completeness, relevance, toxicity, robustness, latency, and cost. Automatic metrics can be useful screening tools but do not replace expert review for consequential applications.

Calibration is particularly important. A system that knows when it is uncertain is safer than one that presents every answer with equal confidence. However, verbal expressions such as “I am 80 percent confident” are not automatically calibrated probabilities and should not be interpreted as such without validation.

Applications and Professional Practice

Neural and generative systems support medical image analysis, fraud detection, predictive maintenance, recommendation, robotics, translation, accessibility tools, software engineering, scientific discovery, customer support, and document analysis. In organizations, value rarely comes from the model alone. It emerges from integration with data pipelines, user interfaces, workflow controls, identity management, monitoring, and accountability structures.

A professional development lifecycle commonly includes problem formulation, data governance, baseline construction, model selection, training or adaptation, offline evaluation, pilot deployment, human review, monitoring, and iterative improvement. The first question should be whether AI is appropriate for the problem. A deterministic rule, database query, conventional statistical model, or human process may be more reliable and economical.

Managers must evaluate total cost of ownership, including data preparation, inference infrastructure, licensing, cybersecurity, evaluation, retraining, incident response, and workforce adaptation. Technical teams should document data sources, intended use, limitations, evaluation results, model versions, and known failure modes.

Illustrative Case Study: A University Policy Assistant

Background

A university wishes to provide students with an assistant that answers questions about academic regulations, deadlines, examinations, and graduation requirements. The institution has a large collection of policy documents, but policies are revised periodically and differ across programs.

Problem

A general-purpose language model can answer routine questions fluently, but it sometimes invents deadlines or combines rules from different programs. An incorrect answer could cause academic or financial harm.

Analysis

The core requirement is current, traceable access to institutional documents rather than creative text generation. The system must distinguish university-wide rules from program-specific regulations and must handle incomplete or ambiguous student questions.

Approach

The university creates an approved document repository with version dates, program metadata, and access controls. Documents are segmented into semantically coherent passages and indexed for hybrid keyword and vector retrieval. A language model receives the question and retrieved passages through a prompt that requires citations, identifies the applicable program, and instructs the model to abstain when evidence is insufficient. A separate validation layer checks that cited passages exist and that dates in the answer match the retrieved text. Ambiguous or high-impact cases are routed to an academic adviser.

The team evaluates retrieval recall, citation validity, factual accuracy, abstention quality, subgroup performance across programs, response latency, and user satisfaction. It also conducts adversarial tests involving outdated documents, conflicting policies, prompt injection inside uploaded files, and deliberately vague questions.

Outcome

The resulting assistant handles routine, well-supported questions efficiently while directing uncertain cases to humans. Its value comes from document governance, retrieval quality, version control, and escalation design as much as from the language model.

Learning Points

The case illustrates the distinction between model knowledge and authoritative organizational knowledge. It also shows why RAG does not automatically guarantee truth, why metadata and access controls are essential, and why high-impact decisions require accountable human oversight.

Risks, Ethics, and Governance

Neural systems can reproduce historical bias, especially when training data reflect unequal representation or discriminatory decisions. Fairness should be assessed in relation to the application, affected groups, and decision consequences; no single metric is universally correct. Privacy risks include memorization, unauthorized use of personal data, inference of sensitive attributes, and exposure through prompts or logs.

Generative systems also create risks of misinformation, impersonation, copyright conflict, unsafe advice, prompt injection, data exfiltration, and automation bias. Security controls should treat retrieved documents, user inputs, tools, and model outputs as potentially untrusted. Least-privilege access, input and output filtering, audit logs, encryption, red-team testing, and incident response are important safeguards.

Governance should establish ownership, approval thresholds, documentation requirements, monitoring responsibilities, and procedures for correction or withdrawal. Human review must be meaningful: reviewers need adequate expertise, time, authority, and visibility into evidence. Transparency should explain the system's purpose, limitations, data use, and routes for appeal where individuals are affected.

Common professional mistakes include optimizing only average accuracy, using a test set contaminated by training data, deploying without monitoring, confusing fluent output with factual output, fine-tuning when retrieval is more suitable, and treating a vendor's benchmark as proof of fitness for a specific organizational task.

Current Developments and Best Practices

Current research is moving toward multimodal foundation models, smaller and more efficient models, mixture-of-experts architectures, long-context processing, tool-using agents, synthetic data, on-device inference, and automated evaluation. These developments expand capability but also introduce new failure modes, including tool misuse, context overload, and greater difficulty in tracing responsibility.

Sound practice includes the following:

1. Define the decision, user, harm model, and success criteria before selecting a model.

2. Establish data provenance, consent, quality checks, and version control.

3. Compare against simple baselines and human performance where appropriate.

4. Use task-specific, adversarial, subgroup, and temporal evaluation.

5. Separate retrieval, generation, verification, and escalation responsibilities.

6. Protect confidential data and minimize retention of prompts and outputs.

7. Monitor drift, incidents, cost, latency, and user behavior after deployment.

8. Keep a human accountable for consequential decisions.

9. Prefer abstention and evidence display over unsupported confidence.

10. Reassess the system whenever its data, model, users, or operating environment changes.

Chapter Summary

Neural networks learn parameterized transformations from data, and deep architectures create hierarchical representations that support complex tasks. CNNs exploit spatial locality, recurrent networks model sequential state, and transformers use attention to capture relationships across sequences and modalities. Foundation models generalize across tasks through pretraining and can be adapted by prompting, retrieval-augmented generation, or fine-tuning.

Generative AI systems must be understood as socio-technical systems rather than isolated models. Their reliability depends on data governance, retrieval, evaluation, security, monitoring, and human oversight. Hallucination control requires grounding, verification, calibrated abstention, and use-case-specific testing. Ethical and professional practice demands attention to fairness, privacy, accountability, transparency, and the consequences of deployment.

Key Terms

Artificial neural network: A parameterized computational model composed of interconnected units that learn mappings from inputs to outputs.

Activation function: A nonlinear function applied to a neuron's weighted input.

Backpropagation: A gradient-computation procedure based on the chain rule.

Representation learning: Learning features or internal encodings that support a task.

Deep learning: Learning with neural networks containing multiple computational layers.

Overfitting: Fitting training data so closely that performance on new data deteriorates.

Transfer learning: Adapting knowledge learned on one task or dataset to another.

Self-supervised learning: Learning from automatically constructed targets derived from the input data.

Convolutional neural network: A neural architecture using local filters and shared parameters, especially for spatial data.

Recurrent neural network: A sequence model that maintains a hidden state across time steps.

Attention: A mechanism that assigns learned importance weights to elements of an input.

Transformer: An architecture built primarily from attention and feed-forward blocks.

Foundation model: A broadly pretrained model adaptable to multiple downstream tasks.

Large language model: A large pretrained model that generates or analyzes language, commonly using transformer architecture.

Prompting: Supplying instructions, context, examples, or constraints to guide model behavior.

Retrieval-augmented generation: Combining information retrieval with model generation to ground responses in external sources.

Fine-tuning: Updating model parameters using task- or domain-specific data.

Hallucination: An unsupported, fabricated, or misleadingly confident model output.

Calibration: The correspondence between stated or estimated confidence and actual likelihood of correctness.

Distribution shift: A change between the data used for development and the data encountered in deployment.

Review Questions

Short Answer Questions

1. What is the role of an activation function in a neural network?

2. Distinguish parameters from hyperparameters.

3. Why is representation learning important in deep learning?

4. What problem does retrieval-augmented generation address?

5. Define hallucination in the context of a language model.

Long Answer Questions

1. Explain the training process of a neural network, including forward propagation, loss calculation, backpropagation, and optimization.

2. Compare CNNs, recurrent neural networks, and transformers in terms of inductive bias, computational behavior, and suitable applications.

3. Explain how pretraining, prompting, RAG, and fine-tuning provide different forms of model adaptation.

4. Discuss the causes of overfitting and distribution shift and propose a comprehensive evaluation strategy.

5. Examine the ethical, privacy, security, and governance requirements for deploying generative AI in an organization.

Analytical / Application Questions

1. A hospital wants to use a language model to summarize patient records. Decide whether prompting, RAG, fine-tuning, or a combination is most appropriate, and justify the decision.

2. An LLM answers policy questions fluently but cites irrelevant documents. Diagnose the likely pipeline failures and design an evaluation and remediation plan.

3. A university must choose between a large commercial model and a smaller private model for a confidential student-support service. Analyze the technical, organizational, economic, and ethical trade-offs.

22. Multiple Choice Questions with Answers

Question 1

Which mechanism enables a neural network to learn parameter updates from the loss function?

A. Backpropagation using gradients

B. Pooling without a loss function

C. Tokenization alone

D. Database indexing

Correct Answer: A. Backpropagation using gradients

Question 2

A model has very high training accuracy but substantially lower validation accuracy. Which condition is most likely present?

A. Underfitting

B. Overfitting

C. Perfect calibration

D. Data normalization

Correct Answer: B. Overfitting

Question 3

Why are convolutional neural networks particularly effective for many image tasks?

A. They require no training data

B. They use local connectivity and shared filters

C. They process every image as a symbolic rule set

D. They eliminate the need for evaluation

Correct Answer: B. They use local connectivity and shared filters

Question 4

What is a central advantage of self-attention in transformers?

A. It restricts every token to its immediately preceding token

B. It models relationships among sequence elements more directly

C. It prevents the use of positional information

D. It guarantees factual answers

Correct Answer: B. It models relationships among sequence elements more directly

Question 5

An organization needs a model to answer questions using frequently changing internal manuals. Which approach is generally most suitable?

A. RAG over an governed document repository

B. Training only on random public text

C. Removing all source citations

D. Using a fixed prompt without documents

Correct Answer: A. RAG over an governed document repository

Question 6

Which statement best distinguishes fine-tuning from retrieval-augmented generation?

A. Fine-tuning changes model parameters, whereas RAG supplies external context at inference

B. Fine-tuning only changes the user interface, whereas RAG changes hardware

C. RAG permanently changes all model weights

D. Neither approach requires evaluation

Correct Answer: A. Fine-tuning changes model parameters, whereas RAG supplies external context at inference

Question 7

Which practice most directly helps control hallucinations in a high-risk application?

A. Increasing response creativity

B. Requiring evidence from authoritative sources and allowing abstention

C. Removing human review

D. Measuring only response length

Correct Answer: B. Requiring evidence from authoritative sources and allowing abstention

Question 8

A model performs well on historical test data but poorly after deployment at another hospital. What is the most plausible explanation?

A. Distribution shift

B. Tokenization success

C. Guaranteed generalization

D. Excessive citation

Correct Answer: A. Distribution shift

Question 9

Why should a generative AI system be evaluated beyond average accuracy?

A. Because subgroup performance, robustness, faithfulness, cost, and safety may differ

B. Because accuracy is never useful

C. Because evaluation prevents all model training

D. Because only model size determines quality

Correct Answer: A. Because subgroup performance, robustness, faithfulness, cost, and safety may differ

Question 10

In the university policy assistant case, why was human escalation retained?

A. The model could not generate any text

B. Ambiguous or consequential cases require accountable expert judgment

C. Retrieval systems cannot store documents

D. Citations make every answer incorrect

Correct Answer: B. Ambiguous or consequential cases require accountable expert judgment

Artificial Intelligence and Expert System
Chapter 9 of 15