Fastbook Chapter 10 questionnaire solutions (wiki)

Here are the questions:

  1. What is self-supervised learning?

Training a model without the use of labels. An example is a language model.

  1. What is a language model?

A language model is a self-supervised model that tries to predict the next word of a given passage of text.

  1. Why is a language model considered self-supervised learning?

There are no labels (ex: sentiment) provided during training. Instead, the model learns to predict the next word by reading lots of provided text with no labels.

  1. What are self-supervised models usually used for?

Sometimes, they are used by themselves. For example, a language model can be used for autocomplete algorithms! But often, they are used as a pre-trained model for transfer learning.

  1. Why do we fine-tune language models?

We can fine-tune the language model on the corpus of the desired downstream task, since the original pre-trained language model was trained on a corpus that is slightly different than the one for the current task.

  1. What are the three steps to create a state-of-the-art text classifier?
  1. Train a language model on a large corpus of text (already done for ULM-FiT by Sebastian Ruder and Jeremy!)
  2. Fine-tune the language model on text classification dataset
  3. Fine-tune the language model as a text classifier instead.
  1. How do the 50,000 unlabeled movie reviews help create a better text classifier for the IMDb dataset?

By learning how to predict the next word of a movie review, the model better understands the language style and structure of the text classification dataset and can, therefore, perform better when fine-tuned as a classifier.

  1. What are the three steps to prepare your data for a language model?
  1. Tokenization
  2. Numericalization
  3. Language model DataLoader
  1. What is tokenization? Why do we need it?

Tokenization is the process of converting text into a list of words. It is not as simple as splitting on the spaces. Therefore, we need a tokenizer that deals with complicated cases like punctuation, hypenated words, etc.

  1. Name three different approaches to tokenization.
  1. Word-based tokenization
  2. Subword-based tokenization
  3. Character-based tokenization
  1. What is ‘xxbos’?

This is a special token added by fastai that indicated the beginning of the text.

  1. List 4 rules that fastai applies to text during tokenization.

Here are all the rules:

  • fix_html :: replace special HTML characters by a readable version (IMDb reviews have quite a few of them for instance) ;
  • replace_rep :: replace any character repeated three times or more by a special token for repetition (xxrep), the number of times it’s repeated, then the character ;
  • replace_wrep :: replace any word repeated three times or more by a special token for word repetition (xxwrep), the number of times it’s repeated, then the word ;
  • spec_add_spaces :: add spaces around / and # ;
  • rm_useless_spaces :: remove all repetitions of the space character ;
  • replace_all_caps :: lowercase a word written in all caps and adds a special token for all caps (xxcap) in front of it ;
  • replace_maj :: lowercase a capitalized word and adds a special token for capitalized (xxmaj) in front of it ;
  • lowercase :: lowercase all text and adds a special token at the beginning (xxbos) and/or the end (xxeos).
  1. Why are repeated characters replaced with a token showing the number of repetitions, and the character that’s repeated?

We can expect that repeated characters could have special or different meaning than just a single character. By replacing them with a special token showing the number of repetitions, the model’s embedding matrix can encode information about general concepts such as repeated characters rather than requiring a separate token for every number of repetitions of every character.

  1. What is numericalization?

This refers to the mapping of the tokens to integers to be passed into the model.

  1. Why might there be words that are replaced with the “unknown word” token?

If all the words in the dataset have a token associated with them, then the embedding matrix will be very large, increase memory usage, and slow down training. Therefore, only words with more than min_freq occurrence are assigned a token and finally a number, while others are replaced with the “unknown word” token.

  1. With a batch size of 64, the first row of the tensor representing the first batch contains the first 64 tokens for the dataset. What does the second row of that tensor contain? What does the first row of the second batch contain? (Careful—students often get this one wrong! Be sure to check your answer against the book website.)
  1. Why do we need padding for text classification? Why don’t we need it for language modeling?

Since the documents have variable sizes, padding is needed to collate the batch. Other approaches. like cropping or squishing, either to negatively affect training or do not make sense in this context. Therefore, padding is used. It is not required for language modeling since the documents are all concatenated.

  1. What does an embedding matrix for NLP contain? What is its shape?
  2. What is perplexity?

Perplexity is a commonly used metric in NLP for language models. It is the exponential of the loss.

  1. Why do we have to pass the vocabulary of the language model to the classifier data block?

This is to ensure the same correspondence of tokens to index so the model can appropriately use the embeddings learned during LM fine-tuning.

  1. What is gradual unfreezing?

This refers to unfreezing one layer at a time and fine-tuning the pretrained model.

  1. Why is text generation always likely to be ahead of automatic identification of machine generated texts?

The classification models could be used to improve text generation algorithms (evading the classifier) so the text generation algorithms will always be ahead.

1 Like

Question 16 is a little unclear IMO. Not sure exactly what it is asking.
It doesn’t seem Question 18 is really discussed in the chapter?


Thanks for posting your answers! I’m also looking for the official answers. What is the book’s website though? It seems it should be but it redirects to the course site now. Is there an official place I’m unaware of?

The book and course website have been merged:

1 Like

In regards to this question:

  1. What is “tokenization”? Why do we need it?

I don’t think the book really dwells with why this is needed, only with some of the challenges. Tokenization is needed because we’re examining texts for patterns. It won’t be possible to find such patterns if we only consider a text at the sentence level, since patterns would only emerge if certain sentences frequently appeared together in sets, and this is a very rare phenomenon. Needless to say, examining texts in their entirety would be even less productive. We only find interesting patterns when we examine texts at the level of individual words, substrings, or individual characters.