How to Fine Tune Google PaliGemma, a Vision Language Model?

Mervin Praison
28 May 202407:35

Summary

TLDRこのビデオでは、GoogleがリリースしたVision言語モデル「Pala」のファインチューニングについて紹介しています。画像とテキストを組み合わせて画像内の内容を理解することができるアーキテクチャを説明し、データセットのロード、モデルのファインチューニング、Hugging Faceへの保存という手順を紹介しています。また、異なるVisionモデルであるLavaについては、CLIPを視覚エンコーダとして、VUNaを言語モデルとして使用するという違いも触れています。実際にPythonのターミナルでコードを実行し、モデルをトレーニングしてHugging Faceにアップロードするプロセスも解説されています。

Takeaways

  • 📚 GoogleがリリースしたVision言語モデルPalaについて学ぶことができます。これは画像とテキストを理解する機能を持っています。
  • 🔍 Palaのアーキテクチャでは、Siglipを使用して画像をエンコードし、テキスト入力と組み合わせて最終出力を生成します。
  • 🌐 別のVisionモデルであるLavaでは、CLIPを視覚エンコーダとして、Vunaを言語モデルとして使用します。
  • 🛠️ チュートリアルでは、データセットの読み込み、モデルのファインチューニング、Hugging Faceへの保存というステップが紹介されています。
  • 🎥 YouTubeチャンネルで人工知能に関するビデオを定期的に投稿している旨が紹介されており、購読を呼びかけています。
  • 💻 Master Compute仮想マシンを使用し、特定のクーポンコードで割引を得る方法が提案されています。
  • 📦 Pythonのpipコマンドを使用して必要なパッケージをインストールする手順が説明されています。
  • 🔧 Hugging Faceのトークンをエクスポートし、app.pyというファイルを作成して使用する方法が紹介されています。
  • 🔄 VQA(Visual Question Answering)データセットからデータをロードし、不要な列を削除するプロセスが説明されています。
  • 🔢 パラメータの設定やトレーニングの設定など、ファインチューニングのためのトレーニング引数を定義する方法が説明されています。
  • 🚀 ファインチューニング後にモデルをHugging FaceのHUBにアップロードする手順が紹介されています。
  • 📈 ファインチューニングが完了した後、モデルがどのように機能するかを示すデモが行われています。

Q & A

  • Palaモデルとは何ですか?

    -PalaはGoogleがリリースしたVisionとLanguageのモデルで、画像とテキストを理解し、画像の中身を理解することができます。

  • Palaモデルのアーキテクチャはどのようなものでしょうか?

    -Palaモデルでは画像はSiglipを使用してエンコードされ、その後テキスト入力と組み合わせて最終出力を生成します。

  • LAVAモデルとは何ですか?また、Palaとの違いは何ですか?

    -LAVAは別のVisionモデルで、CLIPをVisual Encoderとして、VUNaをLanguage Modelとして使用しています。主な違いはPalaはFine-tuningを行い、LAVAはFine-tuningと保存をHugging Faceにすることです。

  • Fine-tuningとはどのようなプロセスですか?

    -Fine-tuningとは、事前に学習されたモデルを特定のタスクに合わせて調整するプロセスです。ここではPalaモデルをFine-tuningして、より正確な結果を得ることができます。

  • Hugging Faceとは何ですか?

    -Hugging Faceはオープンソースの機械学習ライブラリを提供する企業で、モデルを保存し共有するためのプラットフォームを提供しています。

  • Fine-tuningを行う前に必要なパッケージは何ですか?

    -Fine-tuningを行うためには、Transformers、datasets、PFT-bits、pytorch、lower-config、およびpillowなどのパッケージが必要です。

  • データセットはどのようにロードされるのでしょうか?

    -データセットはvqa version twoからロードされ、視覚質問と回答のデータセットを使用して、画像とそれに対応する質問と回答をモデルに教えます。

  • モデルのFine-tuningに必要なパラメータはどのようなものでしょうか?

    -Fine-tuningに必要なパラメータには、エポック数、オプティマイザ、学習率などがあります。これらは必要に応じて調整することができます。

  • Fine-tuning後にモデルはどのように保存されるのでしょうか?

    -Fine-tuning後には、Trainerのpush to HUB機能を使用して、モデルをHugging Faceに保存します。

  • Fine-tuningされたモデルはどのように使用されるのでしょうか?

    -Fine-tuningされたモデルは、画像を入力として与えることで、画像の中身を理解し、質問に答えることができます。

  • このチュートリアルで使用するGPUのサイズに応じてモデルをどのように調整するべきですか?

    -GPUのサイズに応じて、モデルをQuantizedバージョンにロードすることができます。GPUが大きい場合は、Quantizationなしのモデルを使用することができます。

  • Fine-tuningされたモデルはどのような用途に使えますか?

    -Fine-tuningされたモデルは、医療画像の分析、独自の画像データセットに基づくカスタマイズなど、様々な用途に使えます。

