開始使用免費開始

遷移學習的起點

在這個練習中,你會看到以預先訓練的向量作為模型起點的好處。

你將比較兩個模型在訓練 2 個 epoch 後的準確率。這兩個模型的架構相同:1 個 embedding 層、1 個具有 128 個單元的 LSTM 層,以及 1 個輸出層(5 個單元,對應範例資料的類別數)。不同之處在於,其中一個模型在 embedding 層使用了預先訓練的向量(遷移學習),另一個則沒有。

所使用的預先訓練向量是 GloVE,維度為 200。兩個模型在驗證集上的訓練準確率歷程分別儲存在變數 history_no_embhistory_emb 中。

本練習屬於課程

使用 Keras 建立語言模型的循環神經網路(RNN)

檢視課程

練習說明

  • 將模組 matplotlib.pyplotplt 名稱匯入。
  • 將「未使用 embeddings 的模型」的準確率列表加入圖表。
  • 將「使用 embeddings 的模型」的準確率列表加入圖表。
  • 使用 .show() 方法顯示圖表。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import plotting package
import matplotlib.____ as ____

# Insert lists of accuracy obtained on the validation set
plt.plot(____['acc'], marker='o')
plt.plot(history_emb[____], marker='o')

# Add extra descriptions to plot
plt.title('Learning with and without pre-trained embedding vectors')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['no_embeddings', 'with_embeddings'], loc='upper left')

# Display the plot
plt.____
編輯並執行程式碼