BioinspiredLLM: Conversational Large Language Model for the Mechanics of Biological and Bio-Inspired Materials
Reference: R. Luu and M.J. Buehler, Adv. Science, 2023, DOI: https://doi.org/10.1002/advs.202306724
Abstract: The study of biological materials and bio-inspired materials science is well established; however, surprisingly little knowledge is systematically translated to engineering solutions. To accelerate discovery and guide insights, an open-source autoregressive transformer large language model (LLM), BioinspiredLLM, is reported. The model is finetuned with a corpus of over a thousand peer-reviewed articles in the field of structural biological and bio-inspired materials and can be prompted to recall information, assist with research tasks, and function as an engine for creativity. The model has proven that it is able to accurately recall information about biological materials and is further strengthened with enhanced reasoning ability, as well as with Retrieval-Augmented Generation (RAG) to incorporate new data during generation that can also help to traceback sources, update the knowledge base, and connect knowledge domains. BioinspiredLLM also has shown to develop sound hypotheses regarding biological materials design and remarkably so for materials that have never been explicitly studied before. Lastly, the model shows impressive promise in collaborating with other generative artificial intelligence models in a workflow that can reshape the traditional materials design process. This collaborative generative artificial intelligence method can stimulate and enhance bio-inspired materials design workflows. Biological materials are at a critical intersection of multiple scientific fields and models like BioinspiredLLM help to connect knowledge domains.
model = PeftModel.from_pretrained('lamm-mit/BioinspiredLLM')
tokenizer = AutoTokenizer.from_pretrained(model_name)
Variants of the model are included, featuring various GGUF versions for use withm llama.cpp, for instance.
Generate:
device='cuda'
def generate_response (text_input="Biological materials offer amazing",
num_return_sequences=1,
temperature=1.,
max_new_tokens=127,
num_beams=1,
top_k = 50,
top_p =0.9,repetition_penalty=1.,eos_token_id=2,verbatim=False,
exponential_decay_length_penalty_fac=None,
):
inputs = tokenizer.encode(text_input, add_special_tokens =False, return_tensors ='pt')
if verbatim:
print ("Length of input, tokenized: ", inputs.shape, inputs)
with torch.no_grad():
outputs = model.generate(input_ids=inputs.to(device),
max_new_tokens=max_new_tokens,
temperature=temperature, #value used to modulate the next token probabilities.
num_beams=num_beams,
top_k = top_k,
top_p =top_p,
num_return_sequences = num_return_sequences, eos_token_id=eos_token_id,
do_sample =True,#skip_prompt=True,
repetition_penalty=repetition_penalty,
)
return tokenizer.batch_decode(outputs[:,inputs.shape[1]:].detach().cpu().numpy(), skip_special_tokens=True)
Generation example:
system_prompt = "You are BioinspiredLLM. You are knowledgeable in biological and bio-inspired materials and provide accurate and qualitative insights about biological materials found in Nature. You are a cautious assistant. You think step by step. You carefully follow instructions."
user_message = "What are hierarchical, biological materials?"
txt = f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{user_message}<|im_end|>\n<|im_start|>assistant"
# modulate temperature(0.1-1.0) to adjust 'creativity'
# modulate max_new_tokens to change length of generated response
output_text=generate_response ( text_input=txt,eos_token_id=2,
num_return_sequences=1,
repetition_penalty=1.1,
top_p=0.95,
top_k=50,
temperature=0.1,
max_new_tokens=512,
verbatim=False,
)
print(output_text)