Created
December 15, 2021 14:22
-
-
Save patientzero/5c8ce0589bae37c476505280c48d5404 to your computer and use it in GitHub Desktop.
loading wai labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def load_cbt_annotations(path): | |
import json | |
with open(path) as f: | |
x = json.load(f) | |
# make session numeric | |
df = pd.DataFrame() | |
for k, v in x.items(): | |
while v: | |
session, vv = v.popitem() | |
session = int(session[0]) | |
df_v = pd.DataFrame() | |
for annotation in vv: | |
a_id = annotation.pop('annotator_id') | |
df_v = df_v.append(pd.DataFrame(annotation, index=pd.MultiIndex.from_tuples([(session, a_id, k)], | |
names=['session', 'annotator', 'speaker']))) | |
df = df.apply(pd.to_numeric) | |
df = df.append(df_v) | |
return df | |
goal = ['wai_4', 'wai_6', 'wai_10', 'wai_11'] | |
task = ['wai_1', 'wai_2', 'wai_8', 'wai_12'] | |
bond = ['wai_3', 'wai_5', 'wai_7', 'wai_9'] | |
categories = ['goal', 'task', 'bond'] | |
wais = [f'wai_{i}' for i in range(1, 13) | |
filter_annotators = True | |
df_label = load_cbt_annotations('transkriptions_coadapt/CBT_WAI.json') | |
df_label = df_label[wais].astype(float).dropna() | |
df_label = df_label.reset_index() | |
if filter_annotators: | |
df_label = df_label[df_label.annotator.isin([43, 52])] | |
df_agg_labels = df_label.groupby(['speaker', 'session']).mean() | |
df_agg_labels = df_agg_labels.reset_index()[['speaker', 'session', *wais]] | |
df_agg_labels['id'] = df_agg_labels[['speaker', 'session']].apply(lambda x: '_'.join(x.astype(str)), axis=1) | |
df_agg_labels['goal'] = df_agg_labels[goal].apply(lambda x: round(sum(x) / len(goal)), axis=1) | |
df_agg_labels['bond'] = df_agg_labels[bond].apply(lambda x: round(sum(x) / len(bond)), axis=1) | |
df_agg_labels['task'] = df_agg_labels[task].apply(lambda x: round(sum(x) / len(task)), axis=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment