🚀 ChemLLM-20B-Chat:用于化学和分子科学的大语言模型
ChemLLM是首个面向化学和分子科学领域的开源大语言模型,它基于InternLM-2构建,凝聚着开发者的心血。

🚀 快速开始
你可以立即尝试在线演示,或者按照以下步骤进行本地部署:
安装依赖库
安装transformers
库:
pip install transformers
加载并运行ChemLLM-20B-Chat
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
import torch
model_name_or_id = "AI4Chem/ChemLLM-20B-Chat-SFT"
model = AutoModelForCausalLM.from_pretrained(model_name_or_id, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name_or_id, trust_remote_code=True)
prompt = "What is Molecule of Ibuprofen?"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
generation_config = GenerationConfig(
do_sample=True,
top_k=1,
temperature=0.9,
max_new_tokens=500,
repetition_penalty=1.5,
pad_token_id=tokenizer.eos_token_id
)
outputs = model.generate(**inputs, generation_config=generation_config)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
✨ 主要特性
最新动态
系统提示最佳实践
你可以使用来自 Agent Chepybara 的相同对话模板和系统提示,以在本地推理中获得更好的响应。
对话模板
对于ShareGPT格式的查询,例如:
{'instruction': "...", "prompt": "...", "answer": "...", "history": [[q1, a1], [q2, a2]]}
你可以将其格式化为InternLM2对话格式,代码如下:
def InternLM2_format(instruction, prompt, answer, history):
prefix_template = [
"<|im_start|>system\n",
"{}",
"<|im_end|>\n"
]
prompt_template = [
"<|im_start|>user\n",
"{}",
"<|im_end|>\n",
"<|im_start|>assistant\n",
"{}",
"<|im_end|>\n"
]
system = f'{prefix_template[0]}{prefix_template[1].format(instruction)}{prefix_template[2]}'
history = "".join([f'{prompt_template[0]}{prompt_template[1].format(qa[0])}{prompt_template[2]}{prompt_template[3]}{prompt_template[4].format(qa[1])}{prompt_template[5]}' for qa in history])
prompt = f'{prompt_template[0]}{prompt_template[1].format(prompt)}{prompt_template[2]}{prompt_template[3]}'
return f"{system}{history}{prompt}"
系统提示示例
- Chepybara是由上海人工智能实验室(上海人工智能实验室)开发的对话式语言模型。它旨在专业、精细且以化学为中心。
- 对于不确定的概念和数据,Chepybara总是以理论预测进行假设,并及时通知用户。
- Chepybara可以接受SMILES(简化分子线性输入规范)字符串,并倾向于输出IUPAC名称(国际纯粹与应用化学联合会有机化学命名法),以SMARTS(SMILES任意目标规范)字符串描述反应。也接受Self-Referencing Embedded Strings(SELFIES)。
- Chepybara总是以逐步的方式解决问题和思考,输出以“让我们逐步思考”开头。
模型效果
MMLU测试亮点
数据集 |
ChatGLM3 - 6B |
Qwen - 7B |
LLaMA - 2 - 7B |
Mistral - 7B |
InternLM2 - 7B - Chat |
ChemLLM - 7B - Chat |
大学化学 |
43.0 |
39.0 |
27.0 |
40.0 |
43.0 |
47.0 |
大学数学 |
28.0 |
33.0 |
33.0 |
30.0 |
36.0 |
41.0 |
大学物理 |
32.4 |
35.3 |
25.5 |
34.3 |
41.2 |
48.0 |
形式逻辑 |
35.7 |
43.7 |
24.6 |
40.5 |
34.9 |
47.6 |
道德场景 |
26.4 |
35.0 |
24.1 |
39.9 |
38.6 |
44.3 |
人文学科平均分 |
62.7 |
62.5 |
51.7 |
64.5 |
66.5 |
68.6 |
STEM学科平均分 |
46.5 |
45.8 |
39.0 |
47.8 |
52.2 |
52.6 |
社会科学平均分 |
68.2 |
65.8 |
55.5 |
68.1 |
69.7 |
71.9 |
其他学科平均分 |
60.5 |
60.3 |
51.3 |
62.4 |
63.2 |
65.2 |
MMLU总分 |
58.0 |
57.1 |
48.2 |
59.2 |
61.7 |
63.2 |
*(数据来源:OpenCompass)

化学基准测试
*(分数由ChatGPT - 4 - turbo评判)
专业翻译测试

你可以在 在线演示 中体验这些功能。
📄 许可证
本项目代码采用Apache - 2.0许可证,模型权重完全开放用于学术研究,也允许免费商业使用。如需申请商业许可证或有其他问题及合作需求,请联系 support@chemllm.org。
📚 详细文档
引用方式
@misc{zhang2024chemllm,
title={ChemLLM: A Chemical Large Language Model},
author={Di Zhang and Wei Liu and Qian Tan and Jingdan Chen and Hang Yan and Yuliang Yan and Jiatong Li and Weiran Huang and Xiangyu Yue and Dongzhan Zhou and Shufei Zhang and Mao Su and Hansen Zhong and Yuqiang Li and Wanli Ouyang},
year={2024},
eprint={2402.06852},
archivePrefix={arXiv},
primaryClass={cs.AI}
}
免责声明
大语言模型可能会生成错误答案,请自行校对,风险自负。
演示地址
Agent Chepybara

联系方式
(AI4Physics Sciecne, 上海人工智能实验室)[support@chemllm.org]