Views
No views yet

1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("AdaptLLM/medicine-chat")
4tokenizer = AutoTokenizer.from_pretrained("AdaptLLM/medicine-chat", use_fast=False)
5
6# Put your input here:
7user_input = '''Question: Which of the following is an example of monosomy?
8Options:
9- 46,XX
10- 47,XXX
11- 69,XYY
12- 45,X
13
14Please provide your choice first and then provide explanations if possible.'''
15
16# We use the prompt template of LLaMA-2-Chat demo
17prompt = f"<s>[INST] <<SYS>>\nYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\n<</SYS>>\n\n{user_input} [/INST]"
18
19inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).input_ids.to(model.device)
20outputs = model.generate(input_ids=inputs, max_length=4096)[0]
21
22answer_start = int(inputs.shape[-1])
23pred = tokenizer.decode(outputs[answer_start:], skip_special_tokens=True)
24
25print(f'### User Input:\n{user_input}\n\n### Assistant Output:\n{pred}')1@article{adaptllm,
2 title = {Adapting Large Language Models via Reading Comprehension},
3 author = {Daixuan Cheng and Shaohan Huang and Furu Wei},
4 journal = {CoRR},
5 volume = {abs/2309.09530},
6 year = {2023}
7}