benchang1110 commited on
Commit
b548db9
1 Parent(s): 9fed89e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +128 -157
README.md CHANGED
@@ -1,199 +1,170 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
 
 
11
 
 
12
  ## Model Details
13
 
14
- ### Model Description
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
 
 
 
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
55
 
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
 
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
61
 
62
- [More Information Needed]
63
 
64
- ### Recommendations
 
 
 
 
 
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
69
 
70
  ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
126
 
127
- ### Results
128
 
129
- [More Information Needed]
 
 
130
 
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
 
 
 
159
  ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ datasets:
4
+ - benchang1110/TaiVision-pretrain-1M-v2.0
5
+ language:
6
+ - zh
7
+ pipeline_tag: image-text-to-text
8
  ---
9
 
 
 
 
 
10
 
11
+ # Model Card for Model ID
12
 
13
+ ![TaivisionLM](TaivisionLM.png)
14
  ## Model Details
15
 
16
+ ## English
17
+ # TaiVisionLM: The First of Its Kind! 🚀
18
 
19
+ 🌟 This is a small (only 1.2B parameters) visual language model on Hugging Face that responds to Traditional Chinese instructions given an image input! 🌟
20
 
21
+ Developed compatible with the Transformers library, TaiVisionLM is quick to load, fine-tune, and use for lightning-fast inferences without needing any external libraries! ⚡️
22
 
23
+ Ready to experience the Traditional Chinese visual language model? Let's go! 🖼️🤖
 
 
 
 
 
 
24
 
 
25
 
26
+ ## 繁體中文
27
+ # 台視: 台灣視覺語言模型!! 🚀
28
 
29
+ 🌟 TaiVisionLM 是一個小型的視覺語言模型(僅有 12 億參數),可以根據圖像輸入來回覆繁體中文指令!🌟
 
 
30
 
31
+ TaiVisionLM 可以用 transformers 載入、微調和使用!⚡️
32
 
33
+ 準備好體驗"臺視"了嗎?讓我們開始吧!🖼️🤖
34
 
 
35
 
 
36
 
37
+ ---
38
 
39
+ ### Model Description
40
 
