模型简介
模型特点
模型能力
使用案例
🚀 ChemVLM-8B:用于化学领域的多模态大语言模型
这是ChemVLM的80亿参数版本,它是一款专为化学应用设计的多模态大语言模型,能够有效处理化学领域的文本和视觉信息,为化学研究和应用提供强大支持。
🚀 快速开始
安装依赖库
使用以下命令安装所需的库:
pip install transformers>=4.37.0 sentencepiece einops timm accelerate>=0.26.0
同时,请确保已经安装了 torch
和 torchvision
。
代码示例
from transformers import AutoTokenizer, AutoModelforCasualLM
import torch
import torchvision.transforms as T
import transformers
from torchvision.transforms.functional import InterpolationMode
IMAGENET_MEAN = (0.485, 0.456, 0.406)
IMAGENET_STD = (0.229, 0.224, 0.225)
IMAGENET_MEAN = (0.485, 0.456, 0.406)
IMAGENET_STD = (0.229, 0.224, 0.225)
def build_transform(input_size):
MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
transform = T.Compose([
T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
T.ToTensor(),
T.Normalize(mean=MEAN, std=STD)
])
return transform
def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
best_ratio_diff = float('inf')
best_ratio = (1, 1)
area = width * height
for ratio in target_ratios:
target_aspect_ratio = ratio[0] / ratio[1]
ratio_diff = abs(aspect_ratio - target_aspect_ratio)
if ratio_diff < best_ratio_diff:
best_ratio_diff = ratio_diff
best_ratio = ratio
elif ratio_diff == best_ratio_diff:
if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
best_ratio = ratio
return best_ratio
def dynamic_preprocess(image, min_num=1, max_num=6, image_size=448, use_thumbnail=False):
orig_width, orig_height = image.size
aspect_ratio = orig_width / orig_height
# calculate the existing image aspect ratio
target_ratios = set(
(i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
i * j <= max_num and i * j >= min_num)
target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
# find the closest aspect ratio to the target
target_aspect_ratio = find_closest_aspect_ratio(
aspect_ratio, target_ratios, orig_width, orig_height, image_size)
# calculate the target width and height
target_width = image_size * target_aspect_ratio[0]
target_height = image_size * target_aspect_ratio[1]
blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
# resize the image
resized_img = image.resize((target_width, target_height))
processed_images = []
for i in range(blocks):
box = (
(i % (target_width // image_size)) * image_size,
(i // (target_width // image_size)) * image_size,
((i % (target_width // image_size)) + 1) * image_size,
((i // (target_width // image_size)) + 1) * image_size
)
# split the image
split_img = resized_img.crop(box)
processed_images.append(split_img)
assert len(processed_images) == blocks
if use_thumbnail and len(processed_images) != 1:
thumbnail_img = image.resize((image_size, image_size))
processed_images.append(thumbnail_img)
return processed_images
def load_image(image_file, input_size=448, max_num=6):
image = Image.open(image_file).convert('RGB')
transform = build_transform(input_size=input_size)
images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
pixel_values = [transform(image) for image in images]
pixel_values = torch.stack(pixel_values)
return pixel_values
tokenizer = AutoTokenizer.from_pretrained('AI4Chem/ChemVLM-8B', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"AI4Chem/ChemVLM-8B",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).cuda().eval()
query = "Please describe the molecule in the image."
image_path = "your image path"
pixel_values = load_image(image_path, max_num=6).to(torch.bfloat16).cuda()
gen_kwargs = {"max_length": 1000, "do_sample": True, "temperature": 0.7, "top_p": 0.9}
response = model.chat(tokenizer, pixel_values, query, gen_kwargs)
print(response)
✨ 主要特性
- 多模态信息处理:能够同时处理文本和视觉信息,包括分子结构、反应和化学试题等。
- 双语训练:在精心策划的双语多模态数据集上进行训练,增强了对不同语言化学信息的理解能力。
- 全面评估:针对化学光学字符识别(OCR)、多模态化学推理(MMCR)和多模态分子理解等任务开发了三个数据集进行全面评估。
📚 详细文档
论文
摘要
大语言模型(LLMs)已经取得了显著成功,并已应用于包括化学在内的各个科学领域。然而,许多化学任务需要处理视觉信息,而现有的化学大语言模型无法成功处理这些信息。这使得在化学领域对能够整合多模态信息的模型的需求日益增长。在本文中,我们介绍了 ChemVLM,这是一个专门为化学应用设计的开源化学多模态大语言模型。ChemVLM在精心策划的双语多模态数据集上进行训练,增强了其理解文本和视觉化学信息的能力,包括分子结构、反应和化学试题。我们开发了三个数据集,分别针对化学光学字符识别(OCR)、多模态化学推理(MMCR)和多模态分子理解任务进行全面评估。我们在各种任务上对ChemVLM与一系列开源和专有多模态大语言模型进行了基准测试。实验结果表明,ChemVLM在所有评估任务中都取得了有竞争力的性能。我们的模型可以在https://huggingface.co/AI4Chem/ChemVLM-26B找到。
模型描述
ChemVLM的架构基于InternVLM,并结合了视觉和语言处理组件。该模型在包含化学信息的双语多模态数据集上进行训练,这些信息包括分子结构、反应和化学试题。有关架构的更多详细信息可以在Github README中找到。
引用
@inproceedings{li2025chemvlm,
title={Chemvlm: Exploring the power of multimodal large language models in chemistry area},
author={Li, Junxian and Zhang, Di and Wang, Xunzhi and Hao, Zeying and Lei, Jingdi and Tan, Qian and Zhou, Cai and Liu, Wei and Yang, Yaotian and Xiong, Xinrui and others},
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
volume={39},
number={1},
pages={415--423},
year={2025}
}
代码库和数据集
代码库和数据集可以在https://github.com/AI4Chem/ChemVlm找到。
🔧 技术细节
模型架构
ChemVLM的架构基于InternVLM,结合了视觉和语言处理组件,能够有效处理化学领域的多模态信息。
训练数据
模型在包含化学信息的双语多模态数据集上进行训练,这些信息包括分子结构、反应和化学试题,增强了模型对化学信息的理解能力。
评估数据集
针对化学光学字符识别(OCR)、多模态化学推理(MMCR)和多模态分子理解等任务开发了三个数据集进行全面评估。
📄 许可证
本项目采用Apache 2.0许可证。
📊 模型性能
属性 | 详情 |
---|---|
模型类型 | 多模态大语言模型 |
训练数据 | 包含分子结构、反应和化学试题的双语多模态数据集 |
80亿参数模型在几个任务上的表现
数据集 | MMChemOCR | CMMU | MMCR-bench | 反应类型 |
---|---|---|---|---|
指标 | 谷本相似度(tani@1.0) | 得分(%,GPT - 4o辅助判断) | 得分(%,GPT - 4o辅助判断) | 准确率(%) |
ChemVLM - 8b得分 | 81.75/57.69 | 52.7(SOTA) | 33.6 | 16.79 |