Outlines

00:00

😲 パラマのファインチューニングを学ぶ

この段落では、GoogleがリリースしたVision言語モデルであるPalaのファインチューニングについて学ぶことができます。Palaは画像とテキストを理解し、それらを組み合わせて最終出力を生成するアーキテクチャを持っています。このチュートリアルでは、データセットの読み込み、モデルのファインチューニング、そしてHugging Faceへの保存というステップを紹介します。また、YouTubeチャンネルでのAIに関するビデオの作成も紹介しており、Master Compute Virtual Machineの使用や割引クーポンコードの提供もあります。必要なパッケージをインストールし、Hugging Faceのトークンを設定した後、app.pyを作成し、データセットの読み込み、モデルの設定、ファインチューニングのためのパラメータの設定を行います。

05:01

🎓 パラマのファインチューニングからHugging Faceへのモデルの保存

この段落では、ファインチューニングされたPalaモデルをHugging Faceに保存する方法について説明しています。トレーニングに必要な引数を設定し、Trainerクラスを使用してモデルをトレーニングします。その後、モデルをHugging FaceのHUBにプッシュし、ユーザー名とモデル名を指定して保存します。トレーニングが完了すると、Hugging Faceでモデルを確認でき、独自の画像を追加してファインチューニングすることができると紹介されています。医療分野での応用も想定されており、ビデオの最後には、ビデオを楽しんでくれたことに感謝し、今後も同様のビデオを作成していく旨のコメントがされています。

Mindmap

Keywords

💡Fine-tuning

ファインチューニングとは、既存の機械学習モデルを特定のタスクやデータセットに合わせて調整することを指します。このビデオでは、GoogleがリリースしたVision言語モデルであるPalaをファインチューニングして、画像とテキストを理解し、画像に何が含まれているかを認識する能力を高めることを目的としています。例として、「ファインチューニング」という言葉がスクリプトで使用されているのは、モデルをトレーニングするプロセスを説明する際です。

💡Pala (Vision言語モデル)

PalaはGoogleがリリースしたVision言語モデルで、画像とテキストの両方を理解する能力を持っています。ビデオでは、Palaを使用して画像とそれに関連するテキストを入力し、画像の内容を理解するようにファインチューニングします。スクリプトでは、「Pala」という言葉が、モデルの選択とその機能の説明に使用されています。

💡シグナルP (Sig lip)

シグナルPは、画像を符号化するための手法です。ビデオでは、画像がシグナルPを使用してエンコードされ、その後テキスト入力と組み合わせられ、最終的な出力を生成するアーキテクチャについて説明しています。スクリプトでは、「シグナルP」と提唱されているのは、画像を符号化するプロセスを説明する場面です。

💡Jemma

Jemmaは、ビデオのスクリプト内でモデルの出力を得るために使用されるアルゴリズムまたはプロセスを指している可能性がありますが、スクリプト内で正確な定義が提供されていません。ただし、一般的なコンテキストでは、Jemmaは画像とテキストを組み合わせて最終出力を生成する過程の一部として使用されると推測されます。

