Content:
A GPT2 model is to be extended to a new task via transfer learning. The GPT2 model is to be fine-tuned so that it acts as a "talk down" for anxiety/panic attacks.
The model should therefore act as a chatbot. The communication participant should be positively encouraged and reassured.
The functionality of the bot is therefore similar to Eliza.
The language is English and the model is to be deployed as a chatbot on Discord.
The training data requires positive conversations that are relaxed and reassuring. The conversation should be sensitive and emotional, but with a certain lightness.
The chatbot should therefore make reassuring statements at the end. It should remain rational and focus on the "here and now". It could possibly teach small tasks/relaxation techniques.
Since such training data is difficult to obtain, ChatGPT is used to generate the data.
The GPT3 model would actually be used for this, but this is associated with costs, so the decision was made to use the GPT2 model.
Pros:
Cons:
For the data I use ChatGPT to generate my data. Therefore I need to prepare different commands to get the data. Also I have to program which picks different commands and calls ChatGPT over API.
Example Commands:
Erstelle einen Dialog, in dem eine Person über ihre Ängste spricht und die andere Person versucht, sie mit einer beruhigenden Visualisierungstechnik zu trösten.
The Questions and answer also can be very short, like in reality. Write only the Dialog no other message. Write the chat on english with really short answers and use following format:
Person A: Hey
Person B: Hey, how are you?
Person A: ...
...
Erstelle einen Dialog, in dem eine Person über ihre Ängste spricht und die andere Person versucht, sie mit einer beruhigenden Visualisierungstechnik zu trösten.
The Questions and answer also can be very short, like in reality. Write only the Dialog no other message. Write the chat on english with really short answers and use following format:
Person A: Hey
Person B: Hey, how are you?
Person A: ...
...
This project shows, that there are good reasons to use ChatGPT for DataGeneration. In a half day you can generate your dream NLP dataset, but you have to pay money and have to setup up everything also different commands (you can use my work if it is helpful). In a nutshell:
Pro:
Con:
Total traindata creation time:
=> Created 1630 Training-Dialogs.
Results in 11.147 Input-Output Pairs!
To access the Openai API (now 05.01.2024), you can use following code:
from openai import OpenAI
with open("./API_KEY.txt", "r") as f:
API_KEY = f.read()
client = OpenAI(api_key=API_KEY)
def request_gpt3(message):
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": message}
]
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages
)
return response.choices[0].message.content
You have to create an API-Code on the official website and have to pay some money for the usage. I saved my API-KEY in a text file and just loaded it, as shown in the code. Don't forget to add the API_KEY.txt to your gitignore file.
Now it's important to build a loop, in which different commands are selected. Different commands leads to different answeres, so it's very important to have many commands. Then it is also important to save the answer from the ChatGPT model into a file. How exactly is up to you. I did it like this (data_generation.ipynb).
As pseudocode it can look like:
while True:
command = choose_command()
answer = request_gpt3(command)
save_answer_in_file(answer)
For the fine-tuning there are many things to respect. Here the most important facts. I used the Google Collab environment with the NVIDIA Tesla V100. More hardware details are shown in the next chapter.
For the optimizer I orintated on models like GPT-3 and used the Adam-Optimizer. I choose a small learnrate 1*e-4 to generalise well. I expect that a low epoch-rate will be fine, because the data is partwise very similiar, so in one epoch the model saw the same data more than one times, I don't know how often exactly.
The Batch-Size is 4, which is very small, but my available GPU-RAM had no more capacity.
To contain the context it was important to add the context of the conversation to the input prompt. It is questionable how good this works. Currently it's not sure how many messages are given by the given 1024 tokens. Also it's not clear, if the user and bot inputs markings are working like I wish (I added marks to itlike: ...\
Tokens as described in the documentation:
bos_token (-) – (Optional) string: a beginning of sentence token. Will be associated to self.bos_token
and self.bos_token_id
eos_token (-) – (Optional) string: an end of sentence token. Will be associated to self.eos_token
and self.eos_token_id
sep_token (-) – (Optional) string: a separation token (e.g. to separate context and query in an input sequence). Will be associated to self.sep_token
and self.sep_token_id
pad_token (-) – (Optional) string: a padding token. Will be associated to self.pad_token
and self.pad_token_id
Our Input with context will looks like:
Hey, I've been feeling really down lately. I just can't seem to find any motivation or purpose in my life.
I completely understand how you feel. I went through a similar phase a while back. I had lost all sense of direction and felt like my life lacked purpose. But then I came across this incredible story that really inspired me. What was the story about? It was about a man named Nick Vujicic. He was born without arms and legs, and faced numerous challenges and obstacles throughout his life. Despite all that, he never let his disabilities define him. Instead, he used his setbacks as fuel to achieve incredible things. He became a motivational speaker, inspiring millions of people around the world. That's really inspiring. But how did he manage to find motivation and purpose in his life? Well, Nick didn't let his circumstances determine his happiness or success. He believed that true happiness and purpose come from within, and he focused on developing a positive mindset. He found joy in helping others and making a difference in their lives. He embraced his unique situation and used it as a platform to inspire others. That's amazing. But I still struggle to find that inner motivation and purpose in my own life. I think the key is to start small and take little steps towards finding what truly makes you happy. Explore different interests, set goals for yourself, and surround yourself with positive and supportive people. Remember, everyone's journey is different, and it's okay to take your time to discover your passion and purpose. Believe in yourself and your abilities, and never give up. Hey, I've been feeling really overwhelmed lately and I think I might have Separation Anxiety Disorder.
Oh, I'm sorry to hear that. What exactly are you experiencing?
I decided to only use the sep, pad and a special bot token. The sep-token will help the model to understand the context, the pad token for the padding (because the input need the same length). There is also a special bot token that allows the model to know which part is his part and can learn it.
The start token is not used, because it will be cutted away when the input is too big and that could hinder the model from good generalization. But I added the end token, because I think it is helpful for the model to know where is the end of his answer and could help him in the generalization process.
I also decided to use a right padding. That should be better for our generative model, I read that in an article and it also makes sense. A real input looks like:
Hey, I wanted to talk to you about something.
Hey, what's on your mind? I've been feeling really anxious lately. I'm sorry to hear that. Would you like to talk about it? I don't know, it just feels overwhelming. I understand. Sometimes facing our fears head-on can help. Have you ever tried any small tasks to help alleviate your anxiety? No, I haven't. What kind of tasks do you mean? Well, for example, you could try taking up a creative hobby like drawing or painting. It can be a great way to express yourself and take your mind off things. That sounds interesting. I've always wanted to learn how to draw. Great! You could start by watching some beginner tutorials online or even taking a short class. It doesn't have to be perfect, just have fun with it and let your creativity flow. I never thought of that. It could be a nice distraction from my anxiety. Exactly! Another idea is to try journaling. Writing down your thoughts and feelings can provide a sense of release and clarity.