Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Reframing task #5039

Merged
merged 4 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions parlai/tasks/reframe_thoughts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
54 changes: 54 additions & 0 deletions parlai/tasks/reframe_thoughts/agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import os
import copy
import json
from parlai.core.teachers import DialogTeacher
from .build import build


def _path(opt):
# Build the data if it doesn't exist.
build(opt)
dt = opt['datatype'].split(':')[0]
return os.path.join(
opt['datapath'], 'reframe_thoughts', 'reframe_thoughts_dataset', dt + '.txt'
)


class ReframeThoughtsTeacher(DialogTeacher):
def __init__(self, opt, shared=None):
opt = copy.deepcopy(opt)
opt['task'] = "reframe_thoughts"
opt['datafile'] = _path(opt)
super().__init__(opt, shared)

def setup_data(self, datafile):
all_data = [json.loads(line.strip()) for line in open(datafile)]
for data in all_data:
persona = data["persona"]
pattern = data["pattern"] + " (" + data["pattern_def"] + ")"
thought = data["thought"]
persona_token = ""
pattern_token = "[PAT]"
thought_token = "[THT]"
for reframe in data["reframes"]:
input = " ".join(
[
persona_token,
persona,
pattern_token,
pattern,
thought_token,
thought,
]
).strip()
yield (input, reframe['reframe']), True


class DefaultTeacher(ReframeThoughtsTeacher):
pass
40 changes: 40 additions & 0 deletions parlai/tasks/reframe_thoughts/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# Download and build the data if it does not exist.

from parlai.core.build_data import DownloadableFile
import parlai.core.build_data as build_data
import os

REFRAME_VERSION = "v0.1"

RESOURCES = [
DownloadableFile(
f'http://parl.ai/downloads/reframe_thoughts/reframe_thoughts_{REFRAME_VERSION}.tar.gz',
f'reframe_thoughts_{REFRAME_VERSION}.tar.gz',
'bfbfc61c26341dd64b59945c3d290caba67fa2db435fb01ac309cef295222c99',
)
]


def build(opt):
dpath = os.path.join(opt['datapath'], 'reframe_thoughts')
version = REFRAME_VERSION

if not build_data.built(dpath, version_string=version):
print('[building data: ' + dpath + ']')
if build_data.built(dpath):
# An older version exists, so remove these outdated files.
build_data.remove_dir(dpath)
build_data.make_dir(dpath)

# Download the data.
for downloadable_file in RESOURCES:
downloadable_file.download_file(dpath)

# Mark the data as built.
build_data.mark_done(dpath, version_string=version)
11 changes: 11 additions & 0 deletions parlai/tasks/reframe_thoughts/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from parlai.utils.testing import AutoTeacherTest # noqa: F401


