Idefics2 Raven Finetuned
专门用于解决瑞文推理矩阵问题的多模态模型,基于视觉-语言基础模型构建,验证集准确率达91%
下载量 235
发布时间 : 3/10/2024
模型简介
该模型基于SigLIP和Mistral-7B构建,通过特定数据集训练,专门用于解决瑞文推理矩阵问题,在验证集上表现出色。
模型特点
高准确率
在瑞文推理矩阵验证集上达到91%的准确率
多模态基础
基于视觉-语言基础模型的早期检查点构建
专门优化
针对瑞文推理矩阵问题进行了专门训练和优化
模型能力
解决瑞文推理矩阵问题
多模态图像理解
逻辑推理
使用案例
认知能力测试
瑞文推理测试
用于解决标准瑞文推理矩阵问题
91%的验证准确率
教育评估
认知能力评估
可用于教育场景中的认知能力测试
🚀 AI Raven模型
本模型旨在解决瑞文推理矩阵问题,基于即将推出的多模态基础模型的早期检查点进行训练。通过使用特定数据集训练,在验证集上达到了较高的准确率,为解决相关问题提供了有效方案。
🚀 快速开始
你可以先尝试 在线演示!
✨ 主要特性
- 该模型经过训练,专门用于解决瑞文推理矩阵问题。
- 基于即将推出的视觉 - 语言基础模型的早期检查点构建。
- 在验证集上,模型的准确率可达 91%。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
此代码片段展示了如何使用该模型进行批量推理。当我们将模型集成到 HF Transformers 中时,许多输入准备工作将被封装起来。
import torch
import requests
from io import BytesIO
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
from transformers.image_utils import to_numpy_array, PILImageResampling, ChannelDimension
from transformers.image_transforms import resize, to_channel_dimension_format
DEVICE = torch.device("cuda")
PROCESSOR = AutoProcessor.from_pretrained(
"HuggingFaceM4/tr_272_bis_opt_step_15000_merge",
token=API_TOKEN,
)
MODEL = AutoModelForCausalLM.from_pretrained(
"HuggingFaceM4/tr_272_bis_opt_step_15000_merge",
token=API_TOKEN,
trust_remote_code=True,
torch_dtype=torch.bfloat16,
).to(DEVICE)
image_seq_len = MODEL.config.perceiver_config.resampler_n_latents
BOS_TOKEN = PROCESSOR.tokenizer.bos_token
BAD_WORDS_IDS = PROCESSOR.tokenizer(["<image>", "<fake_token_around_image>"], add_special_tokens=False).input_ids
def convert_to_rgb(image):
# `image.convert("RGB")` would only work for .jpg images, as it creates a wrong background
# for transparent images. The call to `alpha_composite` handles this case
if image.mode == "RGB":
return image
image_rgba = image.convert("RGBA")
background = Image.new("RGBA", image_rgba.size, (255, 255, 255))
alpha_composite = Image.alpha_composite(background, image_rgba)
alpha_composite = alpha_composite.convert("RGB")
return alpha_composite
# The processor is the same as the Idefics processor except for the BILINEAR interpolation,
# so this is a hack in order to redefine ONLY the transform method
def custom_transform(x):
x = convert_to_rgb(x)
x = to_numpy_array(x)
height, width = x.shape[:2]
aspect_ratio = width / height
if width >= height and width > 980:
width = 980
height = int(width / aspect_ratio)
elif height > width and height > 980:
height = 980
width = int(height * aspect_ratio)
width = max(width, 378)
height = max(height, 378)
x = resize(x, (height, width), resample=PILImageResampling.BILINEAR)
x = PROCESSOR.image_processor.rescale(x, scale=1 / 255)
x = PROCESSOR.image_processor.normalize(
x,
mean=PROCESSOR.image_processor.image_mean,
std=PROCESSOR.image_processor.image_std
)
x = to_channel_dimension_format(x, ChannelDimension.FIRST)
x = torch.tensor(x)
return x
# Create text token inputs
image_seq = '<image>' * image_seq_len
inputs = PROCESSOR.tokenizer(
[
f"{BOS_TOKEN}User:<fake_token_around_image>{image_seq}<fake_token_around_image>Which figure should complete the logical sequence?<end_of_utterance>\nAssistant:",
f"{BOS_TOKEN}User:<fake_token_around_image>{image_seq}<fake_token_around_image>Which figure should complete the logical sequence?<end_of_utterance>\nAssistant:",
],
return_tensors="pt",
add_special_tokens=False,
padding=True,
)
# Create pixel inputs
raw_images = [
[your_raven_puzzle_as_a_pil_image1],
[your_raven_puzzle_as_a_pil_image2],
]
output_images = [
[PROCESSOR.image_processor(img, transform=custom_transform) for img in img_list]
for img_list in raw_images
]
total_batch_size = len(output_images)
max_num_images = max([len(img_l) for img_l in output_images])
max_height = max([i.size(2) for img_l in output_images for i in img_l])
max_width = max([i.size(3) for img_l in output_images for i in img_l])
padded_image_tensor = torch.zeros(total_batch_size, max_num_images, 3, max_height, max_width)
padded_pixel_attention_masks = torch.zeros(
total_batch_size, max_num_images, max_height, max_width, dtype=torch.bool
)
for batch_idx, img_l in enumerate(output_images):
for img_idx, img in enumerate(img_l):
im_height, im_width = img.size()[2:]
padded_image_tensor[batch_idx, img_idx, :, :im_height, :im_width] = img
padded_pixel_attention_masks[batch_idx, img_idx, :im_height, :im_width] = True
inputs["pixel_values"] = padded_image_tensor
inputs["pixel_attention_mask"] = padded_pixel_attention_masks
inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
generated_ids = MODEL.generate(**inputs, bad_words_ids=BAD_WORDS_IDS, max_new_tokens=10)
generated_texts = PROCESSOR.batch_decode(generated_ids, skip_special_tokens=True)
print(generated_texts)
高级用法
模型经过专门微调以解决瑞文谜题,若未进行适当调整,我们不能保证它在该用例之外能准确运行。
📚 详细文档
模型详情
属性 | 详情 |
---|---|
开发者 | Hugging Face |
模型类型 | 多模态模型 |
语言(NLP) | 英语 |
许可证 | 见 许可证部分 |
父模型 | SigLIP 和 mistralai/Mistral - 7B - v0.1 |
更多信息资源 | RAVEN 数据集:数据集卡片 |
📄 许可证
该模型基于两个预训练模型构建:SigLIP 和 mistralai/Mistral - 7B - v0.1,它们均遵循 Apache - 2.0 许可证分发。因此,用户应遵守这些模型的许可证规定。
这两个预训练模型通过我们训练的新初始化参数相互连接。这些参数并非基于构成复合模型的两个基础冻结模型。我们将训练得到的额外权重以 Apache - 2.0 许可证发布。
Codebert Base
CodeBERT是一个面向编程语言与自然语言的预训练模型,基于RoBERTa架构,支持代码搜索和代码生成文档等功能。
多模态融合
C
microsoft
1.6M
248
Llama 4 Scout 17B 16E Instruct
其他
Llama 4 Scout是Meta开发的多模态AI模型,采用混合专家架构,支持12种语言的文本和图像交互,具有17B激活参数和109B总参数。
多模态融合
Transformers 支持多种语言

