Hands-on AI II - Hands-on AI II
Unit 1
9 min read
This subchapter covers the foundational concepts of how data is represented and preprocessed before feeding it into machine learning models. Tabular data is structured in columns (features) and rows (samples). - Properties: Every row (record) shares the exact same set of properties (column headers). - Access: Rows can be retrieved using unique identifiers (queries through key values). - Scale: Tabular databases have a virtually infinite range for mass data storage. Using the Iris Dataset ( features) as an introductory example: - Sample: A single data instance (e.g., a specific flower). - Features: Measurable properties (columns). - **Feature Vector (\mathbf{x**)}: A vector representing all features of a sample, e.g., . - Class: The target category (e.g., setosa, virginica, versicolor). - Label (): The ground-truth class of the sample (e.g., ). High-dimensional data (hundreds/thousands of features) cannot be visualized directly. - Goal: Project data into lower dimensions (e.g., 2D or 3D) while preserving maximum information, making it extremely useful for visualizing high-dimensional datasets. - Algorithms: Principal Component Analysis (PCA) and t-Distributed Stochastic Neighbor Embedding (t-SNE). Note that clustering algorithms like k-Means are for grouping, not for dimensionality reduction. - Information Loss: Reducing dimensionality always leads to some loss of information. - Prerequisite: Applying dimensionality reduction is not a strict requirement before training a model (many models can train directly on high-dimensional data). Images are represented as 3D tensors: . - Channels: Color images typically have 3 channels (Red, Green, Blue). Summing them creates the final colored image. - Color Depth: Number of possible intensity values per pixel per channel. - 8-bit depth: values (integer range ). - 16-bit depth: values. [Image] Artificially generating new training samples by modifying existing ones. - Techniques: Rotation, flipping, cropping, blurring, noise, input dropout, color jitter. - Pros: Increases dataset size, reduces overfitting, and increases robustness. - Cons: Can introduce artifacts, can change the task (e.g., flipping a handwritten digit `6' makes it look like another class), and is highly dependent on the task/model. Sequences are ordered elements: . - Types: Time series (ordered in time, e.g., weather, stocks) or non-temporal ordered data (molecules, language syntax). - Standard Feed-Forward Neural Networks (FFNNs): - Require fixed-length inputs (variable-length sequences must be preprocessed/padded). - Process elements independently; thus, the relation of elements in the sequence is lost. \subsection{Subchapter 1.2: Unsupervised Machine Learning}
Key concepts
Unit 2
8 min read
This subchapter covers the key techniques used to regularize deep neural networks, improve generalization, and prevent overfitting. Artificially modifying training examples by changing an irrelevant input property. - Goal: Help the model ignore irrelevant variations (e.g. flipping a cat horizontally, rotation, scaling) and focus on relevant features (shape, edges). - Effect: Increases the effective dataset size and improves model robustness. Dropout randomly deactivates neurons during training to prevent co-adaptation. - Training Time: Randomly omit (set to 0) of the hidden units. Scale the remaining weights by to keep the output expectation constant: - If , scale weights by . - If , scale weights by . - At Test Time: Use the full network (all units active, no scaling). - Effect: Acts as a strong regularizer. Leads to a higher, noisier training loss, but significantly reduces validation loss (prevents overfitting). [Image] [Image] Standardizing data inside hidden layers to speed up training. - Concept: Standardizing input features is easy (precompute training set mean/std once). Standardizing hidden layers is hard because distributions shift with weight updates (Internal Covariate Shift). - During Training: Normalize each mini-batch of training examples by its own mini-batch mean and standard deviation after every convolution or fully-connected layer. - During Testing: Use running statistics (mean and standard deviation) computed over the entire training set. - Effect: Speeds up optimization, acts as a regularizer due to batch-wise noise. Penalizing large weights by adding a term to the loss function: - L1 Regularization: Adds the sum of absolute weights: [ L_{\text{new}} = L + \lambda \sum_i |w_i| Commonly referred to as weight decay in deep learning. \subsection{Subchapter 2.2: Deep Networks & Transfer Learning}
Key concepts
Unit 3
9 min read
This subchapter introduces sequence data, outlines the architectural limitations of feed-forward networks on sequential inputs, and explains the basic recurrent neural network (RNN) structure, equations, and properties. - Fixed Input size: The input vector must have a fixed dimensionality, making variable-length sequences (e.g., sentences with different lengths) difficult to handle. - Order/Relation Loss: FFNNs process elements independently, discarding the sequence order and temporal relations. - Workaround Limits: Concatenating inputs in a sliding window increases input size and parameters, making optimization intractable. [Image] - Definition: A sample is a sequence of length with features at each timestep : [ s = (\mathbf{x}_1, \mathbf{x}_2, \dots, \mathbf{x}_T) \quad \text{with} \quad \mathbf{x}_t \in \mathbb{R}^D DTDTT = 4D = 5\mathbf{h**_t)}: The network's internal state (memory) at timestep t\mathbf{h}_t \in \mathbb{R}^H - Shared Weights: The same weight matrix is reused (shared) across all timesteps. [Image] The hidden state update equation is: [ \mathbf{h}t = f\left( W \cdot \begin{bmatrix} \mathbf{h}{t-1} \mathbf{x}t \end{bmatrix} + \mathbf{b} \right) f\tanh\begin{bmatrix} \mathbf{h}{t-1} \mathbf{x}t \end{bmatrix}\mathbf{x}tD \times 1\mathbf{h}{t-1}H \times 1\begin{bmatrix} \mathbf{h}{t-1} \mathbf{x}_t \end{bmatrix}(H+D) \times 1WH \times (H+D)\mathbf{b}H \times 1\mathbf{h}_tH \times 1T_xT_yT_x = T_y = 1T_x = 1T_y = 1T_x = 1, T_y > 1T_x > 1, T_y = 1T_x = T_yT_x \ne T_yL(\hat{\mathbf{y}}, \mathbf{y}) - Concept: RNNs are theoretically Turing complete, meaning they can represent any program (Siegelmann & Sontag, 1991). - Practical Challenge: The primary challenge is not representation capability, but finding the representation via gradient descent (learning). - Shared Weight Matrix: For each timestep, the exact same (shared) weight matrix is used. - Length Independence: The size of the weight matrix is independent of the sequence length. - Different Lengths: For sequences of different lengths, we do not need to learn multiple weight matrices. The same learned weight matrix is applied across all sequence lengths. Problem: Assume you have a sequence of 8 elements, and each element has 10 features (). If you process it using a standard, single-layer RNN with a hidden state size of 6 (), what is the size of the first RNN output? - Solution: The size of the RNN output at the first timestep (and every other timestep ) is exactly equal to the hidden state size . - Answer: The size is 6. (It is independent of sequence length 8 or feature size 10). \subsection{Subchapter 3.2: Unrolling RNNs & BPTT}
Key concepts
Unit 4
8 min read
This subchapter covers the introduction to Natural Language Processing (NLP), linguistic concepts like Chomsky's Universal Grammar, and early AI attempts at language modeling, specifically Weizenbaum's ELIZA and the Connectionist Model. Language is a highly complex, evolved system closely connected to human cognition: - Cognitive Link: Language allows humans to express, communicate, and structure thought. - Natural Language Processing (NLP): The computational modeling of language to infer structure, represent thoughts, and enable human-machine communication. Noam Chomsky (1965) proposed a highly influential (and controversial) theory of linguistics: - Innate Rules: Newborns possess an innate, genetically determined set of structural rules common to all human languages. - Constraints: During first-language acquisition, children do not learn grammar from scratch; rather, they map the specific vocabulary and rules of their native tongue onto these pre-existing, universal grammatical constraints. Joseph Weizenbaum developed ELIZA, one of the earliest conversational agents: - Role: Mimicked a Rogerian psychotherapist. - Mechanism: Relied strictly on hardcoded, hand-crafted rules and keyword pattern matching to reflect user inputs back as questions (e.g., matching "my boyfriend" and responding with "Is it important to you that your boyfriend..."). - Limit: It possessed no actual semantic understanding or representation of language. In contrast to rule-based systems, connectionists argued that language rules emerge from statistical learning: - Core Idea: Neural networks can learn linguistic structures directly from examples, without hardcoded grammatical rules. - Past Tense Learning: A neural network was trained on English verbs and successfully learned: - Regular Verbs: E.g., walk walked, play played. - Irregular Verbs: E.g., sing sang, go went. - Similarity Patterns: E.g., group patterns like sing/sang, ring/rang, drink/drank. - Significance: It demonstrated that complex, rule-like language behavior can emerge naturally from learned statistical patterns in data. - Limitations: Used simplified training settings, artificial data representations, and did not fully replicate human developmental stages. \subsection{Subchapter 4.2: Word Representations & Embeddings}
Key concepts
Unit 5
7 min read
This subchapter introduces the fundamentals of drug discovery, the pharmacology paradigm, the drug development timeline, the cost structures (including Eroom's Law), the massive molecular search space, and traditional High-Throughput Screening (HTS) approaches. The biological and chemical basis of modern drug discovery: - Drug: A chemical substance of known structure, other than a nutrient or essential dietary ingredient, which produces a biological effect when administered to a living organism. - Pharmacology Paradigm: The biological effect of a drug is strongly determined by its molecular structure. - Targets: Diseases are typically associated with pathological molecular pathways. The target molecules responsible for these pathways are frequently proteins (humans have approximately 20,000 to 25,000 proteins). - Proteins: Large biomolecules consisting of chains of 50 to 2,000 amino acids. - Task: - Identify the target biomolecule (often a protein) associated with a disease. - Find a small molecule (drug candidate) that interacts with (binds to) that target to produce a useful therapeutic effect. Bringing a drug to market is a long, high-risk process: - Funnel Model: - Drug Discovery & Preclinical: Starts with 10,000 compounds. Takes 6.5 years. Filters down to 250 compounds for preclinical testing. - Clinical Trials: Filters down to 5 candidate compounds tested on humans. Takes 7 years. - Review: FDA/EMA review of the clinical data. Takes 1.5 years. - Result: Only 1 approved drug reaches the market from the initial 10,000. [Image] - Financial Cost: Bringing a new drug to market is extremely expensive, with typical estimates ranging from $1 billion to over $2 billion. - Success Rate: Only about 10% of drug candidates that enter clinical trials are eventually approved. - Discovery Share: The initial drug discovery stage contributes to about 30% of the total cost. Improving this stage using machine learning can greatly increase cost efficiency. - Eroom's Law (Moore's Law spelled backward): The number of new drugs approved per billion dollars of R&D spending has roughly halved every 9 years. This indicates a severe decline in R&D efficiency over time, raising the need for computational solutions. Finding a drug candidate is literally like finding a "needle in a haystack": - Search Space Size: - If the maximum number of heavy atoms in a molecule is 13: (977 million) possible compounds. - If the maximum number of heavy atoms is 17: (166 billion) possible compounds. - For typical drug-like molecules, the maximum number of heavy atoms is 40: this yields an astronomical search space of possible molecules. - High-Throughput Screening (HTS): The traditional approach where millions of candidate molecules are physically tested in biological assays. HTS is an expensive and time-consuming physical process. - Need for Machine Learning: By training neural networks to predict bioactivity, we can make educated guesses and computationally screen candidates (Virtual Screening), significantly narrowing down the physical testing requirements. In Virtual Screening, a trained neural network predicts whether a molecule in a database is likely to bind/react with the target of interest. \subsection{Subchapter 5.2: QSAR & Small Molecules}
Key concepts
Unit 6
8 min read
This subchapter introduces Reinforcement Learning (RL), contrasts it with Supervised and Unsupervised Learning, mathematically formulates the problem using Markov Decision Processes (MDPs), details the Q-Value Function and Q-learning update updates, analyzes the exploration-exploitation trade-off, and walks through the classic Taxi toy environment. Machine Learning paradigms differ fundamentally in their learning signals and objectives: - Supervised Learning: Learning a mapping from input values and corresponding target labels (predictive modeling: classification/regression). - Unsupervised Learning: Finding underlying hidden structure from unlabeled inputs (clustering, dimensionality reduction, feature learning, density estimation). - Reinforcement Learning (RL): Learning how to act to maximize cumulative rewards. An agent interacts with an active environment by executing actions and receiving numeric reward signals. An MDP is the standard mathematical formulation of the reinforcement learning problem. It is formally defined by a 4-tuple: - States (): The set of all possible states in the environment. - Actions (): The set of all possible actions available to the agent. - Transition Probability (): The probability of transitioning from state to state when executing action at timestep : [ P_a(s, s') = \Pr(s_{t+1} = s' \mid s_t = s, a_t = a) R_a(s, s')ass'\pia = \pi(s)\pi^*Q(s, a)\gammaas Where: - (Learning Rate): Specifies the update step size. - : No update at all is performed (the agent ignores new experiences and learns nothing). - : Both the old Q-value as well as the new information will be used in the update step. - : The agent completely discards the old estimate, overwriting it with the new temporal difference target. - (Discount Factor): Specifies the significance of future rewards. - : "Myopic" (short-term) agent that only maximizes the immediate reward . - : Far-sighted (long-term) agent that places full weight on future cumulative rewards. - : The immediate reward received when transitioning from to using action . - : The estimated optimal future value in the next state. - Definition: An optimal policy maximizes the expected cumulative return from any starting state. - Method: The optimal policy may be obtained via Q-learning. - Non-Uniqueness: There does not necessarily exist exactly one optimal policy. Multiple policies can be optimal if they achieve the same maximal expected cumulative return. - Objective: Applying the optimal policy maximizes the discounted sum of future rewards. It does not minimize rewards, nor does it simply maximize the immediate reward (unless ). Scenario: Consider a 2D grid world of size 5x5. A robot (the agent) is placed randomly on this grid and must move to the target destination. - Actions: 4 movements (up, down, left, right). If the robot tries to go off the grid, it remains at the same location. - Rewards: Each action has a reward of (negative reward). Reaching the target awards (positive reward). - Key Properties: - Optimal Policy steps: The maximum number of steps of an optimal policy starting from any location is 8 (moving from one corner to the opposite corner takes steps). - Optimal Policy reward: An optimal policy does not always have a positive cumulative reward. Starting 8 steps away, the optimal cumulative reward is (negative). - Policy Failure: With a bad policy, it might happen that the target destination is not reached at all (e.g. infinite loops). Thus, the maximum steps of any policy is infinite (not limited to 100). - The Dilemma: The agent must balance: - Exploration: Trying actions with uncertain outcomes to discover better policies. - Exploitation: Choosing the action currently estimated to yield the highest reward. - -Greedy Selection: A simple, widely-used policy to balance this trade-off: [ a_t = $\begin{cases} \text{random action} & \text{with probability } \epsilon
\arg\max_a Q(s_t, a) & \text{with probability } 1 - \epsilon
\end{cases}$
$
$\epsilon$ is often decayed over time (high exploration initially, high exploitation as learning stabilizes).
- **Episodes**: An interaction sequence starting from an initial state and running until a terminal state (win/loss) is reached. If no terminal state is reached, the episode is truncated after a maximum number of steps.
The Taxi domain is a classic reinforcement learning environment used to test tabular Q-learning: - State Space Size: Calculated as the Cartesian product of sub-states: [ 25 \text{ grid cells} \times 5 \text{ passenger locations} \times 4 \text{ drop-off locations} = 500 \text{ states} 500 \text{ states} \times 6 \text{ actions} = 3,000+20-10-1s_{12}a_1r = -1s_{174}\alpha = 0.1\gamma = 1 [Image] \subsection{Subchapter 6.2: Q-learning & Policies}
Key concepts