<jupyter_start><jupyter_text>livelossplot example: extended APILast update: `livelossplot 0.5.2`. For code and documentation, see [livelossplot GitHub repository](https://github.com/stared/livelossplot).<jupyter_code>!pip install livelossplot --quiet
%matplotlib inline

from time import sleep
import numpy as np

from livelossplot import PlotLosses, MainLogger
from livelossplot.outputs import BaseOutput<jupyter_output><empty_output><jupyter_text>How to define groups<jupyter_code>groups = {'acccuracy': ['acc', 'val_acc'], 'log-loss': ['loss', 'val_loss']}
plotlosses = PlotLosses(groups=groups)
for epoch in range(1, 100):
    plotlosses.update({
        'acc': 1 - np.random.rand() / (epoch + 2.),
        'val_acc': 1 - np.random.rand() / (epoch + 0.5),
        'loss': 1. / (epoch + 2.),
        'val_loss': 1. / (epoch + 0.5)
    })
    plotlosses.send()
    sleep(.01)<jupyter_output><empty_output><jupyter_text>How to define groups with regex patterns<jupyter_code>group_patterns = [
    (r'^(train(_|-))(.*)', 'training'),
    (r'^(val_cats(_|-))(.*)', 'validation_cats'),
    (r'^(val_dogs(_|-))(.*)', 'validation_dogs'),
    (r'^(val_all(_|-))(.*)', 'validation_all'),
]
plotlosses = PlotLosses(group_patterns=group_patterns)
for epoch in range(1, 100):
    plotlosses.update({
        'train_acc': 1 - np.random.rand() / (epoch + 2.),
        'val_all_acc': 1 - np.random.rand() / (epoch + 0.5),
        'val_dogs_acc': 1 - np.random.rand() / (epoch + 0.5),
        'val_cats_acc': 1 - np.random.rand() / (epoch + 0.5),
        'train_loss': 1. / (epoch + 2.),
        'val_all_loss': 1. / (epoch + 0.5 * np.random.rand()),
        'val_cats_loss': 1. / (epoch + 0.5 * np.random.rand()),
        'val_dogs_loss': 1. / (epoch + 0.5 * np.random.rand())
    })
    plotlosses.send()
    sleep(.01)<jupyter_output><empty_output><jupyter_text>How to write custom pluginIf you want to create a custom output you have to create class that inherits from the BaseOutput and override `send` method.<jupyter_code>class AccuracyPrint(BaseOutput):
    def send(self, logger: MainLogger):
        grouped_log_history = logger.grouped_log_history()
        for group_name, group_logs in grouped_log_history.items():
            for metric_name, logs in group_logs.items():
                vals = [log.value for log in logs]
                if group_name == 'Accuracy':
                    print('{} accuracy: {}'.format(metric_name, sum(vals) / len(vals)))

plotlosses = PlotLosses(outputs=[AccuracyPrint()])
for epoch in range(1, 5):
    plotlosses.update({
        'acc': 1 - np.random.rand() / (epoch + 2.),
        'val_acc': 1 - np.random.rand() / (epoch + 0.5),
        'loss': 1. / (epoch + 2.),
        'val_loss': 1. / (epoch + 0.5)
    })
    plotlosses.send()
    sleep(.01)<jupyter_output>training accuracy: 0.7825222766056974
validation accuracy: 0.579172514342329
training accuracy: 0.8900729432701822
validation accuracy: 0.6080767827381713
training accuracy: 0.8626459645554587
validation accuracy: 0.7176364082970258
training accuracy: 0.8809672556107493
validation accuracy: 0.7639963416704895
{'fraction_non_alphanumeric': 0.15884244372990353, 'fraction_numerical': 0.06302250803858521, 'mean_word_length': 3.4762589928057555, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, '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}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '160587', 'license': 'MIT', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1093, 'n_words': 244, 'path': 'examples/various_options.ipynb', 'repo_name': 'rameshKrSah/livelossplot', 'size': '3110'}