Reputation: 53
I am attempting to get hugging face to do some text rewriting for me. In a sentence, there will be a prefix, message, and suffix. The prefix and suffix must remain the same while the message is rewritten. I use an @ symbol to separate the prefix, message, and suffix. See example here:
How would I write a few-shot prompt for this? I have this code so far, but it is not working.
torch.manual_seed(0)
model = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model)
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype=torch.bfloat16,
device_map="auto",
)
prompt = """Sentence: It @ sucks that you got caught, @ but it's not my fault.
Rewritten: It @ is too bad you were exposed, @ but it's not my fault.
Sentence: Your bravery @ is wasted on @ those people.
Rewritten: Your bravery @ is useless for @ those people.
Sentence: This guy @ is meticulous in both planning @ and execution.
Rewritten: This guy @ is diligent when it comes to preparation @ and execution.
Rewrite the text between the 2 @ symbols in the following sentence.
Sentence: It @ sucks that you got caught, @ but it's not my fault.
Rewritten:
"""
sequences = pipe(
prompt,
max_new_tokens=10,
)
for seq in sequences:
print(f"Result: {seq['generated_text']}")
Upvotes: 1
Views: 423