@@ -0,0 +1,1943 @@
+%22%22%22Generate visualization pairs (emotion label - concept type) for predicted%0Alabels.%0A%0AInput: directory containing text files with predicted heem labels.%0A%0AGenerates a text file containing%0A%3Ctext_id%3E%5Ct%3Csentence id%3E%5Ct%3Cemotion label%3E%5Ct%3Cconcept type label%3E%0Afor each file in the input dir.%0A%0AUsage: python predictions2visualization.py %3Cdir in%3E %3Cdir out%3E%0A%22%22%22%0Aimport argparse%0Aimport glob%0Aimport os%0Aimport codecs%0Afrom count_labels import load_data%0Afrom emotools.heem_utils import heem_emotion_labels, heem_concept_type_labels%0A%0Aif __name__ == '__main__':%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('input_dir', help='directory containing files with '%0A                        'predictions.')%0A    parser.add_argument('output_dir', help='the directory where the '%0A                        'generated text files should be saved')%0A    args = parser.parse_args()%0A%0A    input_dir = args.input_dir%0A    output_dir = args.output_dir%0A%0A    text_files = glob.glob(os.path.join(input_dir, '*.txt'))%0A    for i, text_file in enumerate(text_files):%0A        print '(%7B%7D of %7B%7D) %7B%7D'.format((i+1), len(text_files), text_file)%0A        text_id = text_file%5B-17:-4%5D%0A%0A        X_data, Y_data = load_data(text_file)%0A%0A        out_file = os.path.join(output_dir, os.path.basename(text_file))%0A        with codecs.open(out_file, 'wb', 'utf-8') as f:%0A            for j, predicted in enumerate(Y_data):%0A                lbs = (set(predicted.split('_')) - %7B'None'%7D)%0A                emotion_labels = %5Bl for l in lbs if l in heem_emotion_labels%5D%0A                ct_labels = %5Bl for l in lbs if l in heem_concept_type_labels%5D%0A                if emotion_labels and ct_labels:%0A                    for e in emotion_labels:%0A                        for ct in ct_labels:%0A                            sent_id = X_data%5Bj%5D.split('%5Ct')%5B0%5D%0A                            f.write('%7B%7D%5Ct%7B%7D%5Ct%7B%7D%5Ct%7B%7D%5Cn'.format(text_id, sent_id,%0A                                                              e, ct))%0A

Add script to generate visualization pairs for predicted labels