模型概述
模型特點
模型能力
使用案例
🚀 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 |