💡LAVA

LAVAは、ビデオ内で別のVisionモデルとして言及されていますが、具体的な詳細はスクリプトに記載されていません。LAVAは、画像を扱う別のモデルまたはフレームワークである可能性がありますが、ビデオの主題に直接関係する詳細については不明です。スクリプトからは、「LAVA」という言葉が別のVisionモデルと共に言及されていることだけがわかります。

💡クリップ (CLIP)

CLIPは、ビデオ内で視覚エンコーダとして使用されるモデルです。スクリプトでは、CLIPがLAVAモデルと組み合わせて使用され、画像をエンコードし、テキストと共にモデルの出力を得る方法について説明しています。CLIPは、画像を理解し、テキストと関連付けるタスクに役立つとされています。

💡Hugging Face

Hugging Faceは、オープンソースの自然言語処理ツールやモデルを提供する企業です。ビデオでは、ファインチューニングされたモデルをHugging Faceに保存し、共有するプロセスについて説明しています。スクリプトでは、「Hugging Face」という言葉が、モデルを保存し、他のユーザーと共有するためのプラットフォームとして紹介されています。

💡トークン化 (Tokenization)

トークン化は、テキストをモデルが理解できる形の単語やフレーズに分割するプロセスです。ビデオでは、画像とテキストデータをトークンに変換し、モデルにフィードする必要があると説明しています。スクリプトでは、「トークン化」が、データセットをモデルに適合させるために使用される方法として触れられています。

💡トライナー (Trainer)

トライナーは、機械学習のトレーニングプロセスを管理するツールまたはフレームワークです。ビデオでは、トライナーを使用してモデルをトレーニングし、パラメータを調整してパフォーマンスを向上させる方法について説明しています。スクリプトでは、「トライナー」が、モデルのトレーニングとファインチューニングに使用されるコンポーネントとして言及されています。

💡VQA (Visual Question Answering)

VQAは、画像に対する質問に答えることを目的としたタスクです。ビデオでは、VQAバージョン2のデータセットを使用してモデルをトレーニングし、画像とそれに関連する質問と回答をモデルが理解するようにファインチューニングしています。スクリプトでは、「VQA」が、トレーニングデータとして使用されるデータセットのタイプとして説明されています。

Highlights

Introduction to fine-tuning the Pala vision and language model by Google.

Pala's architecture combines image encoding with text input for image understanding.

Comparison between Pala and Lava models, highlighting the use of different encoders and language models.

The process of fine-tuning involves loading datasets, model fine-tuning, and saving to Hugging Face.

Recommendation to subscribe to the YouTube channel for more AI-related content.

Instructions on using a Master compute virtual machine with a discount coupon.

Step-by-step guide to install necessary packages for the project.

Explanation of how to export the Hugging Face token for authentication.

Creation of an app.py file and the initial steps to import necessary libraries.

Loading of the VQA (Visual Question Answering) dataset for training.

Details on how to remove unnecessary columns from the dataset.

Splitting the dataset into training and test sets for model evaluation.

Loading the Pala model with different versions and choosing the appropriate one for the task.

Using bitsandbytes for loading a quantized version of the model to fit GPU limitations.

Setting up the fine-tuning process by defining a collate function for data tokenization.

Configuration of training arguments such as epochs and optimizer.

Utilization of the Trainer class to automate the model training process.

Saving the fine-tuned model to Hugging Face for easy sharing and access.

Demonstration of running the fine-tuning code and the expected output.

Explanation of how to load the fine-tuned model and use it for image recognition tasks.

Potential applications of the fine-tuned model in various fields such as medical imaging.

Closing remarks encouraging viewers to like, share, and subscribe for more content.

Transcripts

play00:00

this is amazing now we going to see

play00:02

about fine-tuning Pala so Pala is Vision

play00:06

language model released by Google in

play00:08

