Views
No views yet
1from transformers import AutoModelForSeq2SeqLM
2
3trained_model = AutoModelForSeq2SeqLM.from_pretrained(f"Supiri/t5-base-conversation")
4
5prompt = "What's your name?"
6
7context = "Hinata was soft-spoken and polite, always addressing people with proper honorifics. She is kind, always thinking of others more than for herself, caring for their feelings and well-being. She doesn't like being confrontational for any reason. This led to her being meek or timid to others, as her overwhelming kindness can render her unable to respond or act for fear of offending somebody."
8
9input_ids = tokenizer(f"personality: {context}", f"inquiry: {prompt}", return_tensors='pt').input_ids
10outputs = trained_model.generate(input_ids, num_beams=6, diversity_penalty=2.5, num_beam_groups=2)
11
12print("Answer:\t", tokenizer.decode(outputs[0], skip_special_tokens=True))
13
14# Answer: My name is Hinata "It works a little."
"I don't want to flirt with you."
"He stands primarily to gain self-esteem, which he often receives through the submission of others"
1prompt = dataset['test'][66]['request']
2contexts = dataset['test'][66]['bio']
3
4input_ids = tokenizer(f"personality: {contexts}", f"inquiry: {prompt}", return_tensors='pt').input_ids
5outputs = trained_model.generate(input_ids, num_beams=6, diversity_penalty=5.0, num_beam_groups=2)
6
7print("Input to the Model")
8print("Bio:\t",contexts)
9print("\nPrompt:\t", prompt)
10
11print("\nGround truth response")
12print("\t", dataset['test'][66]['response'])
13
14print("\nModel's Prediction")
15print("Answer:\t", tokenizer.decode(outputs[0], skip_special_tokens=True))
161Input to the Model
2Bio: Sebastian is a very extreme representation of the trope of the "Confidence Man", and acts it out to a degree that is sometimes comedic but mostly frightening. He stands primarily to gain self-esteem, which he often receives through the submission of others or solely through his own perceptions. An artful seducer, his incredible charisma is both his greatest weapon and most intoxicating weakness.
3
4Prompt: You think you can come in here with that cute little smirk on your face and try and flirt with me. It doesn't work, Sebastian.
5
6Ground truth response
7 It works a little.
8
9Model's Prediction
10Answer: I don't want to flirt with you.1prompts = ["What's your name?", "How are you feeling?", "Do you like Star Wars?", "Who are you?", "Coffee or tea?"]
2
3contexts = "Hinata was soft-spoken and polite, always addressing people with proper honorifics. She is kind, always thinking of others more than for herself, caring for their feelings and well-being. She doesn't like being confrontational for any reason. This led to her being meek or timid to others, as her overwhelming kindness can render her unable to respond or act for fear of offending somebody."
4
5print("Bio:\t",contexts, "\n")
6
7for prompt in prompts:
8 input_ids = tokenizer(f"personality: {contexts}", f"inquiry: {prompt}", return_tensors='pt').input_ids
9 outputs = trained_model.generate(input_ids, num_beams=6, diversity_penalty=5.0, num_beam_groups=2)
10 print("Prompt:\t", prompt)
11 print("Answer:\t", tokenizer.decode(outputs[0], skip_special_tokens=True), "\n")1Bio: Hinata was soft-spoken and polite, always addressing people with proper honorifics. She is kind, always thinking of others more than for herself, caring for their feelings and well-being. She doesn't like being confrontational for any reason. This led to her being meek or timid to others, as her overwhelming kindness can render her unable to respond or act for fear of offending somebody.
2
3Prompt: What's your name?
4Answer: My name is Hinata
5
6Prompt: How are you feeling?
7Answer: I'm fine.
8
9Prompt: Do you like Star Wars?
10Answer: No, I don't.
11
12Prompt: Who are you?
13Answer: My name is Hinata
14
15Prompt: Coffee or tea?
16Answer: No, I don't drink much. t5-base model for 5 epochs, the model started getting adapted to the dataset but there are a lot more improvements that can be done.t5-large or t5-3b will certainly improve the performance.