Downloads · 30 days
0
c6oisini/Qwen3-VL-8B-embedding
Qwen3-VL-8B-embedding is a feature extraction model from c6oisini. Use it when you need embeddings to search or compare text. It is set up for transformers. The card lists the license as apache-2.0.
提取自 Qwen3-VL-8B-Instruct 的轻量级多模态 embedding 模型,专为 RAG 和多模态检索场景设计。
Downloads · 30 days
0
Access
Public
Updated Mar 9, 2026
Repo size
6 GB
Likes
2
Public
Click a slice to open those files.
.safetensors6 GB · 100%
From the Hugging Face model README
提取自 Qwen3-VL-8B-Instruct 的轻量级多模态 embedding 模型,专为 RAG 和多模态检索场景设计。
Lightweight multimodal embedding model extracted from Qwen3-VL-8B-Instruct, designed for RAG and multimodal retrieval.
pip install torch transformers safetensors pillow
import sys
from pathlib import Path
# 将模型目录添加到路径
sys.path.insert(0, '.')
from qwen3vl_embedding import load_embedding_model
from transformers import AutoTokenizer
# 加载模型
model = load_embedding_model('.', device='cuda')
# 加载 tokenizer(需要从原始 Qwen3-VL 模型下载)
tokenizer = AutoTokenizer.from_pretrained(
'Qwen/Qwen3-VL-8B-Instruct',
trust_remote_code=True
)
# 单个文本
text = "机器学习是人工智能的重要分支"
embedding = model.encode_text(text, tokenizer, normalize=True)
print(embedding.shape) # torch.Size([1, 4096])
# 批量文本
texts = ["你好世界", "Hello world", "深度学习"]
embeddings = model.encode_text(texts, tokenizer, normalize=True)
# 计算相似度
import torch
similarity = torch.mm(embeddings, embeddings.T)
print(similarity)
from PIL import Image
# 单张图片
image = Image.open("example.jpg")
embedding = model.encode_image(image, normalize=True)
# 批量图片
images = ["image1.jpg", "image2.jpg", "image3.jpg"]
embeddings = model.encode_image(images, normalize=True)
# 支持 URL
image_url = "https://example.com/image.jpg"
embedding = model.encode_image(image_url, normalize=True)
# 视频自动抽帧编码
video_path = "example.mp4"
embedding = model.encode_video(
video_path,
fps=2.0, # 每秒采样帧数
max_frames=32, # 最大帧数
normalize=True
)
# 文本查询图像
query_text = "一只可爱的猫"
query_emb = model.encode_text(query_text, tokenizer, normalize=True)
image_paths = ["cat1.jpg", "dog1.jpg", "cat2.jpg"]
image_embs = model.encode_image(image_paths, normalize=True)
# 计算相似度并排序
scores = torch.mm(query_emb, image_embs.T)[0]
for img, score in sorted(zip(image_paths, scores), key=lambda x: x[1], reverse=True):
print(f"{img}: {score:.4f}")
| 模型 | 大小 | 文本编码速度 | 图像编码速度 |
|---|---|---|---|
| Qwen3-VL-8B-Instruct (完整) | 17GB | 1x | 1x |
| Qwen3-VL-8B-Embedding (本模型) | 4.5GB | 3.5x | 3.2x |
测试环境: NVIDIA A100, batch_size=8
text: 单个文本或文本列表tokenizer: HuggingFace tokenizernormalize: 是否 L2 归一化 (默认 True)pooling: 池化策略 - "mean" (默认), "first", "last"max_length: 最大序列长度 (默认 512)image: 图像路径、URL 或 PIL.Image 对象normalize: 是否 L2 归一化 (默认 True)pooling: 池化策略 - "mean" (默认), "first", "last", "none"video_path: 视频文件路径fps: 采样帧率 (默认 2.0)max_frames: 最大帧数 (默认 32)normalize: 是否 L2 归一化 (默认 True)pooling: 池化策略 - "mean" (默认), "first", "last".
├── vision_encoder.safetensors # 1.1GB - 视觉编码器权重
├── text_encoder.safetensors # 3.4GB - 文本编码器权重
├── embedding_config.json # 模型配置
├── qwen3vl_embedding.py # 主模型代码
├── text_encoder.py # 文本编码器实现
├── vision_process.py # 视觉预处理
└── weight_index.json # 权重索引
从 Qwen3-VL-8B-Instruct 中提取:
实验表明,前 6 层已经能够捕获丰富的语义信息,适合 embedding 任务。更深的层主要用于生成任务,对检索任务贡献有限。
视觉编码器通过 PatchMerger 将 1152 维投影到 4096 维,与文本编码器输出对齐,实现真正的跨模态检索。
如果使用本模型,请引用原始 Qwen3-VL 论文:
@article{qwen3vl,
title={Qwen3-VL: Towards Versatile Vision-Language Understanding},
author={Qwen Team},
year={2024}
}
本模型遵循 Apache 2.0 许可证,与原始 Qwen3-VL 模型保持一致。