class TestDefaultTeacher(AutoTeacherTest):
task = 'reframe_thoughts'
70 changes: 70 additions & 0 deletions parlai/tasks/reframe_thoughts/test/reframe_thoughts_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
acts:
- - episode_done: true
eval_labels:
- My neighbor calls me by my first name instead of my nickname. He may think he
doesn't know me well enough to use it. I will let him know that I don't mind
if he calls me Bubblegum.
id: reframe_thoughts
text: 'i''ve found the cure for the common cold . my nickname is bubblegum . i
am plotting on taking over the world . my brother and i''ve bright red hair
. [PAT] Jumping to conclusions: mind reading (Inferring a person''s possible
or probable (usually negative) thoughts from their behavior and nonverbal communication;
taking precautions against the worst suspected case without asking the person.

) [THT] My neighbor calls me by my first name instead of my nickname. He probably
thinks bubblegum is a tacky nickname.'
- - episode_done: true
eval_labels:
- My neighbor calls me by my silly first name, but since it's my name he is obliged
to call me by it.
id: reframe_thoughts
text: 'i''ve found the cure for the common cold . my nickname is bubblegum . i
am plotting on taking over the world . my brother and i''ve bright red hair
. [PAT] Jumping to conclusions: mind reading (Inferring a person''s possible
or probable (usually negative) thoughts from their behavior and nonverbal communication;
taking precautions against the worst suspected case without asking the person.

) [THT] My neighbor calls me by my first name instead of my nickname. He probably
thinks bubblegum is a tacky nickname.'
- - episode_done: true
eval_labels:
- My neighbor calls me by my first name instead of my nickname. He is such a formal
gentleman.
id: reframe_thoughts
text: 'i''ve found the cure for the common cold . my nickname is bubblegum . i
am plotting on taking over the world . my brother and i''ve bright red hair
. [PAT] Jumping to conclusions: mind reading (Inferring a person''s possible
or probable (usually negative) thoughts from their behavior and nonverbal communication;
taking precautions against the worst suspected case without asking the person.

) [THT] My neighbor calls me by my first name instead of my nickname. He probably
thinks bubblegum is a tacky nickname.'
- - episode_done: true
eval_labels:
- My wife recently got laid off from her job and since I'm creating my own start
up company she can come to work with me now instead of having to worry about
looking for another one.
id: reframe_thoughts
text: 'i design video games for a living . my wife recently got laid off from
her human resources job . my son plays on the local football team . i have been
on the design team for over 65 video games . i am trying to create my own startup
company in the gaming industry . [PAT] Catastrophizing (Catastrophizing: Giving
greater weight to the worst possible outcome, however unlikely, or experiencing
a situation as unbearable or impossible when it is just uncomfortable.) [THT]
My wife recently got laid off from her huyman resources job, she''ll never be
able to find another job and we will lose our house soon.'
- - episode_done: true
eval_labels:
- My wife recently got laid off from her human resources job. I'm sure she will
be able to find another job soon.
id: reframe_thoughts
text: 'i design video games for a living . my wife recently got laid off from
her human resources job . my son plays on the local football team . i have been
on the design team for over 65 video games . i am trying to create my own startup
company in the gaming industry . [PAT] Catastrophizing (Catastrophizing: Giving
greater weight to the worst possible outcome, however unlikely, or experiencing
a situation as unbearable or impossible when it is just uncomfortable.) [THT]
My wife recently got laid off from her huyman resources job, she''ll never be
able to find another job and we will lose our house soon.'
num_episodes: 18635
num_examples: 18635
55 changes: 55 additions & 0 deletions parlai/tasks/reframe_thoughts/test/reframe_thoughts_train.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
acts:
- - episode_done: true
id: reframe_thoughts
labels:
- I like my cats. I have a fun imagination, but I know it's not likely they are
plotting against me to eat me.
text: 'i have a pencil thin mustache . i have six tattoos , all of cats . my mother
is a ballet dancer . i am from baltimore md . [PAT] Catastrophizing (Catastrophizing:
Giving greater weight to the worst possible outcome, however unlikely, or experiencing
a situation as unbearable or impossible when it is just uncomfortable.) [THT]
I like my cats. I think one day they will plot against me and eat me in my sleep.'
- - episode_done: true
id: reframe_thoughts
labels:
- I like my cats. I’ll get used to living with them and will be less afraid as
time goes on.
text: 'i have a pencil thin mustache . i have six tattoos , all of cats . my mother
is a ballet dancer . i am from baltimore md . [PAT] Catastrophizing (Catastrophizing:
Giving greater weight to the worst possible outcome, however unlikely, or experiencing
a situation as unbearable or impossible when it is just uncomfortable.) [THT]
I like my cats. I think one day they will plot against me and eat me in my sleep.'
- - episode_done: true
id: reframe_thoughts
labels:
- I like my cats so I will make sure to give them all the exercise and playtime
that they need.
text: 'i have a pencil thin mustache . i have six tattoos , all of cats . my mother
is a ballet dancer . i am from baltimore md . [PAT] Catastrophizing (Catastrophizing:
Giving greater weight to the worst possible outcome, however unlikely, or experiencing
a situation as unbearable or impossible when it is just uncomfortable.) [THT]
I like my cats. I think one day they will plot against me and eat me in my sleep.'
- - episode_done: true
id: reframe_thoughts
labels:
- I'm a vegan, and the restaurant served me a dis with fish in it. I believe I
should have told them I am a vegan.
text: i like visiting art museums in my spare time . i just started dating someone
new . i m a student . i am a vegan . [PAT] Overgeneralization (Someone who overgeneralizes
makes faulty generalizations from insufficient evidence. Even if something bad
happens only once, it is expected to happen over and over again.) [THT] I'm
a vegan, and the restaurant served me a dish with fish in it. They're trying
to kill me.
- - episode_done: true
id: reframe_thoughts
labels:
- I'm vegan, and the restaurant served me a dish with a fish in it. I'll just
notify the waiter and have it sent back.
text: i like visiting art museums in my spare time . i just started dating someone
new . i m a student . i am a vegan . [PAT] Overgeneralization (Someone who overgeneralizes
makes faulty generalizations from insufficient evidence. Even if something bad
happens only once, it is expected to happen over and over again.) [THT] I'm
a vegan, and the restaurant served me a dish with fish in it. They're trying
to kill me.
num_episodes: 5249
num_examples: 5249
53 changes: 53 additions & 0 deletions parlai/tasks/reframe_thoughts/test/reframe_thoughts_valid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
acts:
- - episode_done: true
eval_labels:
- I tried making my own hummus for the party. My friends will appreciate my hard
work.
id: reframe_thoughts
text: 'i love to eat pita bread with hummus . i am bipolar . i am thinking of
becoming a mother next year . i go to work early in the morning as a nurse .
i am a mother of three . [PAT] Jumping to conclusions: Fortune-telling (Predicting
outcomes (usually negative) of events.) [THT] I tried making my own hummus for
the party. My friends will hate it.'
- - episode_done: true
eval_labels:
- Working from home is convenient and allows me to spend more time with my family.
id: reframe_thoughts
text: i have a cat . i hope to move out soon . i work at home , editing . i've
depression and anxiety so i don't really go out a lot . i live at home with
my dad and brother . [PAT] Discounting the positive (Rejecting positive experiences
by insisting they "don't count" for some reason or other.) [THT] Although working
from home is convenient, my family gets tired of me being around.
- - episode_done: true
eval_labels:
- Working from home is convenient. My family probably appreciates that I have
a good job.
id: reframe_thoughts
text: i have a cat . i hope to move out soon . i work at home , editing . i've
depression and anxiety so i don't really go out a lot . i live at home with
my dad and brother . [PAT] Discounting the positive (Rejecting positive experiences
by insisting they "don't count" for some reason or other.) [THT] Although working
from home is convenient, my family gets tired of me being around.
- - episode_done: true
eval_labels:
- Although working at home is convenient, my family hopes I will start working
more at the office which would allow me to focus more.
id: reframe_thoughts
text: i have a cat . i hope to move out soon . i work at home , editing . i've
depression and anxiety so i don't really go out a lot . i live at home with
my dad and brother . [PAT] Discounting the positive (Rejecting positive experiences
by insisting they "don't count" for some reason or other.) [THT] Although working
from home is convenient, my family gets tired of me being around.
- - episode_done: true
eval_labels:
- I have been dieting for two months now, and today I had a setback because I
ate a cupcake. That's okay though, I'll go to the gym and work off that cupcake
and get stronger at the same time!
id: reframe_thoughts
text: i cannot drive . i'm on a diet . i am thirty two years old . i've been married
eight years . i'm a house wife . [PAT] Mental filtering (Filtering distortions
occur when an individual dwells only on the negative details of a situation
and filters out the positive aspects.) [THT] My diet is ruined. Sure I have
done it for 2 months now and lost weight but I ate a cupcake today.
num_episodes: 2623
num_examples: 2623
17 changes: 17 additions & 0 deletions projects/reframe_thoughts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Training Models to Generate, Recognize, and Reframe Unhelpful Thoughts

Mounica Maddela, Megan Ung, Jing Xu, Andrea Madotto, Heather Foran, Y-Lan Boureau

## Abstract

Many cognitive approaches to well-being, such as recognizing and reframing unhelpful thoughts, have received considerable empirical support over the past decades, yet still lack truly widespread adoption in self-help format. A barrier to that adoption is a lack of adequately specific and diverse dedicated practice material. This work examines whether current language models can be leveraged to both produce a virtually unlimited quantity of practice material illustrating standard unhelpful thought patterns matching specific given contexts, and generate suitable positive reframing proposals. We propose \textsc{PatternReframe}, a novel dataset of about 10k examples of thoughts containing unhelpful thought patterns conditioned on a given persona, accompanied by about 27k positive reframes. By using this dataset to train and/or evaluate current models, we show that existing models can already be powerful tools to help generate an abundance of tailored practice material and hypotheses, with no or minimal additional model training required.

## Paper



## Data

```
parlai display_data -t reframe_thoughts
```