Views
No views yet

1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("AdaptLLM/finance-chat")
4tokenizer = AutoTokenizer.from_pretrained("AdaptLLM/finance-chat", use_fast=False)
5
6# Put your input here:
7user_input = '''Use this fact to answer the question: Title of each class Trading Symbol(s) Name of each exchange on which registered
8Common Stock, Par Value $.01 Per Share MMM New York Stock Exchange
9MMM Chicago Stock Exchange, Inc.
101.500% Notes due 2026 MMM26 New York Stock Exchange
111.750% Notes due 2030 MMM30 New York Stock Exchange
121.500% Notes due 2031 MMM31 New York Stock Exchange
13
14Which debt securities are registered to trade on a national securities exchange under 3M's name as of Q2 of 2023?'''
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}