Update README.md
Browse files
README.md
CHANGED
@@ -5,8 +5,199 @@ language:
|
|
5 |
base_model:
|
6 |
- LiquidAI/LFM2-1.2B
|
7 |
- openai/clip-vit-base-patch32
|
8 |
-
pipeline_tag: text-
|
9 |
library_name: transformers
|
10 |
tags:
|
11 |
- merge
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
base_model:
|
6 |
- LiquidAI/LFM2-1.2B
|
7 |
- openai/clip-vit-base-patch32
|
8 |
+
pipeline_tag: image-text-to-text
|
9 |
library_name: transformers
|
10 |
tags:
|
11 |
- merge
|
12 |
+
datasets:
|
13 |
+
- crag-mm-2025/crag-mm-multi-turn-public
|
14 |
+
---
|
15 |
+
|
16 |
+
# N2-Eye: Multimodal Conversational AI
|
17 |
+
|
18 |
+
N2-Eye is a multimodal language model that combines the power of LiquidAI's LFM2-1.2B language model with OpenAI's CLIP vision encoder to enable image understanding and conversation capabilities.
|
19 |
+
|
20 |
+
## Model Details
|
21 |
+
|
22 |
+
- **Base Language Model**: LiquidAI/LFM2-1.2B (1.26B parameters)
|
23 |
+
- **Vision Encoder**: OpenAI CLIP-ViT-Base-Patch32
|
24 |
+
- **Model Type**: Image-Text-to-Text (Multimodal Conversational)
|
25 |
+
- **Training Dataset**: CRAG-MM Multi-Turn Public Dataset
|
26 |
+
- **License**: MIT
|
27 |
+
- **Framework**: PyTorch + Transformers
|
28 |
+
|
29 |
+
## Architecture
|
30 |
+
|
31 |
+
N2-Eye uses a modular architecture that combines:
|
32 |
+
|
33 |
+
1. **Language Model**: LFM2-1.2B for text generation and conversation
|
34 |
+
2. **Vision Encoder**: CLIP for image understanding (frozen during training)
|
35 |
+
3. **Projection Layer**: A trainable MLP that maps CLIP features to the language model's embedding space
|
36 |
+
|
37 |
+
The model processes images by:
|
38 |
+
- Encoding images with CLIP to extract visual features
|
39 |
+
- Projecting these features through a learnable projection layer
|
40 |
+
- Integrating projected features into the language model at special `<image>` token positions
|
41 |
+
|
42 |
+
## Training Details
|
43 |
+
|
44 |
+
### Dataset
|
45 |
+
- **Source**: CRAG-MM Multi-Turn Public Dataset (v0.1.1)
|
46 |
+
- **Format**: Multi-turn conversations with images
|
47 |
+
- **Preprocessing**: Conversations formatted with ChatML-style tokens
|
48 |
+
|
49 |
+
### Training Configuration
|
50 |
+
- **Batch Size**: 2 per device (with gradient accumulation steps: 4)
|
51 |
+
- **Learning Rate**: 2e-5
|
52 |
+
- **Training Length**: 3 epoch on validation split (we got down to loss 0.703300)
|
53 |
+
- **Precision**: bfloat16
|
54 |
+
- **Max Sequence Length**: 2048 tokens
|
55 |
+
- **Optimization**: Gradient checkpointing enabled
|
56 |
+
|
57 |
+
### Special Tokens
|
58 |
+
- `<image>`: Placeholder for image embeddings in conversation
|
59 |
+
- System prompt: "You are a helpful assistant trained by Liquid AI. You can see and understand images."
|
60 |
+
|
61 |
+
## Usage
|
62 |
+
|
63 |
+
### Basic Inference
|
64 |
+
|
65 |
+
```python
|
66 |
+
# Load model directly
|
67 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
68 |
+
|
69 |
+
tokenizer = AutoTokenizer.from_pretrained("GoofyLM/N2.1-Eye-1.3B", trust_remote_code=True)
|
70 |
+
model = AutoModelForCausalLM.from_pretrained("GoofyLM/N2.1-Eye-1.3B", trust_remote_code=True)
|
71 |
+
messages = [
|
72 |
+
{
|
73 |
+
"role": "user",
|
74 |
+
"content": [
|
75 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
|
76 |
+
{"type": "text", "text": "What animal is on the candy?"}
|
77 |
+
]
|
78 |
+
},
|
79 |
+
]
|
80 |
+
inputs = tokenizer.apply_chat_template(
|
81 |
+
messages,
|
82 |
+
add_generation_prompt=True,
|
83 |
+
tokenize=True,
|
84 |
+
return_dict=True,
|
85 |
+
return_tensors="pt",
|
86 |
+
).to(model.device)
|
87 |
+
|
88 |
+
outputs = model.generate(**inputs, max_new_tokens=40)
|
89 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
|
90 |
+
```
|
91 |
+
|
92 |
+
### Chat Template
|
93 |
+
|
94 |
+
N2-Eye uses an advanced ChatML-based format with support for tools and multimodal content. The model includes a sophisticated Jinja2 template that handles:
|
95 |
+
|
96 |
+
- **System prompts**: Automatically formatted with `<|im_start|>system` tags
|
97 |
+
- **Tool integration**: Special `<|tool_list_start|>` and `<|tool_list_end|>` markers for tool definitions
|
98 |
+
- **Tool responses**: Wrapped with `<|tool_response_start|>` and `<|tool_response_end|>` markers
|
99 |
+
- **Multimodal content**: JSON serialization for complex message content including images
|
100 |
+
|
101 |
+
Basic conversation format:
|
102 |
+
```
|
103 |
+
<|im_start|>system
|
104 |
+
You are a helpful assistant trained by Liquid AI. You can see and understand images.<|im_end|>
|
105 |
+
<image>
|
106 |
+
<|im_start|>user
|
107 |
+
{user_message}<|im_end|>
|
108 |
+
<|im_start|>assistant
|
109 |
+
{assistant_response}<|im_end|>
|
110 |
+
```
|
111 |
+
|
112 |
+
For tool-enabled conversations:
|
113 |
+
```
|
114 |
+
<|im_start|>system
|
115 |
+
{system_prompt}
|
116 |
+
List of tools: <|tool_list_start|>[{tool_definitions}]<|tool_list_end|><|im_end|>
|
117 |
+
<|im_start|>user
|
118 |
+
{user_message}<|im_end|>
|
119 |
+
<|im_start|>assistant
|
120 |
+
{assistant_response}<|im_end|>
|
121 |
+
<|im_start|>tool
|
122 |
+
<|tool_response_start|>{tool_output}<|tool_response_end|><|im_end|>
|
123 |
+
```
|
124 |
+
|
125 |
+
## Capabilities
|
126 |
+
|
127 |
+
N2-Eye can:
|
128 |
+
- **Visual Understanding**: Understand and describe images in detail
|
129 |
+
- **Visual Q&A**: Answer questions about visual content
|
130 |
+
- **Multi-turn Conversations**: Engage in extended conversations that reference images
|
131 |
+
- **Tool Integration**: Support for tool calling and structured responses
|
132 |
+
- **Multimodal Reasoning**: Combine visual and textual information for comprehensive responses
|
133 |
+
- **Structured Output**: Handle complex message formats including JSON content
|
134 |
+
|
135 |
+
## Limitations
|
136 |
+
|
137 |
+
- **Image Token Handling**: Requires specific placement of `<image>` tokens in conversation format
|
138 |
+
- **Single Image**: Currently optimized for single image per conversation
|
139 |
+
- **Training Scale**: Trained on a limited dataset (validation split only)
|
140 |
+
- **Frozen Vision**: CLIP encoder is frozen, limiting adaptation to new visual domains
|
141 |
+
|
142 |
+
## Technical Implementation
|
143 |
+
|
144 |
+
### Model Architecture Classes
|
145 |
+
|
146 |
+
The implementation includes several key components:
|
147 |
+
|
148 |
+
1. **MultimodalLFM2Model**: Main model class combining language and vision
|
149 |
+
2. **CRAGMMDataset**: Dataset handler for CRAG-MM format
|
150 |
+
3. **MultimodalTrainer**: Custom trainer for multimodal inputs
|
151 |
+
|
152 |
+
### Key Features
|
153 |
+
|
154 |
+
- **Gradient Checkpointing**: Memory-efficient training
|
155 |
+
- **Custom Collation**: Handles multimodal batch processing
|
156 |
+
- **Flexible Image Integration**: Dynamic matching of image features to token positions
|
157 |
+
- **Safe Serialization**: Custom saving to handle shared tensors
|
158 |
+
|
159 |
+
## Requirements
|
160 |
+
|
161 |
+
```
|
162 |
+
torch
|
163 |
+
transformers
|
164 |
+
datasets
|
165 |
+
Pillow
|
166 |
+
clip-by-openai
|
167 |
+
```
|
168 |
+
|
169 |
+
## Training Your Own Version
|
170 |
+
|
171 |
+
To retrain or fine-tune N2-Eye:
|
172 |
+
|
173 |
+
1. Install dependencies
|
174 |
+
2. Prepare your dataset in CRAG-MM format
|
175 |
+
3. Modify configuration in the training script
|
176 |
+
4. Run the training pipeline
|
177 |
+
|
178 |
+
See the included training script for complete implementation details.
|
179 |
+
|
180 |
+
## Citation
|
181 |
+
|
182 |
+
If you use N2-Eye in your research, please cite:
|
183 |
+
|
184 |
+
```bibtex
|
185 |
+
@misc{n2eye2025,
|
186 |
+
title={N2-Eye: Multimodal Conversational AI},
|
187 |
+
author={GoofyLM Lab},
|
188 |
+
year={2025},
|
189 |
+
publisher={Hugging Face},
|
190 |
+
howpublished={\url{https://huggingface.co/GoofyLM/N2-Eye-v1-1.3B}}
|
191 |
+
}
|
192 |
+
```
|
193 |
+
|
194 |
+
## Acknowledgments
|
195 |
+
|
196 |
+
- **LiquidAI** for the LFM2-1.2B base model
|
197 |
+
- **OpenAI** for the CLIP vision encoder
|
198 |
+
- **CRAG-MM** dataset contributors for training data
|
199 |
+
- **Hugging Face** for the transformers library and model hosting
|
200 |
+
|
201 |
+
## License
|
202 |
+
|
203 |
+
This model is released under the MIT License. See the LICENSE file for details.
|