Kakao Brain ViT 與 ALIGN 模型發布,搭配 COYO 700M 資料集
TL;DR
Kakao Brain 與 Hugging Face 已開源兩個視覺語言模型——ViT 與 ALIGN——這些模型以全新的 700 M 圖文 COYO 資料集訓練,標誌著首個公開發布的 ALIGN 模型以及首批與開放訓練語料搭配的 ViT/ALIGN 模型。
發布內容
- COYO dataset – 從網路收集的 700 M 圖文配對,以開源授權發布。
- ViT models – 依照 Google ViT 的架構與超參數設計的視覺 Transformer,於 COYO‑Labeled‑300M 子集上訓練。
- ALIGN models – 與 Google ALIGN 架構相同的雙編碼器圖文模型,於完整的 COYO 資料集上訓練。
- Demo spaces and pipelines – 在 Hugging Face Hub 上的互動示範,以及可直接使用的
transformerspipeline,支援分類與零樣本任務。
效能比較
- ALIGN‑B7‑Base 於 700 M 配對上訓練,其在 Image KNN 分類上與 Google 的 ALIGN‑B7‑Base 相匹配,且在 MS‑COCO 圖文檢索(image‑to‑text 與 text‑to‑image)上超越其表現。
- ViT‑L/16 在 384 px 與 512 px 解析度下,於 ImageNet 與 ImageNet‑ReaL 的準確度與 Google 的 ViT‑L/16 相當。
- 這些結果顯示,即使僅使用部分專有資料規模,開源模型亦能達到最先進的效能。
COYO 資料集細節
- 規模:700 M 英文圖文配對(過濾後約 747 M)。
- 來源:於 2020 年 10 月至 2021 年 8 月期間爬取的網頁(Common Crawl)。
- 中繼資料:包含 CLIP 相似度分數(ViT‑B/32 與 ViT‑L/14)、NSFW 分數、水印分數、美學分數,以及人臉計數資料。
- Differences from LAION‑2B:
| 特徵 | COYO | LAION‑2B |
|---|---|---|
| 規模 | 700 M | 2 B |
| 相似度分數 | CLIP‑B/32 & L/14,未篩選 | CLIP‑B/32,門檻 0.28 |
| NSFW 篩選 | 圖片與文字皆篩選 | 僅圖片 |
| 人臉計數 | 有提供 | 未提供 |
| 水印分數 | 穩健指標 | 基礎分數 |
| 可取得性 | Hugging Face Hub | Hugging Face Hub |
ViT 工作原理
ViT 將影像切割成固定大小的 patch,對每個 patch 進行嵌入,加入位置嵌入,並以標準的 Transformer 編碼器處理序列。 此設計相較於同等的 CNN 可提升至多四倍的計算效率,同時保持領域無關性。 Kakao Brain 的 ViT 模型採用與 Google ViT 相同的架構,但在公開發布的 COYO‑Labeled‑300M 子集上訓練,使得完整可重現。
ALIGN 工作原理
ALIGN 採用雙編碼器:影像編碼器處理圖片,文字編碼器處理說明文字,並以對比損失於噪聲 alt‑text 配對上訓練。 這個噪聲且大規模的訓練語料庫(最初為 1.8 B 配對)使得 ALIGN 在跨模態檢索與零樣本分類上表現卓越。 Kakao Brain 的 ALIGN 模型是此架構的首個開源實作,於 700 M COYO 配對上訓練,且其效能達到或超過 Google 所報告的數值。
使用 COYO 資料集
from datasets import load_dataset
# Load the full dataset (may be large)
full = load_dataset('kakaobrain/coyo-700m')
# Stream a subset to avoid downloading everything
stream = load_dataset('kakaobrain/coyo-700m', streaming=True)
print(next(iter(stream['train'])))
串流的範例會顯示欄位,例如 url、text、width、height、clip_similarity_vitb32、nsfw_score_opennsfw2、watermark_score 與 aesthetic_score_laion_v2。
ViT 快速入門
import requests, torch
from PIL import Image
from transformers import ViTImageProcessor, ViTForImageClassification
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
processor = ViTImageProcessor.from_pretrained('kakaobrain/vit-large-patch16-384')
model = ViTForImageClassification.from_pretrained('kakaobrain/vit-large-patch16-384')
inputs = processor(images=image, return_tensors='pt')
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.nn.functional.softmax(logits, dim=-1)
top5 = torch.argsort(probs, descending=True)[0, :5]
for idx in top5:
print(f"{model.config.id2label[idx.item()]}: {probs[0, idx].item():.4f}")
或使用高階 pipeline:
from transformers import pipeline
classifier = pipeline('image-classification', model='kakaobrain/vit-large-patch16-384')
print(classifier('http://images.cocodataset.org/val2017/000000039769.jpg', top_k=5))
ALIGN 快速入門
from transformers import AlignProcessor, AlignModel
import requests, torch
from PIL import Image
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
processor = AlignProcessor.from_pretrained('kakaobrain/align-base')
model = AlignModel.from_pretrained('kakaobrain/align-base')
candidate_labels = ['an image of a cat', 'an image of a dog']
inputs = processor(images=image, text=candidate_labels, return_tensors='pt')
with torch.no_grad():
logits = model(**inputs).logits_per_image
probs = logits.softmax(dim=1)
print(probs)
透過 pipeline 進行零樣本分類:
from transformers import pipeline
classifier = pipeline('zero-shot-image-classification', model='kakaobrain/align-base')
print(classifier('https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png',
candidate_labels=['animals', 'humans', 'landscape']))
模型亦提供 get_image_features 與 get_text_features,供下游基於嵌入的任務使用。
對研究社群的影響
- 可重現性:研究人員現在可以複製 Google 規模的 ViT 與 ALIGN 實驗,因為模型與精確的訓練資料皆已公開。
- 可取得性:開源的 ALIGN 模型消除了缺乏專有數十億配對資料集的實驗室的一大障礙。
- 基準測試:由於 COYO 包含豐富的中繼資料(美學、水印、人臉計數),因此可對過濾子集進行更細緻的模型行為分析。
- 未來工作:社群可以擴充 COYO,與其他資料集(如 LAION)結合,或針對特定領域微調已發布的模型,同時保持完整透明性。
所有程式碼片段皆假設使用較新版的 transformers(或 ALIGN 的開發分支)以及透過 pip install datasets 安裝的 datasets 套件。