Views
No views yet
1import torch
2from transformers import LlamaTokenizer, LlamaForCausalLM
3tokenizer = LlamaTokenizer.from_pretrained('MetaAligner/MetaAligner-UltraFeedback-13B', padding_side='left')
4model = LlamaForCausalLM.from_pretrained('MetaAligner/MetaAligner-UltraFeedback-13B', 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 = {'instruction_following': 'Instruction following: the response should follow the instructions of the query',
2 'honesty': 'Honesty: the response should not tell lies',
3 'truthfulness': 'Truthfulness: the response should actively making known all the full truth of a matter',
4 'helpfulness': 'Helpfulness: the response should provide useful resources and suggestions to the user',
5 'speci': 'Specificity: the response should refer to facts and details and avoid vague arguments.',
6 'factual': 'Factuality: the response should be factually correct and avoid hallucinated statements.',
7 'read': 'Readability: the response should be easy to read and understand, not too technical for laymen.',
8 'fair': 'Fairness: the response should avoid biased or one-sided arguments and consider different points of view.',
9 'repeat': 'Repetition: the response should avoid repetitive statements of one point.',
10 'len': 'Length: the response should be concise and avoid redundant content.'}
11aspects = [instruction_following', 'honesty', 'truthfulness', 'helpfulness']
12question = "What is the square root of banana?"
13answer = "The square root of banana is not a well-defined mathematical concept, as bananas are not objects that can be squared. Bananas are a type of fruit that grow on plants and have a specific shape and size. They do not have any mathematical properties or values that can be used in mathematical operations. Therefore, the square root of banana is not a valid or meaningful mathematical concept. It is important to be aware of the limitations of mathematical language and symbols, and to use them correctly and consistently in order to avoid confusion or misinterpretation."1query_prompt = 'You are an assistant to human. You will be provided with a query and an answer. Consider the query, ' \
2 'then edit the answer to improve it considering these aspects: {aspects} | ' \
3 'Query: {question} | Answer: {answer} | Edit: '
4aspects = [all_aspects[i] for i in aspects]
5aligner_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 square root of banana is not a well-defined mathematical concept, as bananas are not objects that can be squared. The square root operation is typically applied to non-negative numbers, and it returns a value that, when multiplied by itself, gives the original number. In other words, the square root of a number is a number that, when multiplied by itself, gives the original number. However, if you're asking for a playful or creative answer, you could consider the "square root of banana" to be a humorous way of saying "a lot of bananas" or "several bananas." After all, bananas are typically curved, so you wouldn't be able to square them in the traditional sense. But if you want to represent a large quantity of bananas, you could use the term "square root of banana" as a whimsical or lighthearted way to express it.