<commit_before>
# FIND LOSS INCREASES PY

# Brettin email 2019-12-18:
# Analysis 2: a list of validation samples,
# that when added to the training samples,
# cause the performance of the node/model to decrease.

import argparse, os, pickle, sys

from Node import Node
from utils import abort

parser = argparse.ArgumentParser(description='Finds loss increases.')
parser.add_argument('directory',
                    help='The experiment directory (EXPID)')

args = parser.parse_args()

node_pkl = args.directory + "/node-info.pkl"

try: 
    with open(node_pkl, 'rb') as fp:
        data = pickle.load(fp)
except IOError as e:
    abort(e, os.EX_IOERR, "Could not read: " + node_pkl)

# print(data)
increases = 0
total     = 0
for node_id in data.keys():
    parent = node_id[0:-2]
    if len(parent) == 1: # stage=1
        continue
    # print(node_id + " " + parent)
    if data[node_id].val_loss > data[parent].val_loss:
        increases += 1
    total += 1

fraction = 100.0 * increases / total
print("increases/total = %i / %i %02.f%%" % (increases, total, fraction))<commit_msg>Clean up, add comments<commit_after>
# FIND LOSS INCREASES PY

# Brettin email 2019-12-18:
# Analysis 2: a list of validation samples,
# that when added to the training samples,
# cause the performance of the node/model to decrease.

import argparse, os, pickle, sys

from Node import Node
from utils import abort

parser = argparse.ArgumentParser(description='Finds loss increases.')
parser.add_argument('directory',
                    help='The experiment directory (EXPID)')

args = parser.parse_args()

node_pkl = args.directory + "/node-info.pkl"

try: 
    with open(node_pkl, 'rb') as fp:
        # This is a dict ("node_id" -> Node)
        data = pickle.load(fp)
except IOError as e:
    abort(e, os.EX_IOERR, "Could not read: " + node_pkl)

increases = 0
total     = 0
for node_id in data.keys():
    parent = node_id[0:-2] # "1.2.3" -> "1.2"
    if len(parent) == 1: # stage=1
        continue
    if data[node_id].val_loss > data[parent].val_loss:
        increases += 1
    total += 1

fraction = 100.0 * increases / total
print("increases/total = %i / %i %02.f%%" % (increases, total, fraction))
{'fraction_non_alphanumeric': 0.1247155211652253, 'fraction_numerical': 0.02321347291761493, 'mean_word_length': 3.2432432432432434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3013985', 'n_tokens_mistral': 780, 'n_tokens_neox': 737, 'n_words': 229}