this we are able to give image and also

play00:10

text to understand what is in that image

play00:13

so this is the architecture here the

play00:15

image is encoded using Sig lip and after

play00:19

that it's comined with the text input

play00:23

then we'll get the final output after

play00:26

going through Jemma similarly for

play00:28

another Vision model which is lava we

play00:31

are using clip as the visual encoder and

play00:34

vuna as the lar language model here we

play00:36

are combining jamama and sigp image

play00:39

encoder that is a key difference first

play00:42

is fine-tuning second is saving to

play00:44

hugging face and finally use that fine

play00:47

tune to model that's exactly what we're

play00:50

going to see today let's get

play00:51

[Music]

play00:53

started hi everyone I'm really excited

play00:56

to show you about Pala fine tuning in

play00:59

this we'll be loading data sets loading

play01:01

the model fine-tuning the model and

play01:03

saving that hogging pH as the first step

play01:05

but before that I regularly create

play01:07

videos in regards to Artificial

play01:08

Intelligence on my YouTube channel so do

play01:10

subscribe and click the Bell icon to

play01:11

stay tuned make sure you click the like

play01:13

button so this video can be helpful for

play01:14

many others like you so in this I'm

play01:16

going to use Master compute virtual

play01:18

machine use mvin PR as coupon code to

play01:21

get 50% off so first step pip install

play01:23

and then all these packages such as

play01:25

Transformers data sets PFT bits and buys

play01:28

pillow and then click enter I will put

play01:30

all this information in the description

play01:31

below now next export your hugging face

play01:34

token like this and then click enter now

play01:36

let's create a file called app.py and

play01:37

let's open it first import OS next load

play01:41

data set load from disk now from

play01:43

Transformers We Are importing Palma

play01:44

processor bits and bytes training

play01:47

arguments trainer next importing torch

play01:50

lower config get P model so these are

play01:53

the steps which we going to follow first

play01:54

we are going to load data set next load

play01:56

model then fine-tuning and finally

play01:59

saving to hugging face so loading data

play02:01

set that is Step number one so we are

play02:03

loading data set from vqa version two

play02:07

that is a visual question and answer and

play02:09

we are taking only 10% of the data to

play02:11

keep this tutorial quicker one of the

play02:13

question answering is that how many

play02:16

animals are in the picture we're

play02:18

providing this image and teaching Palama

play02:20

that there are three animals in this

play02:22

picture similarly you can create your

play02:24

own data with question and answers and

play02:27

in this data set we'll have multiple

play02:29

images with with question and answer now

play02:31

we are going to teach the large language

play02:32

model that's why we are loading the data

play02:34

sets from hugging face next we are

play02:37

removing the columns which are not

play02:39

required that is question type answers

play02:41

answer Type image ID and question ID

play02:43

here we are removing in this line next

play02:46

we are splitting the test data and the

play02:48

train data taking the train data and

play02:51

just printing for our reference now step

play02:53

number to loading the model so here we

play02:55

are using Palama 224 so if we see Pala

play02:59

there are are different versions such as

play03:00

224 448 8 96 so these are dimension for

play03:04

the image we are going to use the

play03:06

smallest version for more accuracy you

play03:09

can even use more larger Dimension now

play03:12

we are loading the processor we're going

play03:14

to convert data into tokens next device

play03:17

is Cuda and then image token now here we

play03:20

are defining the model and we are

play03:22

providing the model ID so this is

play03:24

unquantized version of the model next we

play03:26

are going to set the parameter for

play03:29

required gradient to be false so now

play03:32

next step is to make sure that we load

play03:35

the quantise version because of the GPU

play03:38

size we have if you have advanced GPU

play03:40

then go for having a model without any

play03:42

quantization but in our case to make

play03:44

this tutorial quicker I'm going to load

play03:47

quantized model to do that we're going

play03:49

to use bits and bytes so load in for bit

play03:52

that is true next lowerer configuration

play03:54

here we are telling which are the layers

