2024-08-17|閱讀時間 ‧ 約 24 分鐘

AI說書 - 從0開始 - 135 | BERT 微調所需的相關依賴安裝

我想要一天分享一點「LLM從底層堆疊的技術」,並且每篇文章長度控制在三分鐘以內,讓大家不會壓力太大,但是又能夠每天成長一點。


AI說書 - 從0開始 - 134 闡述了 Fine-Tuning 的目標為使用資料集 CoLA,來學習如何判斷一個句子的文法是否是可以被接受的,同時也提供 GPU 使用教學於 使用Meta釋出的模型,實作Chat GPT - Part 0


現在來安裝 Transformer 模組:

try:
import transformers
except:
print("Installing transformers")
!pip -q install transformers


接著匯入一些重要模組以供後續使用:

import torch
import torch.nn as nn
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
from keras.utils import pad_sequences
from sklearn.model_selection import train_test_split
from transformers import BertTokenizer, BertConfig
from transformers import AdamW, BertForSequenceClassification, get_linear_schedule_with_warmup

from tqdm import tqdm, trange #for progress bars

import pandas as pd
import io
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import Image #for image rendering


接著要來使用 GPU,偵測方式如下:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
!nvidia-smi


結果如下:


注意上圖可能隨著 Google Colab 的更迭而有版本異動。

分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.