Self-Alignment with Instruction Backtranslation
Paper
• 2308.06259 • Published
• 43
This is a LoRA adapter trained on the OpenAssistant-Guanaco dataset for instruction backtranslation according to the "Self-Alignment with Instruction Backtranslation" paper.
This model is a fine-tuned version of Llama-2-7b using Low-Rank Adaptation (LoRA). It's designed to generate instructions from responses, effectively performing "backtranslation" of instructions.
To use this model, you need to combine it with the base Llama-2-7b model:
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-2-7b-hf",
torch_dtype=torch.float16,
device_map="auto"
)
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
tokenizer.pad_token = tokenizer.eos_token
# Load LoRA adapter and apply to base model
model = PeftModel.from_pretrained(base_model, "derain30/llama2-7b-backward-instruction")
# Example: Generate an instruction from a response
response = """Machine learning is a subfield of artificial intelligence that focuses on developing algorithms and models that enable computers to learn from data without being explicitly programmed. It identifies patterns in data and makes decisions with minimal human intervention."""
prompt = f"### Output:\n{response}\n\n### Instruction:"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(
inputs["input_ids"],
max_length=256,
temperature=0.7,
top_p=0.9,
num_return_sequences=1
)
generated_instruction = tokenizer.decode(outputs[0], skip_special_tokens=True).split("### Instruction:")[1].strip()
print("Generated instruction:", generated_instruction)
This model was trained using LoRA with the following configuration:
Base model
meta-llama/Llama-2-7b-hf