play03:57

we are going to fine tune next we are

play03:59

mentioning the quantization config that

play04:01

is bits and bytes and providing the

play04:03

model ID so here you can see I've just

play04:06

kept this model name in case if you want

play04:07

to use unquantized version but in my

play04:10

case I'm going to use a quantized

play04:12

version that is model with the

play04:13

quantization config next providing the

play04:15

lower config to get PFT model then model

play04:19

dot print trainable parameters that's it

play04:22

this is the model which we are going to

play04:23

use now step number three fine-tuning

play04:26

the model now I'm going to create a

play04:27

function called collate function so in

play04:30

this we are combining all the three data

play04:32

that is the text the labels and the

play04:34

images we're combining all those things

play04:37

converting that to tokens using the

play04:39

processor and then returning the tokens

play04:41

as you probably know this large language

play04:43

model uses tokens to fine tune so the

play04:47

real data is converted to tokens using

play04:49

processor that's you can see here next

play04:51

we need to provide some arguments that

play04:53

is settings for our training so number

play04:55

of epo Optimizer there is atam Optimizer

play04:59

and various other things you can change

play05:01

this according to your requirement and

play05:03

I'm saving that in Palma this folder so

play05:07

next we going to use trainer trainer

play05:09

equals trainer and providing the model

play05:12

that is the context model training data

play05:14

set that is the first load a data set

play05:17

then providing the collate function and

play05:19

arguments next trainer. train this will

play05:22

automatically train the model and the

play05:24

fourth step is to save the model in

play05:26

hugging face trainer. push to HUB then

play05:28

providing the the location so in your

play05:30

case you might need to modify the

play05:32

username and your preferred model name

play05:35

that's it as a quick summary we loaded

play05:37

the data we loaded the model as a

play05:39

quantized version next we are fine

play05:42

tuning the model by combining all the

play05:44

data and converting that to tokens and

play05:47

providing all the settings the trainer.

play05:49

train will train them all and finally we

play05:51

are pushing that to HUB now I'm going to

play05:53

run this code in your terminal Python

play05:55

app.py and then click enter this will

play05:57

automatically download the model and

play05:59

load the shards and it will start

play06:01

training as you can see here we are

play06:03

training 3% of the whole parameters you

play06:06

can see now the fine tuning is complete

play06:08

which means the model is automatically

play06:10

trained and pushed to hugging phas and

play06:13

you can see the model here in hugging

play06:15

facee now this contains only the adapter

play06:19

so we might need to use the whole

play06:21

configuration as you can see here that

play06:23

is p configuration to load the model and

play06:26

here's the code for that the slight

play06:28

modification is that we we are using our

play06:31

own model that is Palama VQ A2 and then

play06:35

we are combining that with the base

play06:36

model that is Google's Palama then we

play06:39

are adding an image this is the image

play06:42

I'm just asking what is in this image

play06:44

and finally printing out the response

play06:46

now I'm going to run this code in your

play06:48

terminal python test.py that's where

play06:49

I've stored my code I need to enter the

play06:52

token for hugging face just to load the

play06:55

model then yes now it's loading the

play06:58

checkpoint and finally here is the

play07:00

response what's in this image a beach

play07:03

yeah as you can see here is a beach we

play07:05

can even train it further more to

play07:08

identify what's exactly in this image

play07:11

and if we want in a specific format

play07:13

there are multiple use cases such as you

play07:15

can add your own images and fine-tune

play07:18

this based on that even this can be used

play07:20

in medical purpose for example you can

play07:22

upload any medical scans and then train

play07:25

this model accordingly I'm really

play07:27

excited about this I'm going to create

play07:29

more videos similar to this so stay

play07:31

tuned I hope you like this video do like

play07:33

share and subscribe and thanks for

play07:34

watching

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
AI技術ファインチューニング画像認識テキスト理解Googleモデルデータセット機械学習Hugging FaceチュートリアルAI教育
¿Necesitas un resumen en inglés?