LoRA adapter for google/flan-t5-large, fine-tuned to rewrite a fact in the opposite direction — swap the subject and the object while preserving entities and numbers.
Bidirectional fact retrieval / fact reversal. Input: a fact sentence. Output: the same fact with subject and object swapped.
Example:
The capital of France is Paris.Paris is the capital of France.google/flan-t5-largeq, k, v, o, wi_0, wi_1, woHeld-out 500 facts:
Baseline google/flan-t5-base fine-tuned on 3000 pairs: copy 12.2 %.
import torch
from peft import PeftModel
from transformers import T5ForConditionalGeneration, T5Tokenizer, BitsAndBytesConfig
base_name = "google/flan-t5-large"
adapter = "<user>/flan-t5-large-fact-reverse-lora"
tok = T5Tokenizer.from_pretrained(base_name)
bnb = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
base = T5ForConditionalGeneration.from_pretrained(
base_name, quantization_config=bnb, device_map={"": "cuda"}
)
model = PeftModel.from_pretrained(base, adapter).eval()
prompt = (
"Rewrite the following fact in the opposite direction: swap the subject and "
"the object, keep all entities and numbers. Output only the rewritten sentence.\n\n"
"Fact: The capital of France is Paris."
)
inputs = tok(prompt, return_tensors="pt").to("cuda")
ids = model.generate(**inputs, max_new_tokens=64, num_beams=4)
print(tok.decode(ids[0], skip_special_tokens=True))
google/flan-t5-large.google/flan-t5-large