41
+ ## English
42
+ This model is a multimodal large language model that combines [SigLIP](https://huggingface.co/google/siglip-base-patch16-224) as its vision encoder with [Tinyllama](https://huggingface.co/benchang1110/Taiwan-tinyllama-v1.0-chat) as its language model. The vision projector connects the two modalities together.
43
+ Its architecture closely resembles [PaliGemma](https://huggingface.co/docs/transformers/v4.44.0/model_doc/paligemma).
44
 
45
+ Here's the summary of the development process:
46
 
47
+ 1) **Unimodal pretraining**
48
+ - In this stage, instead of pretraining both modalities from scratch, I leverage the image encoder from [google/siglip-base-patch16-224-multilingual](https://huggingface.co/google/siglip-base-patch16-224) and the language model trained by ourselves (https://huggingface.co/benchang1110/Taiwan-tinyllama-v1.0-chat).
49
+ 2) **Feature Alignment**
50
+ - We trained the vision projector and language model using LoRA using 1M image-text pairs to align visual and textual features.
51
+ This model is the finetuned version of [benchang1110/TaiVisionLM-base-v1](https://huggingface.co/benchang1110/TaiVisionLM-base-v1). We fintuned the model using 1M image-text pairs. The finetuned model will generate a longer and more detailed description of the image.
52
 
53
+ 3) **Task Specific Training**
54
+ - The aligned model undergoes further training for tasks such as short captioning, detailed captioning, and simple visual question answering.
55
+ We will undergo this stage after the dataset is ready!
56
 
 
57
 
58
+ - **Developed by:** [benchang1110](https://huggingface.co/benchang1110)
59
+ - **Model type:** [Image-Text-to-Text](https://huggingface.co/tasks/image-text-to-text)
60
+ - **Language(s) (NLP):** *Traditional Chinese*
61
 
62
+ ## 繁體中文
63
+ 這個模型是一個多模態的語言模型,結合了 [SigLIP](https://huggingface.co/docs/transformers/en/model_doc/siglip) 作為其視覺編碼器,並使用 [Tinyllama](https://huggingface.co/benchang1110/Taiwan-tinyllama-v1.0-chat) 作為語言模型。視覺投影器將這兩種模態結合在一起。
64
+ 其架構與 [PaliGemma](https://huggingface.co/docs/transformers/v4.44.0/model_doc/paligemma) 非常相似。
65
 
66
+ 以下是開發過程的摘要:
67
 
68
+ 1) **單模態預訓練**
69
+ - 在這個階段,我���用了 [google/siglip-base-patch16-224-multilingual](https://huggingface.co/google/siglip-base-patch16-224-multilingual) 的圖像編碼器,以及我們自己訓練的語言模型([Taiwan-tinyllama-v1.0-chat](https://huggingface.co/benchang1110/Taiwan-tinyllama-v1.0-chat))。
70
+ 2) **特徵對齊**
71
+ - 我們使用了100萬個圖片和文本的配對來訓練圖像投影器 (visual projector),並使用 LoRA 來微調語言模型的權重。
72
+ 這個模型是 [benchang1110/TaiVisionLM-base-v1](https://huggingface.co/benchang1110/TaiVisionLM-base-v1) 的微調版本。我們使用了100萬個圖片和文本的配對來微調模型。微調後的模型將生成更長、更詳細的圖片描述。
73
+ 3) **任務特定訓練**
74
+ - 對齊後的模型將進行進一步的訓練,針對短描述、詳細描述和簡單視覺問答等任務。我們將在數據集準備好後進行這一階段的訓練!
75
 
 
76
 
77
+ - **創作者:** [benchang1110](https://huggingface.co/benchang1110)
78
+ - **模型類型:** [Image-Text-to-Text](https://huggingface.co/tasks/image-text-to-text)
79
+ - **語言:** 繁體中文
80
+
81
+ ---
82
 
83
  ## How to Get Started with the Model
84
 
85
+ ## English
86
+
87
+ In Transformers, you can load the model and do inference as follows:
88
+
89
+ **IMPORTANT NOTE:** TaiVisionLM model is not yet integrated natively into the Transformers library. So you need to set ```trust_remote_code=True``` when loading the model. It will download the ```configuration_taivisionlm.py```, ```modeling_taivisionlm.py``` and ```processing_taivisionlm.py``` files from the repo. You can check out the content of these files under the *Files and Versions* tab and pin the specific versions if you have any concerns regarding malicious code.
90
+
91
+ ```python
92
+ from transformers import AutoProcessor, AutoModelForCausalLM, AutoConfig
93
+ from PIL import Image
94
+ import requests
95
+ import torch
96
+ config = AutoConfig.from_pretrained("benchang1110/TaiVisionLM-base-v2",trust_remote_code=True)
97
+ processor = AutoProcessor.from_pretrained("benchang1110/TaiVisionLM-base-v2",trust_remote_code=True)
98
+ model = AutoModelForCausalLM.from_pretrained("benchang1110/TaiVisionLM-base-v2",trust_remote_code=True,torch_dtype=torch.float16,attn_implementation="sdpa").to('cuda')
99
+ model.eval()
100
+ url = "https://media.wired.com/photos/598e35fb99d76447c4eb1f28/master/pass/phonepicutres-TA.jpg"
101
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
102
+ text = "描述圖片"
103
+ inputs = processor(text=text,images=image, return_tensors="pt",padding=False).to('cuda')
104
+ outputs = processor.tokenizer.decode(model.generate(**inputs,max_length=512)[0])
105
+ print(outputs)
106
+ ```
107
+
108
+ ## 中文
109
+ 利用 transformers,可以用下面程式碼進行推論:
110
+
111
+ **重要通知:** 台視 (TaiVisionLM) 還沒被整合進transformers,因此在下載模型時要使用 ```trust_remote_code=True```,下載模型將會使用```configuration_taivisionlm.py```、 ```modeling_taivisionlm.py``` 和 ```processing_taivisionlm.py``` 這三個檔案,若擔心有惡意程式碼,請先點選右方 *Files and Versions* 來查看程式碼內容。
112
+
113
+ ```python
114
+ from transformers import AutoProcessor, AutoModelForCausalLM, AutoConfig
115
+ from PIL import Image
116
+ import requests
117
+ import torch
118
+ config = AutoConfig.from_pretrained("benchang1110/TaiVisionLM-base-v2",trust_remote_code=True)
119
+ processor = AutoProcessor.from_pretrained("benchang1110/TaiVisionLM-base-v2",trust_remote_code=True)
120
+ model = AutoModelForCausalLM.from_pretrained("benchang1110/TaiVisionLM-base-v2",trust_remote_code=True,torch_dtype=torch.float16,attn_implementation="sdpa").to('cuda')
121
+ model.eval()
122
+ url = "https://media.wired.com/photos/598e35fb99d76447c4eb1f28/master/pass/phonepicutres-TA.jpg"
123
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
124
+ text = "描述圖片"
125
+ inputs = processor(text=text,images=image, return_tensors="pt",padding=False).to('cuda')
126
+ outputs = processor.tokenizer.decode(model.generate(**inputs,max_length=512)[0])
127
+ print(outputs)
128
+ ```
129
+
130
+
131
+ ### Comparision with prior model ([benchang1110/TaiVisionLM-base-v1](https://huggingface.co/benchang1110/TaiVisionLM-base-v1))
132
+
133
+ - **Example 1**
134
+ ![smile](https://www.slidecow.com/wp-content/uploads/2018/04/Setting-Up-The-Slide-Text-1000x563.jpg)
135
+ * TaiVisionLM-base-v1:
136
+ 卡通插圖描繪掛在家門口的標誌,上下方以卡通插圖的方式呈現。
137
+ * TaiVisionLM-base-v2:
138
+ 這張圖描繪了一個單詞「SMILE」經典的卡通字體。該字表面��黑白的主要色彩調色板。詞以貫穿其身體的光滑線條字體書寫。該字具有模糊的質感,與單詞形成平滑而簡約的視覺效果。
139
+ 字母「「SMILE」」自豪地表示。顯眼的文字是圖片的焦點,吸引觀眾的注意力到其具有簡潔性的方式。該字在白色背景上顯眼地展示,與黑色字體形成鮮明對比。
140
+ 圖片中沒有其他物品或文字。字和底部的文字並沒有提供有關詞「「SMILE」具體含義的任何其他背景信息。然而,詞「「SMILE」」的整體設計使其成為這張影像中的焦點,吸引了注意力到其獨特形狀。圖片中沒有其他物品或文字。
141
+
142
+
143
+ - **Example 2**
144
+ ![paris](https://static.toiimg.com/thumb/msid-53891743,width-748,height-499,resizemode=4,imgsize-152022/.jpg)
145
+ * TaiVisionLM-base-v1:
146
+ 這是一幅攝影作品,展示了巴黎的鐵塔被水景所環繞
147
+ * TaiVisionLM-base-v2:
148
+ 這張照片捕捉了巴黎,法國標誌性的塔樓和人行道景觀的令人驚嘆的景象。塔樓高聳在清澈的藍天沿著舊有大路的背景之上。它是一座高聳入雲的圓頂金屬圖案,高度被分數精確錯量。塔樓由金屬和石頭結構組成,其統一的形狀證明了其歷史意義。
149
+ 塔樓東面延伸的人行道向遠處延伸,邀請路人探索它所有的美麗。這條人行道上排列著樹木,它們翠綠的葉片與藍天形成鮮明的對比。它們的存在為場景增添了一抹綠意,為都市景觀增添了一抹自然元素。
150
+ 背景中可以看到巴黎城市景觀。各種大小和設計的建築物可以看到,它們矗立在背景中,它們的建築藝術被塔樓和人行道的視野所突顯。天空是一個清澈的藍色,它延伸到遠方,沒有任何雲彩的陰影。
151
+
152
+ 這張照片是巴黎豐富歷史和現代性的一個見證。塔樓和人行道標誌著這座經典都市的地標,高聳主權人偶的高度及其證據這座城市獨特的信仰。橫跨整張照片的人行道禮貌地介紹了城市的繁忙路線。
153
  ### Training Procedure
154
 
155
+ Since we don't have enough resources to train the model on the whole dataset, we only use 250k image-text pairs for training. The following training hyperparameters are used in feature alignment and task specific training stages respectively:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
 
157
 
158
+ - **Feature Alignment**
159
 
160
+ | Data size | Global Batch Size | Learning Rate | Epochs | Max Length | Weight Decay |
161
+ |--------------|-------------------|---------------|--------|------------|--------------|
162
+ | 250k | 2 | 5e-5 | 1 | 2048 | 1e-5 |
163
 
164
+ We use full-parameter finetuning for the projector and apply LoRA to the language model.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
+ We will update the training procedure once we have more resources to train the model on the whole dataset.
167
+ ![metric](metrics.png)
168
  ### Compute Infrastructure
169
+ - **Feature Alignment**
170
+ 1xV100(32GB), took approximately 12 GPU hours.