Ainsteinx Logo
Ainsteinx
👤
ຍິນດີຕ້ອນຮັບສູ່ Ainsteinx
ເຂົ້າສູ່ລະບົບ

ປ່ຽນພາສາ

ສະກຸນເງິນ

ໜ້າທຳອິດ
ບົດຄວາມ
ບໍລິການ
ບົດ 13 · ການນຳໃຊ້

Multimodal: DALL·E 2, Imagen, Stable Diffusion

ພິມຂໍ້ຄວາມ ໄດ້ຮູບ: ເຊື່ອມພາສາ ແລະ ພາບເຂົ້າກັນ.

Multimodal model ເຊື່ອມຂໍ້ມູນຫຼາຍຊະນິດ. CLIP ຮຽນໃຫ້ຮູບ ແລະ ຂໍ້ຄວາມທີ່ຕົງກັນມີ embedding ໃກ້ກັນ (contrastive learning). DALL·E 2 ໃຊ້ CLIP + diffusion, Imagen ໃຊ້ text encoder ທີ່ຝຶກແຕ່ຂໍ້ຄວາມ, Stable Diffusion ເຮັດ diffusion ໃນ latent space ຈຶ່ງເບົາພໍລັນໃນຄອມເອງ, ສ່ວນ Flamingo ເຊື່ອມຮູບເຂົ້າກັບ language model.

ໂຄດຕົວຢ່າງຝຶກ CLIP ຂະໜາດນ້ອຍ: ກ່ອນຝຶກຈັບຄູ່ຮູບ–ຂໍ້ຄວາມຖືກ 0%, ຫຼັງຝຶກຖືກ 100%.

logits = norm(img_emb) · norm(txt_emb)ᵀ / τ loss = ½ [ CE(logits, I) + CE(logitsᵀ, I) ] ← ຄູ່ທີ່ຖືກຢູ່ເສັ້ນທະແຍງ
Modelວິທີເຮັດວຽກ
DALL·E 2ຂໍ້ຄວາມ → CLIP embedding → prior → diffusion decoder
ImagenText encoder (T5) + diffusion ຫຼາຍຂັ້ນ ເພີ່ມຄວາມລະອຽດ
Stable DiffusionDiffusion ໃນ latent space ຂອງ autoencoder, open-source
Flamingoເອົາຮູບ/ວິດີໂອເຂົ້າ language model ທີ່ຝຶກແລ້ວ

ສິ່ງທີ່ຄວນຈື່

  • CLIP ແມ່ນ "ຂົວ" ລະຫວ່າງພາສາ ແລະ ພາບ
  • Text-to-image ສ່ວນໃຫຍ່ = text encoder + diffusion
generative-ai-ep13-multimodal.py
import torch, torch.nn as nn

torch.manual_seed(0)
# Toy paired data: 64 "concepts", each seen as an image vector and a text vector
concepts = torch.randn(64, 16)
images = concepts @ torch.randn(16, 32) + 0.1 * torch.randn(64, 32)
texts = concepts @ torch.randn(16, 24) + 0.1 * torch.randn(64, 24)

img_enc, txt_enc = nn.Linear(32, 16), nn.Linear(24, 16)
opt = torch.optim.Adam([*img_enc.parameters(), *txt_enc.parameters()], lr=1e-2)

def retrieval_acc():
    with torch.no_grad():
        i = nn.functional.normalize(img_enc(images), dim=1)
        t = nn.functional.normalize(txt_enc(texts), dim=1)
        return ((i @ t.T).argmax(1) == torch.arange(64)).float().mean().item()

print(f"before training: text->image match {retrieval_acc():.0%}")
for step in range(300):
    i = nn.functional.normalize(img_enc(images), dim=1)
    t = nn.functional.normalize(txt_enc(texts), dim=1)
    logits = i @ t.T / 0.07                                # similarity of every pair
    labels = torch.arange(64)                              # matching pairs are on the diagonal
    loss = (nn.functional.cross_entropy(logits, labels) +
            nn.functional.cross_entropy(logits.T, labels)) / 2   # CLIP contrastive loss
    opt.zero_grad(); loss.backward(); opt.step()
print(f"after training:  text->image match {retrieval_acc():.0%}  (loss {loss.item():.3f})")

ຜົນລັບ

before training: text->image match 0%
after training:  text->image match 100%  (loss 0.008)
  • #GenerativeAI
  • #DeepLearning
  • #PythonສຳລັບຄົນLaos
  • #AI
  • #ບອກຕໍ່ຄວາມຮູ້