Downloads · 30 days
6.1K
0% of all-time downloads
Bingsu/clip-vit-base-patch32-ko
clip-vit-base-patch32-ko is a zero-shot image classification model from Bingsu. Use it for the zero-shot image classification task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
Korean CLIP model trained by Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation
Downloads · 30 days
6.1K
0% of all-time downloads
All-time downloads
1.4M
Public
Parameters
151M
4.2 GB on disk
Likes
7
Public
Click a slice to open those files.
.h5606 MB · 33%
How the weights are stored.
F32151M · 100%
From the Hugging Face model README
Korean CLIP model trained by Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation
Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation로 학습된 한국어 CLIP 모델입니다.
훈련 코드: https://github.com/Bing-su/KoCLIP_training_code
사용된 데이터: AIHUB에 있는 모든 한국어-영어 병렬 데이터
import requests
import torch
from PIL import Image
from transformers import AutoModel, AutoProcessor
repo = "Bingsu/clip-vit-base-patch32-ko"
model = AutoModel.from_pretrained(repo)
processor = AutoProcessor.from_pretrained(repo)
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=["고양이 두 마리", "개 두 마리"], images=image, return_tensors="pt", padding=True)
with torch.inference_mode():
outputs = model(**inputs)
logits_per_image = outputs.logits_per_image
probs = logits_per_image.softmax(dim=1)
>>> probs
tensor([[0.9926, 0.0074]])
from transformers import pipeline
repo = "Bingsu/clip-vit-base-patch32-ko"
pipe = pipeline("zero-shot-image-classification", model=repo)
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
result = pipe(images=url, candidate_labels=["고양이 한 마리", "고양이 두 마리", "분홍색 소파에 드러누운 고양이 친구들"], hypothesis_template="{}")
>>> result
[{'score': 0.9456236958503723, 'label': '분홍색 소파에 드러누운 고양이 친구들'},
{'score': 0.05315302312374115, 'label': '고양이 두 마리'},
{'score': 0.0012233294546604156, 'label': '고양이 한 마리'}]
토크나이저는 한국어 데이터와 영어 데이터를 7:3 비율로 섞어, 원본 CLIP 토크나이저에서 .train_new_from_iterator를 통해 학습되었습니다.
# text_embeds.shape = [batch_size, sequence_length, transformer.width]
# take features from the eot embedding (eot_token is the highest number in each sequence)
# casting to torch.int for onnx compatibility: argmax doesn't support int64 inputs with opset 14
pooled_output = last_hidden_state[
torch.arange(last_hidden_state.shape[0]), input_ids.to(torch.int).argmax(dim=-1)
]
CLIP 모델은 pooled_output을 구할때 id가 가장 큰 토큰을 사용하기 때문에, eos 토큰은 가장 마지막 토큰이 되어야 합니다.