NOTEThe questions come from Prof. Shouliang Qi of Northeastern University (China).
The content comes from the slides of Prof. Hung-yi Lee’s machine learning course at National Taiwan University and from Prof. Shouliang Qi’s lectures.
💻 marks content from ChatGPT.
Chapter 8 SSL
Part I. Autoencoder
-
What is the aim of using autoencoder to get embedding?
💻: The aim of using an autoencoder to get an embedding is to learn a compact and meaningful representation of the input data. An autoencoder trains an encoder that maps the input to a low-dimensional vector (the embedding), and a decoder that reconstructs data as close as possible to the original from that vector. The embedding can be seen as a compressed representation of the input that captures its main features and structure, and can be used for downstream tasks such as classification, clustering and dimensionality reduction. The benefit is that the autoencoder learns feature representations of the input automatically, with no hand-designed feature extractor, which is very useful for complex data types and tasks.
-
Try to compare the denoising1autoencoder (DAE) with BERT and clarify their differences and common points.
💻: The denoising autoencoder (DAE) and BERT are two different pre-trained models.
-
DAE learns features of the input by adding noise to the input, while BERT learns contextual information by masking part of the input sequence.
-
What they have in common: both learn feature representations through pre-training, which can be used for many downstream tasks such as classification and generation.
-
However, they are designed for different purposes: DAE aims to learn features of the input, while BERT aims to learn contextual information.
-
-
Describe what the feature disentanglement is and give one application of feature disentanglement.
- Describe: 💻: Feature disentanglement means training two neural networks, an encoder and a decoder, to learn a set of low-dimensional vectors representing the input (the latent code), where each dimension corresponds to a specific attribute or factor of the input. These factors can be visual attributes such as color, shape, pose or background, sound characteristics of an audio signal, or vocabulary and syntactic structure in natural language processing. Through autoencoder training, the encoder maps the raw data to a low-dimensional latent code, and the decoder reconstructs data as close as possible to the original from it. If training succeeds, the latent code should capture the various factors and attributes of the input and separate them, so that each dimension corresponds to one specific factor or attribute. That is feature disentanglement, and it makes the data easier to analyze and manipulate.
- Application: Voice Conversion
-
What is Vector Quantized Variational Auto-encoder (VQVAE)?
💻: The Vector Quantized Variational Auto-encoder (VQVAE) is a generative model based on the variational autoencoder (VAE). By introducing vector quantization, it discretizes the continuous embedding space, giving generated samples better clarity and diversity.
A VQVAE consists of three parts: an encoder, a quantizer (codebook) and a decoder. The encoder maps the input to a low-dimensional continuous embedding space, the quantizer discretizes this space into a fixed set of discrete vectors, and the decoder decodes these discrete vectors into generated samples. During training, the VQVAE optimizes its parameters by minimizing the reconstruction error and the quantization loss.
-
Once you have a trained variational auto-encoder (VAE), what applications can be done?
Generator, Compression, Anomaly Detection (Fraud Detection, Network Intrusion Detection, Cancer Detection)
-
How to conduct the anomaly detection by using a VAE?
Detecting input x is similar to training data or not. (Check whether the input resembles the training data, i.e. whether its loss is large.)
Part II. BERT
-
What is the full name of BERT and GPT?
💻: BERT stands for Bidirectional Encoder Representations from Transformers, and GPT stands for Generative Pre-training Transformer.
-
What are the differences between BERT and GPT from the viewpoint of SSL?
💻: BERT and GPT are two common self-supervised learning (SSL) models. They differ in SSL as follows:
- Different tasks: BERT uses the Masked Language Modeling (MLM) task and the Next Sentence Prediction (NSP) task, while GPT only uses the Language Modeling (LM) task. MLM randomly masks some words in the input sequence and asks the model to predict the masked words; NSP asks the model to predict whether a pair of input texts are consecutive sentences. GPT’s LM task only asks the model to predict the next word given the input so far.
- Different architectures: BERT uses a bidirectional Transformer encoder, while GPT uses a unidirectional Transformer decoder. BERT’s bidirectional encoder gets contextual information by reading the whole input sequence, but generating text with it needs extra handling, since it cannot guarantee that each generated word depends only on the words before it. GPT’s unidirectional decoder generates words one by one in order, which avoids this problem.
- Different fine-tuning: BERT is usually fine-tuned on downstream tasks, while GPT is usually used directly to generate text. BERT is fine-tuned by plugging the pre-trained model into a downstream task model and fine-tuning it with task-specific labeled data. GPT, by contrast, generates text by fine-tuning the model directly.
- Overall, BERT and GPT are both self-supervised models, but they differ in task type, architecture and fine-tuning. BERT is more general-purpose and suits tasks that require understanding context, such as question answering and text classification, while GPT is better suited to generating text.
-
What is the self-supervised learning?
💻: Self-supervised learning is a family of machine learning methods that learn from data without human labels. Unlike supervised learning, which needs labeled data for training, self-supervised learning learns from the structure or features inherent in the data, producing high-dimensional feature representations?? that characterize the data and can be used for transfer learning in many tasks.
-
Explain why BERT works.
- When a sequence of text is input, every token gets a corresponding vector, called its embedding. These vectors represent the meaning of the input words. More concretely, if you plot the vectors of these words or compute the distances between them ⇒ words with similar meanings have vectors that are close to each other. (When training BERT, we give it w1, w2, w3 and w4, mask w2 and ask it to predict w2, so it extracts information from the context to predict w2. The vector is therefore the essence of its context, and can be used to predict what w2 is.)
- BERT’s encoder contains self-attention, so it takes the context into account and produces different embeddings for the same word in different contexts.
-
How to use BERT to fulfill a task of sentiment analysis of sentences?
Add a CLS token at the start of the sentence and look only at the vector output at the CLS position. Pass that vector through a linear layer (linear transform + softmax) to get the class.
-
How to use BERT to do Part-of-speech tagging, Natural Language Inference, Extraction-based Question Answering?
- POS tagging: attach a linear layer to the vector of each word and classify each one.
- NLI: put a special SEP token between the two sentences and a CLS token at the very beginning. Take the output vector at the CLS token and feed it into a linear transform to get the class.
- QA: show BERT a question, a document, and a special SEP token between them, with a CLS token at the beginning. Randomly initialize two vectors and train them from scratch, one for the start and one for the end of the answer: take the inner product of the first vector with the output vectors corresponding to the document, apply softmax, and the position with the largest value is the start of the answer. Likewise, the second vector finds the end of the answer.
-
In computer vision field, list some per-train tasks for SSL.
💻:
- Self-supervised learning: learn feature representations through unsupervised transformation or prediction tasks on the input image, for example rotating, cropping or occluding the image and having the model learn to recover the original image before the transformation.
- Image inpainting: the model must recover the original image from a partially damaged one, for example with occluded regions added or parts cropped out. This helps the model learn representations of local structure and capture semantic relationships between objects.
- Contrastive learning: a self-supervised method based on a similarity measure, which learns feature representations by minimizing the distance between different copies of the same image and maximizing the distance between different images. This helps the model learn representations that are invariant to different classes and variations.
Chapter 9 Adversarial Attack
-
Explain how to realize a targeted attack to a network?
Add a term to the loss function of the non-targeted attack, meaning we want the attack result to be as close as possible to the target. 2
- Precondition: Non-perceivable
- Non-Targeted Attack: Loss function: put a minus sign in front of the cross entropy between y and the correct answer ŷ. As the loss decreases, the cross entropy increases, and the attack succeeds.
-
For L2-norm and L-infinite, which one is stricter for the requirement of “Non-perceivable”?
L-infinity. Judging the difference has to take human perception into account, i.e. domain knowledge. For example, the “distance” between images is best captured by their infinity norm, which considers where the change is largest. For the “non-perceivable” requirement, the L∞ norm is stricter: it only considers the largest element of the vector, so the other elements can stay closer to the original values, whereas the L2 norm averages over all elements, letting some of them drift slightly from the original values.
-
What is white-box attack and black-box attack?
💻: White-box and black-box attacks are two different ways of attacking a machine learning model. Both can degrade the model’s performance, so defenses are needed to keep the model secure.
- In a white-box attack, the attacker knows all the parameters and structure of the target model, including its inputs and outputs, and can access the model’s internal information directly. The attacker can then use that information to generate adversarial examples that mislead the model into wrong predictions.
- In a black-box attack, the attacker can only access the model’s inputs and outputs, not its internal information. The attacker has to collect enough information by testing and querying the model in order to generate adversarial examples that fool it into wrong predictions.
-
Describe one way of black box attack?
- Transfer attack (proxy network): 💻: This attack exploits the similarity between different models: train a proxy model, then transfer the adversarial examples generated on it to the target model to fool it into wrong predictions. (One pixel attack, Universal Adversarial Attack)
-
💻: Gradient-based attack: the attacker queries the target model many times to obtain its outputs, uses this information to compute the target model’s gradients, and then generates adversarial examples. This requires computing gradients through backpropagation and is usually computationally expensive.
-
List at least four ways of passive defense.
- Filter(e.g. Smoothing)
- Image Compression
- Generator
- Randomization
- Adversarial Training: build the “attack process” into training, to train a model that is harder to break
Chapter 10 Explainable Artificial Intelligence (XAI)
-
Why do we need Explainable ML?
💻: Explainable machine learning matters in several ways:
- Improving the credibility, interpretability and acceptability of models: in many scenarios, people need to understand how a model works internally in order to assess its credibility, interpretability and acceptability.
- Improving model performance:
- Models are usually trained on historical data, and if that data is biased, so is the model. Explainable ML helps us find biases in the data and algorithms, and improve the model.
- Explainable ML helps us understand how the model works internally, so that we know why wrong answers occur and can improve the model.
-
What question the local explanation and global explanation want to answer is?
- Local Explanation: Explain the Decision
- Global Explanation: Explain the WHOLE MODEL
-
Elucidate what the local explanation is and give two or more methods of local explanation.
💻: Local explanation explains a single sample or prediction, aiming to understand why the model made that prediction for the sample and which factors were decisive.
👦:
- Heat maps:
- Gray patches: alter or delete each component; if the network’s output changes a lot, we know the component is important.
- Saliency map: add noise to each pixel separately and plot the magnitude of the partial derivative of the loss with respect to each altered pixel x on a map to get the saliency map.
- What each layer of the network does:
- Dimensionality-reduction visualization: take vectors from the hidden layers and visualize them after dimensionality reduction.
- Probing: use the output vectors of certain layers for some classification tasks.
- Heat maps:
-
How to do global explanation by using constraint from generator?
- Connect an image generator to the image classifier.
- The image generator takes a z as input and outputs an image; the image classifier takes this image as input and outputs a classification.
- Find a z such that the X produced by the image generator, when fed into the image classifier, yields a y in which the score of a particular class is as high as possible.
- Feed the found into the generator and look at the generated image.
-
Explain the idea of Local Interpretable Model-Agnostic Explanations (LIME)
Using an interpretable model to mimic the behavior of an uninterpretable model.
Chapter 11 Transfer learning
-
For NLP and CV, which layer can be transferred (copied)? What is the behind reason?
- NLP: usually copy the last few layers. The lower layers of a pre-trained language model capture basic linguistic features such as morphology, grammar and semantics, while the higher layers capture more complex linguistic structure and semantics specific to the pre-training task. Different NLP tasks have similar linguistic structure (Human languages share some common characteristics.), while words, grammar and so on differ.
- CV: usually copy the first few layers. In CV tasks, the lower layers of a pre-trained convolutional neural network (CNN) capture low-level visual features such as edges, corners and textures, while the higher layers capture more complex visual patterns. Low-level visual features are similar across CV tasks, while high-level visual patterns and tasks differ.
-
How to do multiple task learning while using a neural network with the multi-layer structure?
- Multi-Head Network: 💻: A common approach in which each task has its own output layer but the hidden layers are shared. Each output layer has its task’s loss function, and all parameters are trained with backpropagation. The benefit is that each task’s specific structure and features are preserved.
- Shared Layers: 💻: Multi-task learning by sharing parameters between hidden layers, which can be convolutional or fully connected layers. Sharing these layers across tasks lets them jointly learn general features, improving performance on multiple tasks.
-
What is the domain-adversarial training and how realize it?
💻: Domain-adversarial training is a common transfer learning technique. Its goal is to counter the differences between domains with a domain classifier, improving the model’s generalization. Specifically, a domain classifier is added during training and the model is trained against it, so that it learns more robust and generalizable features.
Domain-adversarial training can be implemented in the following steps:
-
Define the domain classifier: a binary classifier that decides whether the input belongs to the source domain or the target domain.
-
Define the classifier: a base classifier trained on source-domain data.
-
Define the overall loss: it has two parts, the classifier loss and the domain classifier loss. The classifier loss trains on source-domain data, and the domain classifier loss decides which domain the input belongs to.
-
Train the network: in each iteration, randomly sample a batch of source-domain and target-domain data, compute their classifier loss and domain classifier loss, and update the network parameters with backpropagation.
-
👦: Note that the domain classifier should end up failing, while the loss is still kept as small as possible.
-
-
How to realize the zero-shot learning by the attributes?
💻: In attribute-based zero-shot learning, each object is associated with a set of attributes such as color, shape and texture. These attributes describe the object and can be used to recognize it, even if the model has never seen it before.
To train zero-shot learning with attributes, first collect a set of labeled data containing labeled objects and their attributes. Then train a classifier that predicts an object’s attributes from image features.
Once the model is trained, it can classify objects it has never seen by extracting the object’s features, predicting its attributes with the classifier, and assigning it to the right class. This extends the model’s reach, since it generalizes to unseen data without retraining.
-
How to realize the zero-shot learning by the attribute embedding?
💻: Zero-shot learning with attribute embeddings is similar to using attributes, except that attributes are converted into embedding vectors instead of being used as raw values.
In this approach, each attribute is first mapped into an embedding space. This is usually done by taking the attribute as input and computing its embedding with an embedding layer. These embeddings can be seen as feature representations of the attributes.
Then, for each object, its attributes are converted into embedding vectors, for example by averaging the embeddings of the object’s attributes. This average vector is called the object’s attribute embedding.
Finally, a conventional classifier such as an SVM or a neural network can take the object’s attribute embedding as input and predict the class. If the object’s attribute embedding is similar to a known class embedding, the object is assigned to that class.
Compared with attribute-based zero-shot learning, attribute embeddings are more flexible, since different embedding spaces and methods can be used for better performance. The method can also handle multiple attributes directly, without considering the correlations between them.
-
Describe the method of “Attribute embedding + word embedding” for the zero-shot learning.
💻: “Attribute embedding + word embedding” is a common zero-shot learning method. The basic idea is to classify by representing the attributes and names of objects or classes. Specifically, each class is first described by attributes, such as color, shape and material, which can be extracted automatically from existing samples or annotated by hand. Then the attribute vector and the word vector are combined into one complete vector representation. For an unseen class, its attributes and name are used to build its vector representation, and a classifier assigns it to the right class. The method needs enough attribute annotations and good attribute representations, but it applies to many tasks, such as image classification, object detection and natural language processing.
-
How to define the training loss of the zero-shot learning?
k is a hyperparameter: the matching pair (first term) should be as close as possible, and mismatched pairs (second term) as far apart as possible.
Chapter 12 Network compressing
-
List at least five types of way for network compressing.
- Network Pruning
- Knowledge Distillation
- Parameter Quantization
- Architecture Design
- Dynamic Computation
-
Why train a large model and then do network pruning, not train a small network?
It is widely known that smaller network is more difficult to learn successfully. (Small models are harder to train.)
-
How to understand this sentence “Pruning is an architecture search paradigm”?
The Lottery Ticket Hypothesis: a large network can be seen as a combination of many small sub-networks. Training the large network amounts to training many small networks.
Not every small network can be trained successfully; gradient descent may not find a good solution that lowers its loss. But among a large number of sub-networks, as long as one succeeds, the large network succeeds. So the more small networks a large network contains, the more lottery tickets you have bought: more tickets mean a higher chance of winning. That is why the larger a network is, the more likely it is to train successfully.
Pruning, then, is finding the best one among the many sub-networks.
-
How to do a knowledge distillation? What is the temperature for softmax and the formulas?
-
💻: Process:
- Train the large model (teacher model) on the training set and obtain the softmax values from its outputs (logits) and the true labels.
- Use the logits produced by the large model on the validation set and the softmax temperature T to get soft labels.
- Train the small model (student model) with the soft labels.
-
Before the softmax, divide the values by a hyperparameter , which makes the softmax output smoother.
-
-
How to realize parameter quantization?
- Using less bits to represent a value
- Weight clustering
- Represent frequent clusters by less bits, represent rare clusters by more bits (Huffman coding: frequent values get shorter codes, rare values get longer codes)
-
How to realize the Depthwise Separable Convolution?
-
Depthwise Convolution: considers the relationships within a channel
Take a layer with N input neurons and M output neurons. To reduce the number of parameters, insert another layer with K neurons between N and M.
The original single layer has M x N parameters; split into two layers, the first layer U has N x K parameters and the second layer V has K x M. If K is much smaller than M and N, U and V together have far fewer parameters than W.
-
Pointwise Convolution: considers the relationships between channels
A further step on top of the depthwise convolution, with the filter size restricted to .
-
-
What is the mathematical mechanism of the Depthwise Separable Convolution?
Low rank approximation
-
List three ways of dynamic computation.
- Dynamically adjusting the network depth (Dynamic Depth)
- Dynamically adjusting the network width (Dynamic Width)
- Computation based on sample difficulty (letting the network decide its own width and depth)
Chapter 13 Life-long learning
-
Explain what the full name of “CLIP” is, what the task used in CLIP is, and what the loss function used in CLIP.
Note: CLIP is OpenAI work that Prof. Shouliang Qi shared in class.
- Full name: Contrastive Language-Image Pre-training
- Task: matching a piece of text with an image, building a link between vision and language so that the model can handle images and text naturally
- Loss: a batch of images and their corresponding texts produce features and ; compute the matrix , take the diagonal as the labels, and apply cross-entropy loss along rows and columns to get and ; their average is the loss
-
Try to compare the life-long learning and transfer learning while there are two tasks.
-
Transfer Learning: I can do task 2 because I have learned task 1.(We don’t care whether machine can still do task 1.)
Transfer learning cares whether the skills learned on the first task help with the second ⇒ how well the new task is done
-
Life-long Learning: Even though I have learned task 2, I do not forget task 1.
Life-long learning cares whether, after learning the second task, the machine can still solve the first one ⇒ how well the old task is done
-
-
Why Catastrophic Forgetting will happen?
During gradient descent, the parameters move towards where the loss of the current task is small. But since the two tasks have different error surfaces, low loss corresponds to different parameters, which ultimately causes catastrophic forgetting.
-
What is the idea of selective synaptic plasticity? What is the loss function of selective synaptic plasticity?
-
Idea: Some parameters in the model are important to the previous tasks. Only change the unimportant parameters. When learning new parameters, the old, important parameters should change as little as possible; the new task should only change parameters that are unimportant to past tasks.
-
Loss:
denotes the parameters learned from previous tasks. An extra term is added to the original loss, wanting the newly learned to stay as close as possible to , with a “guard” for each parameter saying “how strongly” we want them to stay close, i.e. how important the original parameter is.
-
-
List two kinds of way of Additional Neural Resource Allocation.
- Progressive Neural Network: train some extra neurons for every new task, so the model parameters of previous tasks are never changed.
- PackNet: allocate a large model from the start, and let each task use only some of the parameters; earlier tasks must not use up all the parameters, so later tasks can still use them.
- CPG: Progressive Neural Network + PackNet ⇒ the CPG model can add new parameters, and for each new task only some of the parameters are kept trainable.
-
How to do memory replay by a generator?
- For each task, train a generator that produces data for that task.
- When training later tasks, train on the data of the current task together with pseudo data produced by the generators trained on previous tasks.
-
What is the curriculum learning?
💻: In deep learning, curriculum learning is a method that helps the model learn faster by ordering the training samples. Unlike conventional random sampling, curriculum learning first trains on relatively easy samples, then gradually adds harder ones. This keeps the model from getting stuck on hard samples too early, improving training efficiency and generalization.
Chapter 14 Meta-learning (not a focus)
-
What is Meta Learning?
👦: Learning a learning method
💻: Meta learning is a machine learning approach that aims to learn how to learn. Normally, a model is trained on a large amount of training data and then tested on test data. Meta learning aims to let the model learn from a few training samples, so that it generalizes better to new tasks or environments.
👦: It can also be seen as a function F whose input is training data and whose output is a model.
-
List what can be learned through meta learning.
Net Architecture, Initial Parameters, Learning Rate, Data augmentation, etc. (Almost anything can be learned.)
-
What are the three steps of meta-learning?
- Function with unknown (define a function with unknown parameters )
- Define loss function for learning algorithm
- Optimization3
-
How to define the loss function of meta-learning
- Use the learned learning algorithm to train on one task’s training data, obtaining the model .
- For each task, test the trained model on that task’s (labeled) “test data”, compute the cross entropy between the predictions and the ground truth, and sum over the test data to get . Keep testing the learning algorithm on “other tasks” of the “same kind” to get , …
- Sum the losses of the learning algorithm over all “learning tasks” to get the total loss .
-
List two or three methods of optimization. (not a focus)
Stochastic gradient descent, Adam, NAG, etc.
The loss function of the learning algorithm has been defined.
- If is differentiable, gradient descent can be used.
- If not, use RL (Reinforcement Learning) or EA (Evolutionary Algorithm) and just brute-force train it.
-
Try to compare machine learning and meta-learning from the aspects of function, training, and loss.
- Goal:
- ML: find a function f that can do the task
- Meta: find a learning algorithm F that can find f
- Training Data:
- ML: one task is enough; train on that task’s “training data”
- Meta: train on several tasks, each “training task” having “training data + test data”
- Loss:
- ML: the sum of the losses over all the training4 data of one task
- Meta: is the loss of one task, and is the sum of the losses over all tasks
- Goal:
-
What is the full name of MAML for learning initialization?
Model-Agnostic Meta-Learning
-
Try to compare the different ways of initialization (MAML, transfer learning, domain adaption, self-supervised learning).
💻: Each initialization approach has its own use cases and strengths in deep learning.
MAML (Model-Agnostic Meta-Learning): in few-shot learning scenarios, MAML learns new tasks quickly within a meta-learning framework. Its initialization comes from training on multiple tasks, running gradient descent on each to optimize the model parameters and obtain a good set of initial parameters, which are then fine-tuned on the new task. MAML suits scenarios that need fast iterative optimization on new tasks.
Transfer learning: transfer learning initializes a new target task with model parameters trained on a source task. Using knowledge learned on the source task speeds up training on the target task and improves generalization. Transfer learning suits scenarios where the source and target tasks share similar features.
Domain adaptation: domain adaptation addresses the differences between two domains by mapping source-domain and target-domain data. The model can be initialized with source-domain data and then fine-tuned with target-domain data. Domain adaptation suits scenarios where the source and target data distributions differ.
Self-supervised learning: self-supervised learning learns from natural properties of the data itself, avoiding the cost of labeling large amounts of data by hand. For example, it can learn good feature representations by predicting images or videos from different viewpoints or times. Its training data can be generated automatically, which suits scenarios where data is scarce.
👦: MAML uses labeled data, so naturally it works better, while self-supervised learning uses unlabeled data. If the different tasks in meta learning are seen as different domains, meta learning can be seen as a form of domain adaptation.
-
Why MAML is good?
ANIL (Almost No Inner Loop), Feature Reuse
-
There are some ways of optimizer, such as Adagrad, RMSprop, NAG, Adam, can we learn an optimizer or learning rate?
Yes!
-
What is full name of NAS? Explain how to learning NAS through reinforcement learning?(not a focus)
- Full name: Network Architecture Search (NAS)
- How:
- , : the agent’s parameters
- Build a reinforcement learning agent network (whose output is the network architecture parameters), build a network from the agent’s output, test that network’s accuracy, and use as the agent’s reward to update the agent.
- Example:
- Use an RNN to output a network architecture (action)
- Build the network architecture
- Test the network’s accuracy (observation)
- Update the RNN
-
In Omniglot, there are 1623 characters and each has 20 examples. What is N and K in the “N-way K-shot classification?
- N:1623, K: 20
- N-ways K-shot classification: In each task, there are N classes, each has K examples.
-
What is prompt learning (optional)?
Not covered in class. 💻: Prompt learning is a new self-supervised method in NLP that guides the model to learn a specific task by generating a task-related text prompt. In prompt learning, the user designs a set of relevant prompts by hand to help the model learn the task.
-
Can we learn the data augmentation?
Yes! The method wasn’t explained in detail; roughly, build a graph and train to find the optimal path.
-
How do consider the relationship between general artificial intelligence (GAI) (Large model) and the domain or task specified artificial intelligence (Small model)?
Open question