متقدم
البحث فيالملخصات
طريقة البحث
  • الكلمات تجد عناوين الدروس والنص والكود. صفِّ حسب النوع (أدلة، دورات، برامج، كتب) أو ابقَ في هذا الكتاب.
  • book:rhcsa و ch:8 يضيّقان البحث؛ ‎#code يجد الكلمة داخل أوامر الدروس فقط.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدورة 8الاسم في الدورة: Gen AI Foundational Models for NLP & Language Understanding

Generative AI Foundational Models for NLP and Language Understanding

Course 8 of 13 in the IBM AI Engineering certificate. How to turn words into numbers that a neural network can use.

Course page: Coursera

  • 6 الدروس
  • 0 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

8.1

What the course covers

How to turn words into numbers that a neural network can use.

  • How to build a document classifier with torchtext and PyTorch.
  • How an N-gram language model works, by counts and by a neural network.
  • How Word2Vec learns word vectors with CBOW and skip-gram.
  • How encoder-decoder RNNs translate text.
  • How to measure model and generated-text quality, and why bias matters.
ModuleMain focus
Module 1 · about 5 hoursFundamentals of Language Understanding: word features, document classification, N-gram models
Module 2 · about 5 hoursWord2Vec and Sequence-to-Sequence Models: CBOW, skip-gram, RNN translation, evaluation, ethics

8.2

Module 1: Fundamentals of Language Understanding

Fundamentals of Language Understanding: word features, document classification, N-gram models.

  • Core NLP tasks: document classification, language modeling and translation.
  • A neural network needs numbers, so we convert words to features first.
  • One-hot encoding: a vector of zeros with one 1. It is sparse and shares no meaning between words.
  • Bag-of-words: counts the words in a document and ignores the order.
  • An embedding is a dense vector. Words with similar meaning get similar vectors.
  • Embedding bag averages the vectors of all tokens in a document and gives one vector.
  • torchtext helps with tokenizing, building a vocabulary, loading datasets and making batches.
  • Document classification: text → vector → linear layer → softmax → label.
  • Use cross-entropy loss for classification and accuracy to report the result.
  • The training loop is: forward pass, loss, backward pass, optimizer step.
  • An N-gram predicts a word from the previous n−1 words. Unigram, bigram and trigram use n = 1, 2 and 3.
  • Count-based N-grams fail on unseen sequences, so we add smoothing (for example add-one).
  • A neural N-gram uses embeddings and a hidden layer, so it learns patterns, not only counts.
  • Perplexity measures a language model. A lower value is better.

8.3

Module 2: Word2Vec and Sequence-to-Sequence Models

Word2Vec and Sequence-to-Sequence Models: CBOW, skip-gram, RNN translation, evaluation, ethics.

  • Word2Vec learns dense word vectors from the words around each word.
  • CBOW predicts the center word from the context words.
  • Skip-gram predicts the context words from the center word.
  • Skip-gram is slower, but it works better for rare words.
  • Negative sampling and hierarchical softmax make Word2Vec training faster.
  • Pretrained embeddings (word2vec, GloVe, fastText) can be loaded and reused for a new task.
  • Vector math shows meaning: king − man + woman is close to queen.
  • Seq2Seq models have an encoder that reads the source and a decoder that writes the target.
  • The encoder RNN turns the source into a hidden state, called the context vector.
  • The decoder RNN makes one token at a time, and its output becomes the next input.
  • Teacher forcing: during training, give the decoder the true previous token.
  • At inference we use the model's own output (greedy) or search several paths (beam search).
  • BLEU compares n-grams of the output with the reference. Higher is better. It is common for translation.
  • ROUGE is recall-based. It is common for summaries.
  • Ethics: embeddings learn gender and race bias from the training text. Test for it and use fair data.

8.4

Check yourself

Answer each question first, then open it to check the answer.

1Why do we convert words to numbers before a neural network? a) To remove all grammar · b) To make the file shorter · c) Because the network works with numbers, not raw text · d) To slow the training

c) Because the network works with numbers, not raw text. The model does math, so text must become vectors of numbers.

2What is true about one-hot encoding? a) It is very short and dense · b) It is sparse and gives no meaning to the position · c) It keeps the word order · d) It is a loss function

b) It is sparse and gives no meaning to the position. One-hot vectors are mostly zeros and treat every word as unrelated.

3What does bag-of-words lose? a) The learning rate · b) The word count · c) The labels · d) The word order

d) The word order. It only counts words, so "dog bites man" and "man bites dog" look the same.

4What is an embedding? a) A type of optimizer · b) A sparse vector of counts · c) A dense vector that carries meaning · d) A test metric

c) A dense vector that carries meaning. An embedding is learned, dense and close for words with close meaning.

5In CBOW, what does the model predict? a) The center word from the context words · b) The context from the center word · c) The next sentence · d) The document label

a) The center word from the context words. CBOW uses the neighbour words to guess the missing center word.

6In skip-gram, what does the model predict? a) The center word from the context · b) The vocabulary size · c) The translation score · d) The context words from the center word

d) The context words from the center word. Skip-gram uses one word to guess the words around it.

7Which trick makes Word2Vec training faster? a) Padding · b) Negative sampling · c) One-hot decoding · d) Dropout only

b) Negative sampling. Negative sampling trains on a few wrong pairs instead of the full softmax.

8In a seq2seq model, what does the encoder do? a) It writes the target text · b) It reads the source and makes a context vector · c) It scores the BLEU value · d) It cleans the data

b) It reads the source and makes a context vector. The encoder reads the input and passes one state to the decoder.

9What is teacher forcing? a) Removing the decoder · b) Using a bigger batch · c) Giving the decoder the true previous token during training · d) Training without labels

c) Giving the decoder the true previous token during training. The true token is fed in, so the model learns the next step faster.

10Which metric is common for translation quality? a) R2 · b) MAE · c) BLEU · d) F1 for images

c) BLEU. BLEU compares n-gram overlap with the human reference.

11Which metric is recall-based and common for summaries? a) ROUGE · b) BLEU · c) Perplexity · d) RMSE

a) ROUGE. ROUGE looks at how much of the reference the output covers.

12What is perplexity? a) A count of tokens · b) A measure of a language model, where lower is better · c) A type of embedding · d) A training speed

b) A measure of a language model, where lower is better. Low perplexity means the model is not surprised by the real text.

13Why can word embeddings be an ethical problem? a) They remove all meaning · b) They are always too large · c) They cannot be trained · d) They learn bias from the training text

d) They learn bias from the training text. If the text has stereotypes, the vectors carry them into the model.

8.5

Study and exam tips

Learn the pair: CBOW = context to word, skip-gram = word to context.

  • Remember the flow: text → tokens → IDs → embeddings → model.
  • Keep the metrics clear: perplexity for language models, BLEU for translation, ROUGE for summaries.
  • For bias questions, the answer is usually the training data, not the code.
  • Check the small details: n−1 words, teacher forcing and context vector.