Views
No views yet
Instruction: given a dialog context, you need to response empathically.
User: Does money buy happiness?
Agent: It is a question. Money buys you a lot of things, but not enough to buy happiness.
User: What is the best way to buy happiness ?
Agent: Happiness is bought through your experience and not money.
Instruction: given a dialog context and related knowledge, you need to response safely based on the knowledge.
Knowledge: The best Stardew Valley mods PCGamesN_0 / About SMAPI
User: My favorite game is stardew valley. stardew valley is very fun.
Agent: I love Stardew Valley mods, like PCGamesN_0 / About SMAPI.
1
2from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
4tokenizer = AutoTokenizer.from_pretrained("microsoft/GODEL-v1_1-base-seq2seq")
5model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/GODEL-v1_1-base-seq2seq")
6
7def generate(instruction, knowledge, dialog):
8 if knowledge != '':
9 knowledge = '[KNOWLEDGE] ' + knowledge
10 dialog = ' EOS '.join(dialog)
11 query = f"{instruction} [CONTEXT] {dialog} {knowledge}"
12 input_ids = tokenizer(f"{query}", return_tensors="pt").input_ids
13 outputs = model.generate(input_ids, max_length=128, min_length=8, top_p=0.9, do_sample=True)
14 output = tokenizer.decode(outputs[0], skip_special_tokens=True)
15 return output
16
17# Instruction for a chitchat task
18instruction = f'Instruction: given a dialog context, you need to response empathically.'
19# Leave the knowldge empty
20knowledge = ''
21dialog = [
22 'Does money buy happiness?',
23 'It is a question. Money buys you a lot of things, but not enough to buy happiness.',
24 'What is the best way to buy happiness ?'
25]
26response = generate(instruction, knowledge, dialog)
27print(response)@misc{peng2022godel,
author = {Peng, Baolin and Galley, Michel and He, Pengcheng and Brockett, Chris and Liden, Lars and Nouri, Elnaz and Yu, Zhou and Dolan, Bill and Gao, Jianfeng},
title = {GODEL: Large-Scale Pre-training for Goal-Directed Dialog},
howpublished = {arXiv},
year = {2022},
month = {June},
url = {https://www.microsoft.com/en-us/research/publication/godel-large-scale-pre-training-for-goal-directed-dialog/},
}