adventureshin
commited on
Commit
•
1f78ae1
1
Parent(s):
cea4dfc
Upload 9 files
Browse files- README.md +66 -0
- config.json +162 -0
- model.safetensors +3 -0
- preprocessor_config.json +21 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- clip
|
4 |
+
language: ko
|
5 |
+
license: mit
|
6 |
+
---
|
7 |
+
|
8 |
+
# vitB32_bert_ko_small_clip
|
9 |
+
|
10 |
+
[openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32) + [lassl/bert-ko-small](https://huggingface.co/lassl/bert-ko-small) CLIP Model
|
11 |
+
|
12 |
+
[training code(github)](https://github.com/Bing-su/KoCLIP_training_code)
|
13 |
+
|
14 |
+
## Train
|
15 |
+
|
16 |
+
SBERT의 [Making Monolingual Sentence Embeddings Multilingual using Knowledge Distillation](https://arxiv.org/abs/2004.09813)를 참고하여, `openai/clip-vit-base-patch32` 텍스트 모델의 가중치를 `lassl/bert-ko-small`로 복제하였습니다. 논문과는 달리 mean pooling을 사용하지 않고, huggingface모델의 기본 pooling을 그대로 사용하였습니다.
|
17 |
+
|
18 |
+
사용한 데이터: [Aihub 한국어-영어 번역(병렬) 말뭉치](https://aihub.or.kr/aidata/87)
|
19 |
+
|
20 |
+
|
21 |
+
## How to Use
|
22 |
+
|
23 |
+
#### 1.
|
24 |
+
|
25 |
+
```python
|
26 |
+
import requests
|
27 |
+
from PIL import Image
|
28 |
+
from transformers import VisionTextDualEncoderProcessor, VisionTextDualEncoderModel # or Auto...
|
29 |
+
|
30 |
+
model = VisionTextDualEncoderModel.from_pretrained("Bingsu/vitB32_bert_ko_small_clip")
|
31 |
+
processor = VisionTextDualEncoderProcessor.from_pretrained("Bingsu/vitB32_bert_ko_small_clip")
|
32 |
+
|
33 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
34 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
35 |
+
|
36 |
+
inputs = processor(text=["고양이 두 마리", "개 두 마리"], images=image, return_tensors="pt", padding=True)
|
37 |
+
|
38 |
+
outputs = model(**inputs)
|
39 |
+
logits_per_image = outputs.logits_per_image
|
40 |
+
probs = logits_per_image.softmax(dim=1)
|
41 |
+
```
|
42 |
+
|
43 |
+
```pycon
|
44 |
+
>>> probs
|
45 |
+
tensor([[0.9756, 0.0244]], grad_fn=<SoftmaxBackward0>)
|
46 |
+
```
|
47 |
+
|
48 |
+
#### 2.
|
49 |
+
|
50 |
+
```python
|
51 |
+
from transformers import AutoModel, AutoProcessor, pipeline
|
52 |
+
|
53 |
+
model = AutoModel.from_pretrained("Bingsu/vitB32_bert_ko_small_clip")
|
54 |
+
processor = AutoProcessor.from_pretrained("Bingsu/vitB32_bert_ko_small_clip")
|
55 |
+
pipe = pipeline("zero-shot-image-classification", model=model, feature_extractor=processor.feature_extractor, tokenizer=processor.tokenizer)
|
56 |
+
|
57 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
58 |
+
result = pipe(images=url, candidate_labels=["고양이 한 마리", "고양이 두 마리", "고양이 두 마리와 리모컨 두 개"], hypothesis_template="{}")
|
59 |
+
```
|
60 |
+
|
61 |
+
```pycon
|
62 |
+
>>> result
|
63 |
+
[{'score': 0.871887743473053, 'label': '고양이 두 마리와 리모컨 두 개'},
|
64 |
+
{'score': 0.12316706776618958, 'label': '고양이 두 마리'},
|
65 |
+
{'score': 0.004945191089063883, 'label': '고양이 한 마리'}]
|
66 |
+
```
|
config.json
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "Bingsu/vitB32_bert_ko_small_clip",
|
3 |
+
"architectures": [
|
4 |
+
"VisionTextDualEncoderModel"
|
5 |
+
],
|
6 |
+
"logit_scale_init_value": 2.6592,
|
7 |
+
"model_type": "vision-text-dual-encoder",
|
8 |
+
"projection_dim": 512,
|
9 |
+
"text_config": {
|
10 |
+
"_name_or_path": "lassl/bert-ko-small",
|
11 |
+
"add_cross_attention": false,
|
12 |
+
"architectures": [
|
13 |
+
"BertForPreTraining"
|
14 |
+
],
|
15 |
+
"attention_probs_dropout_prob": 0.1,
|
16 |
+
"bad_words_ids": null,
|
17 |
+
"bos_token_id": null,
|
18 |
+
"chunk_size_feed_forward": 0,
|
19 |
+
"classifier_dropout": 0.1,
|
20 |
+
"cross_attention_hidden_size": null,
|
21 |
+
"decoder_start_token_id": null,
|
22 |
+
"diversity_penalty": 0.0,
|
23 |
+
"do_sample": false,
|
24 |
+
"early_stopping": false,
|
25 |
+
"encoder_no_repeat_ngram_size": 0,
|
26 |
+
"eos_token_id": null,
|
27 |
+
"exponential_decay_length_penalty": null,
|
28 |
+
"finetuning_task": null,
|
29 |
+
"forced_bos_token_id": null,
|
30 |
+
"forced_eos_token_id": null,
|
31 |
+
"hidden_act": "gelu",
|
32 |
+
"hidden_dropout_prob": 0.1,
|
33 |
+
"hidden_size": 256,
|
34 |
+
"id2label": {
|
35 |
+
"0": "LABEL_0",
|
36 |
+
"1": "LABEL_1"
|
37 |
+
},
|
38 |
+
"initializer_range": 0.02,
|
39 |
+
"intermediate_size": 1024,
|
40 |
+
"is_decoder": false,
|
41 |
+
"is_encoder_decoder": false,
|
42 |
+
"label2id": {
|
43 |
+
"LABEL_0": 0,
|
44 |
+
"LABEL_1": 1
|
45 |
+
},
|
46 |
+
"layer_norm_eps": 1e-05,
|
47 |
+
"length_penalty": 1.0,
|
48 |
+
"max_length": 20,
|
49 |
+
"max_position_embeddings": 512,
|
50 |
+
"min_length": 0,
|
51 |
+
"model_type": "bert",
|
52 |
+
"no_repeat_ngram_size": 0,
|
53 |
+
"num_attention_heads": 4,
|
54 |
+
"num_beam_groups": 1,
|
55 |
+
"num_beams": 1,
|
56 |
+
"num_hidden_layers": 12,
|
57 |
+
"num_return_sequences": 1,
|
58 |
+
"output_attentions": false,
|
59 |
+
"output_hidden_states": false,
|
60 |
+
"output_scores": false,
|
61 |
+
"pad_token_id": 0,
|
62 |
+
"position_embedding_type": "absolute",
|
63 |
+
"prefix": null,
|
64 |
+
"problem_type": null,
|
65 |
+
"pruned_heads": {},
|
66 |
+
"remove_invalid_values": false,
|
67 |
+
"repetition_penalty": 1.0,
|
68 |
+
"return_dict": true,
|
69 |
+
"return_dict_in_generate": false,
|
70 |
+
"sep_token_id": null,
|
71 |
+
"task_specific_params": null,
|
72 |
+
"temperature": 1.0,
|
73 |
+
"tie_encoder_decoder": false,
|
74 |
+
"tie_word_embeddings": true,
|
75 |
+
"tokenizer_class": null,
|
76 |
+
"top_k": 50,
|
77 |
+
"top_p": 1.0,
|
78 |
+
"torch_dtype": "float32",
|
79 |
+
"torchscript": false,
|
80 |
+
"transformers_version": "4.19.2",
|
81 |
+
"type_vocab_size": 2,
|
82 |
+
"typical_p": 1.0,
|
83 |
+
"use_bfloat16": false,
|
84 |
+
"use_cache": true,
|
85 |
+
"vocab_size": 51200
|
86 |
+
},
|
87 |
+
"torch_dtype": "float32",
|
88 |
+
"transformers_version": null,
|
89 |
+
"vision_config": {
|
90 |
+
"_name_or_path": "openai/clip-vit-base-patch32",
|
91 |
+
"add_cross_attention": false,
|
92 |
+
"architectures": null,
|
93 |
+
"attention_dropout": 0.0,
|
94 |
+
"bad_words_ids": null,
|
95 |
+
"bos_token_id": null,
|
96 |
+
"chunk_size_feed_forward": 0,
|
97 |
+
"cross_attention_hidden_size": null,
|
98 |
+
"decoder_start_token_id": null,
|
99 |
+
"diversity_penalty": 0.0,
|
100 |
+
"do_sample": false,
|
101 |
+
"dropout": 0.0,
|
102 |
+
"early_stopping": false,
|
103 |
+
"encoder_no_repeat_ngram_size": 0,
|
104 |
+
"eos_token_id": null,
|
105 |
+
"exponential_decay_length_penalty": null,
|
106 |
+
"finetuning_task": null,
|
107 |
+
"forced_bos_token_id": null,
|
108 |
+
"forced_eos_token_id": null,
|
109 |
+
"hidden_act": "quick_gelu",
|
110 |
+
"hidden_size": 768,
|
111 |
+
"id2label": {
|
112 |
+
"0": "LABEL_0",
|
113 |
+
"1": "LABEL_1"
|
114 |
+
},
|
115 |
+
"image_size": 224,
|
116 |
+
"initializer_factor": 1.0,
|
117 |
+
"initializer_range": 0.02,
|
118 |
+
"intermediate_size": 3072,
|
119 |
+
"is_decoder": false,
|
120 |
+
"is_encoder_decoder": false,
|
121 |
+
"label2id": {
|
122 |
+
"LABEL_0": 0,
|
123 |
+
"LABEL_1": 1
|
124 |
+
},
|
125 |
+
"layer_norm_eps": 1e-05,
|
126 |
+
"length_penalty": 1.0,
|
127 |
+
"max_length": 20,
|
128 |
+
"min_length": 0,
|
129 |
+
"model_type": "clip_vision_model",
|
130 |
+
"no_repeat_ngram_size": 0,
|
131 |
+
"num_attention_heads": 12,
|
132 |
+
"num_beam_groups": 1,
|
133 |
+
"num_beams": 1,
|
134 |
+
"num_hidden_layers": 12,
|
135 |
+
"num_return_sequences": 1,
|
136 |
+
"output_attentions": false,
|
137 |
+
"output_hidden_states": false,
|
138 |
+
"output_scores": false,
|
139 |
+
"pad_token_id": null,
|
140 |
+
"patch_size": 32,
|
141 |
+
"prefix": null,
|
142 |
+
"problem_type": null,
|
143 |
+
"pruned_heads": {},
|
144 |
+
"remove_invalid_values": false,
|
145 |
+
"repetition_penalty": 1.0,
|
146 |
+
"return_dict": true,
|
147 |
+
"return_dict_in_generate": false,
|
148 |
+
"sep_token_id": null,
|
149 |
+
"task_specific_params": null,
|
150 |
+
"temperature": 1.0,
|
151 |
+
"tie_encoder_decoder": false,
|
152 |
+
"tie_word_embeddings": true,
|
153 |
+
"tokenizer_class": null,
|
154 |
+
"top_k": 50,
|
155 |
+
"top_p": 1.0,
|
156 |
+
"torch_dtype": null,
|
157 |
+
"torchscript": false,
|
158 |
+
"transformers_version": "4.19.2",
|
159 |
+
"typical_p": 1.0,
|
160 |
+
"use_bfloat16": false
|
161 |
+
}
|
162 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b3fc251be7844996114de04b8a499032bd1f577d82e3380267a19ea85a450fa8
|
3 |
+
size 443105628
|
preprocessor_config.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"crop_size": 224,
|
3 |
+
"do_center_crop": true,
|
4 |
+
"do_convert_rgb": true,
|
5 |
+
"do_normalize": true,
|
6 |
+
"do_resize": true,
|
7 |
+
"feature_extractor_type": "CLIPFeatureExtractor",
|
8 |
+
"image_mean": [
|
9 |
+
0.48145466,
|
10 |
+
0.4578275,
|
11 |
+
0.40821073
|
12 |
+
],
|
13 |
+
"image_std": [
|
14 |
+
0.26862954,
|
15 |
+
0.26130258,
|
16 |
+
0.27577711
|
17 |
+
],
|
18 |
+
"processor_class": "VisionTextDualEncoderProcessor",
|
19 |
+
"resample": 3,
|
20 |
+
"size": 224
|
21 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0f9fd5f573fa3c1acfa2bcef605f290a2748141dbc7566d6c2943bc87c0e7134
|
3 |
+
size 443187803
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": false, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "Bingsu/vitB32_bert_ko_small_clip", "processor_class": "VisionTextDualEncoderProcessor", "tokenizer_class": "BertTokenizer"}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|