Output short, contextual and empathetic reflections by processing journal entries
- Use state-of-the-art generative models to learn pattern of therapy conversations.
- Implemented in pytorch.
- Model used is based on Open AI GPT-2 model.
- The input to the model during training consists of a journaling entry and its corresponding response concatenated as a single sequence.
- A custom separator token is used to separate these two sub-sequences, as the GPT-2 model is adept at inferring customized structure.
- During evaluation, the fine-tuned model generates a response using the journaling entry as the seed sentence.
- The seed sentence and the response are concatenated with the custom separator to compute the perplexity for the generated response.
- data : Contains the data files used to train and evaluate the model.
- scripts : Contains scripts to preprocess data, and to train and evaluate the model.
- results : Contains the responses for journaling entries in the test set in jsonl format.
-
Download this repository.
-
Clone the
hugginface\transformers
repository from this link. -
Reset to commit
827d6d6ef0
using the commandgit reset --hard 827d6d6ef0
-
Install from source.
-
Preprocess counsel_chat.csv using prepare_data.py to generate train, val and test splits using:
python prepare_data.py
. -
Run the training script train.py using the command:
python train.py --output_dir=output --model_type=gpt2 --model_name_or_path=gpt2 --data_dir=../data --do_train --train_data_file=train.jsonl --do_eval --eval_data_file=val.jsonl --per_gpu_train_batch_size 8 --num_train_epochs 5 --overwrite_output_dir --num_return_sequences 5 --learning_rate 2e-5 -k 7 -p 0.7
-
Run the test script:
python test.py --output_dir=output_1 --model_type=gpt2 --model_name_or_path=output --data_dir=../data --eval_data_file=test.jsonl --overwrite_output_dir --num_return_sequences 5 -k 7 -p 0.7
-
The above scripts were tested on a node with 2 V100 32 GB GPUs.
-
The evaluation metric used is perplexity.
The parameters used to control the generation of text are:
Parameters | Description |
---|---|
length | Number of tokens to generate |
k | Filter top-k tokens before sampling |
p | Nucleus filtering top-p tokens before sampling |
num_return_sequences | Number of output sequences to generate |
sep_token | Custom separator token to separate journal and response |
Journal: I'm not suicidal and wouldn't take my own life, but sometimes, I've wished for an accident to occur and take it. I feel like I just shouldn't be here and wish I wouldn't have been born so I didn't have to go through life. For me, it's a chore, but I don't know if that's normal or a sign of something
Reflection: It sounds like you are in a very difficult place. It is not uncommon for people to have
Journal: I'm socially awkward. I've always want to be popular. I've had the opportunity to be popular, but every time I get i,t I'm too scared. All I have to do is talk the popular people. They're really nice to me, but I'm too scared of change. I really want to work up the courage to lose my fear
Reflection: Having the courage to speak your fears as they are sounds like a large step in the right direction.
Journal: My girlfriend just quit drinking and she became really depressed. She told me that she wants to move. What can I do to help her? I want her to stay
Reflection: Hi there. I am sorry to hear about your girlfriend's current situation
- The strategy to truncate examples with long text for the purpose of training. In this POC, the first two sentences of the response (reflection) are extracted for this purpose.
- The evaluation metrics to evaluate responses.
- How to generate truly contextual responses. Some examples included random names of people.
- How to avoid generating incorrect and highly insensitive responses.
- Avoid generating responses that are continuations of the journaling entry.
- Stop generating once a coherent sentence is generated.
Example Response from an experiment with no filtering before sampling (k=0 and p=0) describing points 3 and 4 :
Journal: My girlfriend just quit drinking and she became really depressed. She told me that she wants to move. What can I do to help her? I want her to stay
Reflection: Hi Ashley,It is with great sadness that we are unable to find a permanent solution to your problematic
- Create better contextualized and personalized responses, a knowledge base containing the personality traits and the afflictions affecting a person can be created.
- Maintain a history of prior utterances.
- Sample more data for training from sources like 7cups.com
- Constrain generated responses using techniques like Textual Entailment to prevent generating incorrect and irrelevant responses.
- Use IR techniques to narrow down candidate responses.
- Explore other evaluation metrics like F-1 measure.
- Scale to larger GPT-2 models, and consequently employ distributed training frameworks like horovod.