L
meta-llama
817.62k
844
Unixcoder Base
Apache-2.0
UniXcoder是一个统一的多模态预训练模型,利用代码注释和抽象语法树等多模态数据预训练代码表示。
多模态融合
Transformers 英语

U
microsoft
347.45k
51
TITAN
TITAN是一个多模态全切片基础模型,通过视觉自监督学习和视觉-语言对齐进行预训练,用于病理学图像分析。
多模态融合
Safetensors 英语
T
MahmoodLab
213.39k
37
Qwen2.5 Omni 7B
其他
Qwen2.5-Omni 是一个端到端的多模态模型,能够感知文本、图像、音频和视频等多种模态,并以流式方式生成文本和自然语音响应。
多模态融合
Transformers 英语

Q
Qwen
206.20k
1,522
Minicpm O 2 6
MiniCPM-o 2.6是一款手机端运行的GPT-4o级多模态大模型,支持视觉、语音与直播流处理
多模态融合
Transformers 其他

M
openbmb
178.38k
1,117
Llama 4 Scout 17B 16E Instruct
其他
Llama 4 Scout是Meta推出的17B参数/16专家混合的多模态AI模型,支持12种语言和图像理解,具有行业领先性能。
多模态融合
Transformers 支持多种语言

L
chutesai
173.52k
2
Qwen2.5 Omni 3B
其他
Qwen2.5-Omni是一款端到端多模态模型,能够感知文本、图像、音频和视频等多种模态信息,并以流式方式同步生成文本和自然语音响应。
多模态融合
Transformers 英语

Q
Qwen
48.07k
219
One Align
MIT
Q-Align是一个多任务视觉评估模型,专注于图像质量评估(IQA)、美学评估(IAA)和视频质量评估(VQA),在ICML2024上发表。
多模态融合
Transformers

O
q-future
39.48k
25
Biomedvlp BioViL T
MIT
BioViL-T是一个专注于分析胸部X光片和放射学报告的视觉语言模型,通过时序多模态预训练提升性能。
多模态融合
Transformers 英语

B
microsoft
26.39k
35
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98