Views
No views yet
1import torch
2from transformers import LlamaTokenizer, LlamaForCausalLM
3tokenizer = LlamaTokenizer.from_pretrained('MetaAligner/MetaAligner-IMHI-7B', padding_side='left')
4model = LlamaForCausalLM.from_pretrained('MetaAligner/MetaAligner-IMHI-7B', device_map='auto', torch_dtype=torch.bfloat16)
5device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")device_map='auto' argument is used to automatically
use the GPU if it's available.1all_aspects = {'correct': 'Correctness: the explanations should make correct predictions',
2 'informative': 'Informative: the response should express clear logic and provide consistent evidence',
3 'professional': 'Professional: the response should provide evidence with high quality and reliability'}
4aspects = ['correct', 'informative', 'professional']
5question = "Consider this post: 'how the coronavirus could damage the US economy' Question: What is the stress cause of this post?"
6answer = "The stress cause of this post is the potential damage of the coronavirus to the US economy."1query_prompt = 'Edit the following Question-Answer pair to make it better considering these aspects "{aspects}" | ' \
2 'Question: {question} | Answer: {answer} | Edit: '
3aspects = [all_aspects[i] for i in aspects]
4aligner_queries = [query_prompt.format(aspects='; '.join(aspects), question=question, answer=str(answer))]1inputs = tokenizer(aligner_queries, return_tensors="pt", padding=True)
2input_ids = inputs.input_ids.to(device)
3generate_ids = model.generate(input_ids, max_new_tokens=1024)
4truc_ids = generate_ids[0][len(input_ids[0]):]
5response = tokenizer.decode(truc_ids, skip_special_tokens=True, spaces_between_special_tokens=False)
6print(response)The stress cause of this post is likely the uncertainty and potential negative impacts of the coronavirus on the US economy. The post is discussing the potential consequences of the pandemic, such as job loss, business closures, and economic downturn. These factors can cause significant stress and anxiety for individuals and organizations.