suolyer commited on
Commit
5bb6e71
1 Parent(s): 217103e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -0
README.md CHANGED
@@ -1,3 +1,117 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ # inference: false
4
+
5
+ # inference:
6
+ # parameters:
7
+ tags:
8
+ - classification
9
+ - zero-shot
10
  ---
11
+
12
+ # Erlangshen-Albert-235M-UniMC-English
13
+
14
+ - Github: [Fengshenbang-LM](https://github.com/IDEA-CCNL/Fengshenbang-LM)
15
+ - Docs: [Fengshenbang-Docs](https://fengshenbang-doc.readthedocs.io/)
16
+
17
+ ## 简介 Brief Introduction
18
+
19
+ 首个开源的中文CLIP模型,1.23亿图文对上进行预训练的文本端RoBERTa-base
20
+
21
+ The first open source Chinese CLIP, pre-training on 123M image-text pairs, the text encoder: RoBERTa-base.
22
+
23
+ ## 模型分类 Model Taxonomy
24
+
25
+ | 需求 Demand | 任务 Task | 系列 Series | 模型 Model | 参数 Parameter | 额外 Extra |
26
+ | :----: | :----: | :----: | :----: | :----: | :----: |
27
+ | 通用 General | 自然语言理解 NLU | 二郎神 Erlangshen | Albert | 235M | English |
28
+
29
+ ## 模型信息 Model Information
30
+
31
+ 我们遵循CLIP的实验设置,以获得强大的视觉-语言表征。在训练中文版的CLIP时,我们使用[chinese-roberta-wwm](https://huggingface.co/hfl/chinese-roberta-wwm-ext)作为语言的编码器,并将[open_clip](https://github.com/mlfoundations/open_clip)中的**ViT-L-14**应用于视觉的编码器。为了快速且稳定地进行预训练,我们冻结了视觉编码器并且只微调语言编码器。此外,我们将[Noah-Wukong](https://wukong-dataset.github.io/wukong-dataset/)数据集(100M)和[Zero](https://zero.so.com/)数据集(23M)用作预训练的数据集。在悟空数据集和zero数据集上预训练24轮。据我们所知,我们的Taiyi-CLIP是目前Huggingface社区中首个的开源中文CLIP。
32
+
33
+ We follow the experimental setup of CLIP to obtain powerful visual-language intelligence. To obtain the CLIP for Chinese, we employ [chinese-roberta-wwm](https://huggingface.co/hfl/chinese-roberta-wwm-ext) for the language encoder, and apply the **ViT-L-14** in [open_clip](https://github.com/mlfoundations/open_clip) for the vision encoder. We freeze the vision encoder and tune the language encoder to speed up and stabilize the pre-training process. Moreover, we apply [Noah-Wukong](https://wukong-dataset.github.io/wukong-dataset/) dataset (100M) and [Zero](https://zero.so.com/) dataset (23M) as the pre-training datasets. The model was first trained 24 epochs on wukong and zero. To the best of our knowledge, our TaiyiCLIP is currently the only open-sourced Chinese CLIP in the huggingface community.
34
+
35
+ ### 下游效果 Performance
36
+
37
+ **Zero-Shot Classification**
38
+
39
+ | model | dataset | Top1 | Top5 |
40
+ | ---- | ---- | ---- | ---- |
41
+ | Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese | ImageNet1k-CN | 55.04% | 81.75% |
42
+
43
+ **Zero-Shot Text-to-Image Retrieval**
44
+
45
+ | model | dataset | Top1 | Top5 | Top10 |
46
+ | ---- | ---- | ---- | ---- | ---- |
47
+ | Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese | Flickr30k-CNA-test | 58.32% | 82.96% | 89.40% |
48
+ | Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese | COCO-CN-test | 55.27% | 81.10% | 90.78% |
49
+ | Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese | wukong50k | 64.95% | 91.77% | 96.28% |
50
+
51
+ ## 使用 Usage
52
+
53
+ ```python3
54
+ from PIL import Image
55
+ import requests
56
+ import open_clip
57
+ import torch
58
+ from transformers import BertModel, BertConfig, BertTokenizer
59
+ from transformers import CLIPProcessor, CLIPModel
60
+ import numpy as np
61
+
62
+ query_texts = ["一只猫", "一只狗",'两只猫', '两只老虎','一只老虎'] # 这里是输入文本的,可以随意替换。
63
+ # 加载Taiyi 中文 text encoder
64
+ text_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese")
65
+ text_encoder = BertModel.from_pretrained("IDEA-CCNL/Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese").eval()
66
+
67
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg" # 这里可以换成任意图片的url
68
+ # 加载openclip的image encoder
69
+ clip_model, _, processor = open_clip.create_model_and_transforms('ViT-L-14', pretrained='openai')
70
+ clip_model = clip_model.eval()
71
+
72
+
73
+ text = text_tokenizer(query_texts, return_tensors='pt', padding=True)['input_ids']
74
+ image = processor(Image.open(requests.get(url, stream=True).raw)).unsqueeze(0)
75
+ with torch.no_grad():
76
+ image_features = clip_model.encode_image(image)
77
+ text_features = text_encoder(text)[1]
78
+ # 归一化
79
+ image_features = image_features / image_features.norm(dim=1, keepdim=True)
80
+ text_features = text_features / text_features.norm(dim=1, keepdim=True)
81
+ # 计算余弦相似度 logit_scale是尺度系数
82
+ logit_scale = clip_model.logit_scale.exp()
83
+ logits_per_image = logit_scale * image_features @ text_features.t()
84
+ logits_per_text = logits_per_image.t()
85
+ probs = logits_per_image.softmax(dim=-1).cpu().numpy()
86
+ print(np.around(probs, 3))
87
+
88
+ ```
89
+
90
+ ## 引用 Citation
91
+
92
+ 如果您在您的工作中使用了我们的模型,可以引用我们的[论文](https://arxiv.org/abs/2209.02970):
93
+
94
+ If you are using the resource for your work, please cite the our [paper](https://arxiv.org/abs/2209.02970):
95
+
96
+ ```text
97
+ @article{fengshenbang,
98
+ author = {Junjie Wang and Yuxiang Zhang and Lin Zhang and Ping Yang and Xinyu Gao and Ziwei Wu and Xiaoqun Dong and Junqing He and Jianheng Zhuo and Qi Yang and Yongfeng Huang and Xiayu Li and Yanghan Wu and Junyu Lu and Xinyu Zhu and Weifeng Chen and Ting Han and Kunhao Pan and Rui Wang and Hao Wang and Xiaojun Wu and Zhongshen Zeng and Chongpei Chen and Ruyi Gan and Jiaxing Zhang},
99
+ title = {Fengshenbang 1.0: Being the Foundation of Chinese Cognitive Intelligence},
100
+ journal = {CoRR},
101
+ volume = {abs/2209.02970},
102
+ year = {2022}
103
+ }
104
+ ```
105
+
106
+ 也可以引用我们的[网站](https://github.com/IDEA-CCNL/Fengshenbang-LM/):
107
+
108
+ You can also cite our [website](https://github.com/IDEA-CCNL/Fengshenbang-LM/):
109
+
110
+ ```text
111
+ @misc{Fengshenbang-LM,
112
+ title={Fengshenbang-LM},
113
+ author={IDEA-CCNL},
114
+ year={2021},
115
+ howpublished={\url{https://github.com/IDEA-CCNL/Fengshenbang-LM}},
116
+ }
117
+ ```