Skip to content

Instantly share code, notes, and snippets.

@gorkemgoknar
Last active February 3, 2023 17:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorkemgoknar/ae29bf9d14fa814e6a64d0e57a4a4ed7 to your computer and use it in GitHub Desktop.
Save gorkemgoknar/ae29bf9d14fa814e6a64d0e57a4a4ed7 to your computer and use it in GitHub Desktop.
{
"train":[
{
"personality":[
"My name is Ethan. <<REAL PERSONALITY>> This list defines the character, you can add char related text for chat here to drive chat"
],
"utterances":[
{
"candidates":[
"A line character is not supposed to say in this chat.",
"Another line character is not supposed to say in this chat.",
">>Actual Answer, best to make sure token count <1024 << Which means, Mr. McCloy, we have to get our hands on four hundred and eighty thousand options."
],
"history":[
"..it seems we have a problem, Dmitri."
],
"personality":[
">>This personality item is to keep track of first lines by character, not used in training<<",
"You'll soon be with old friends.",
"My name is Ethan."
]
},
{
"candidates":[
"his left jacket pocket.",
"From her point of view or mine?",
"No."
],
"history":[
"..it seems we have a problem, Dmitri.",
"You keep calling me Dmitri. You really shouldn't.",
"Actual line request to chatbot> You're not Dmitri?"
],
"personality":[
"You carry them together? Safely? >>This personality item is to keep track of first lines by character, not used in training<<",
"My name is Ethan."
]
}
]
}
],
"valid":[
{
"personality":[
"My name is Ethan."
],
"utterances":[
{
"candidates":[
"Some line that character should not say",
"Some other line character should not say",
"Last member is the line character should say."
],
"history":[
"Hello there Dimitry (Line where other char asks to Chatbot)"
],
"personality":[
"Do you know me? >>This personality item is to keep track of first lines by character, not used in training, can ignore<<",
"My name is Ethan.>>This personality item is to keep track of first lines by character, not used in training, can ignore<<"
]
}
]
}
]
}
@JordanMicahBennett
Copy link

JordanMicahBennett commented Mar 29, 2021

Great experiment!

Where is this file invoked?

I attempted to invoke this file via --dataset param calling on interact.py from hugging face, but when prompted, "What is your name?" model returns "Tom", when instead, I would expect to at least see Ethan if I am not mistaken?

@gorkemgoknar
Copy link
Author

gorkemgoknar commented Mar 30, 2021

This is training sample, you are supposed to train the chatpotwith these type of chat pairs, given enough utterances for a personality, you may be able to make a conversation out of it.
If you want personality stay in same type as you trained you should test with smaller temperature value (but will not be able to answer generally if not trained on that specific chat input)

Training dataset should be like this
train: [
[ ["personality": personality_1 , "utterances": utterance_list_for_personality_1],
["personality": personality_2 , "utterances": utterance_list_for_personality_2],
...]

@gorkemgoknar
Copy link
Author

@JordanMicahBennett

It is possible to continue train on previous huggingface chatbot model (GPT2DoubleHead) with a caveat.
The last model you train will have the personas you provided. So say previous model had "personality": "I like swimming" , and you have your personality same (and more) you can keep the previous one (but you need some utterances of course else it will fail to train well).

So if you like to "keep" old personalities, you need previous personality dataset plus add your own personalities in it.
If you want to just make your own personality , but using a pretrained personality model, you can..

Here is an example
!python ./train.py --model /content/chatbot/transfer-learning-conv-ai/runs/previous_trained model --dataset_path '/content/chatbot/personafile/personafile.json' --train_batch_size 1 --valid_batch_size 1 --n_epochs 10

--model parameter uses following in back end so it is actually previous model (or your previous training) itself
tokenizer_class = GPT2Tokenizer # cant use Autotokenizer because checkpoint could be a Path
tokenizer = GPT2Tokenizer.from_pretrained(args.model_checkpoint)
model_class = GPT2DoubleHeadsModel
model = model_class.from_pretrained(args.model_checkpoint)

@JordanMicahBennett
Copy link

This is training sample, you are supposed to train the chatpotwith these type of chat pairs, given enough utterances for a personality, you may be able to make a conversation out of it.
If you want personality stay in same type as you trained you should test with smaller temperature value (but will not be able to answer generally if not trained on that specific chat input)

Training dataset should be like this
train: [
[ ["personality": personality_1 , "utterances": utterance_list_for_personality_1],
["personality": personality_2 , "utterances": utterance_list_for_personality_2],
...]

Thanks for this guideline.

@JordanMicahBennett
Copy link

@JordanMicahBennett

It is possible to continue train on previous huggingface chatbot model (GPT2DoubleHead) with a caveat.
The last model you train will have the personas you provided. So say previous model had "personality": "I like swimming" , and you have your personality same (and more) you can keep the previous one (but you need some utterances of course else it will fail to train well).

So if you like to "keep" old personalities, you need previous personality dataset plus add your own personalities in it.
If you want to just make your own personality , but using a pretrained personality model, you can..

Here is an example
!python ./train.py --model /content/chatbot/transfer-learning-conv-ai/runs/previous_trained model --dataset_path '/content/chatbot/personafile/personafile.json' --train_batch_size 1 --valid_batch_size 1 --n_epochs 10

--model parameter uses following in back end so it is actually previous model (or your previous training) itself
tokenizer_class = GPT2Tokenizer # cant use Autotokenizer because checkpoint could be a Path
tokenizer = GPT2Tokenizer.from_pretrained(args.model_checkpoint)
model_class = GPT2DoubleHeadsModel
model = model_class.from_pretrained(args.model_checkpoint)

Thanks. My goal was to aim to possibly do some type of forward pass of my personality file, and therein, put the pretrained model in a state without the need for backprop aka training.

Albeit, thanks a lot for the training guide, and the file you conveniently provided.

I will perform the training for the 10 epochs you supplied.

After this, I will write a function to non-randomly select personality based on say the last bot name in the training set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment