Welcome to the world of ChemDFM-13B, an advanced open-sourced dialogue foundation model specifically designed for chemistry! Just as a seasoned chef uses various cooking techniques to create delicious dishes, ChemDFM employs powerful algorithms to revolutionize chemistry-related dialogues and tasks. In this article, we will guide you through the process of using ChemDFM-13B efficiently, troubleshooting common issues, and understanding its remarkable capabilities.
Getting Started with ChemDFM-13B
To make the most of ChemDFM-13B, you can choose between the online demo, which will be available soon, or run it locally. Here’s how to do both:
Using ChemDFM Locally
To load and run ChemDFM-13B locally, follow these simple steps:
python
import torch
from transformers import LlamaTokenizer, LlamaForCausalLM, GenerationConfig
model_name_or_id = "X-LANCE/ChemDFM-13B-v1.0"
tokenizer = LlamaTokenizer.from_pretrained(model_name_or_id)
model = LlamaForCausalLM.from_pretrained(model_name_or_id, torch_dtype=torch.float16, device_map="auto")
input_text = "Can you please give detailed descriptions of the molecule below?\nnCl.O=C1c2c(O)cccc2-c2nn(CCNCCO)c3ccc(NCCNCCO)c1c23"
input_text = f"[Round 0]\nHuman: {input_text}\nAssistant:"
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
generation_config = GenerationConfig(
do_sample=True,
top_k=20,
top_p=0.9,
temperature=0.9,
max_new_tokens=1024,
repetition_penalty=1.05,
eos_token_id=tokenizer.eos_token_id
)
outputs = model.generate(**inputs, generation_config=generation_config)
generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0][len(input_text):]
print(generated_text.strip())
This is akin to preparing a dish where you need to gather all ingredients (modules) first, then follow a step-by-step cooking method to end up with a lovely meal (your dialogue output). Just as proper seasoning (configuration settings) enhances a dish, so does fine-tuning of parameters like top_k and temperature enhance your model’s output.
Input Formatting and Preprocessing
To generate effective responses, it is necessary to preprocess your input using dialogue templates. This can be done with the following code:
python
def formatting_input(current_query, history):
input_text = ""
for idx, (query, answer) in enumerate(history):
input_text += f"[Round {idx}]\nHuman: {query}\nAssistant: {answer}\n"
input_text += f"[Round {len(history)}]\nHuman: {current_query}\nAssistant:"
return input_text
Think of this like arranging the ingredients in a specific order to prepare a recipe. By structuring dialogue histories properly, your conversations with ChemDFM feel smooth and organized.
Dealing with SMILES Notation
If your input involves SMILES notation, it’s crucial to ensure it is properly formatted using the RDKit library:
python
from rdkit import Chem
def canonicalize_smiles(smiles):
mol = Chem.MolFromSmiles(smiles)
if mol is None:
return None
return Chem.MolToSmiles(mol, isomericSmiles=True, kekuleSmiles=False)
Imagine this as refining ingredients to achieve consistency in flavor. Properly formatted SMILES helps ChemDFM understand your queries accurately and provide relevant responses.
Performance Metrics
ChemDFM-13B has shown impressive performance on multiple benchmarks in chemistry. You can find detailed performance metrics illustrated in our paper. This performance can be a testament to the meticulous work that has gone into optimizing it.
Troubleshooting Common Issues
- If you encounter errors in generating responses, double-check your input format. Error in formatting is like using the wrong ingredients in a recipe—it can lead to unpredictable results.
- Verify your environment configurations, such as ensuring that `torch` and `transformers` are correctly installed.
- If you get a blank output, try adjusting the sampling parameters like
top_kandtemperature.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
With the right setup and an understanding of ChemDFM-13B, you can delve into the world of chemistry dialogue with enhanced clarity and precision. As you explore, keep in mind the importance of formatting and parameter tuning to maximize output quality.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
