<jupyter_start><jupyter_text>Visualizations of the learned modelsIn this notebook, one can load two pre-trained models to see how the network is behaving. The following visualizations are the simplified and cleaned up versions of our submitted paper at https://arxiv.org/abs/1606.06724.<jupyter_code># Let's first Define some path to the pre-learned models.
MNIST_RUN = './pretrained_models/mnist-results'
SHAPES_RUN = './pretrained_models/shapes-results'

# Let's enable auto-reload for clarity.
%matplotlib inline
%load_ext autoreload
%autoreload 2
%pwd
# prepare the import.
%load_ext autoreload
%autoreload 2

import numpy as np
import matplotlib.pyplot as plt

from utils import AttributeDict
import tagger_exp

from analyze import analyze_plot_publication<jupyter_output><empty_output><jupyter_text>Visualization of Network behavior on Shapes50k20x20<jupyter_code># here we have five models to calculate the final AMI score
# default override
override = AttributeDict(
        n_iterations=5,
        n_groups=4,
        valid_batch_size=1000,
        batch_size=1000,
    )

shapes_exp = tagger_exp.TaggerExperiment.load(SHAPES_RUN, p_override=override)
it = shapes_exp.streams['valid'].get_epoch_iterator(as_dict=True)
mb = next(it)
acts = shapes_exp.tagger.eval_acts(mb)
%load_ext autoreload
%autoreload 2
from analyze import analyze_plot_publication

index_to_plot = acts.clean.ami_score_per_sample[-1].argsort()[100:1000:80][:6][::-1]
index_to_zoom = index_to_plot[0]

special_pairs = [
    {
        'acts': acts,
        'mb': mb,
        'index': 25,
    },
    {
        'acts': acts,
        'mb': mb,
        'index': 19
    },
    {
        'acts': acts,
        'mb': mb,
        'index': 50,
    }
]

f = analyze_plot_publication(index_to_zoom, index_to_plot[:6], acts, mb, 
                             S=(20, 20), specials=special_pairs, saturations_in_z=True)<jupyter_output><empty_output><jupyter_text>MNIST<jupyter_code>mnist_override = AttributeDict(
    n_iterations=5,
    load_from=None,
    n_groups=4,
    valid_batch_size=1000,
    batch_size=1000,
    )
mnist_override2 = AttributeDict(
    dataset='freq20-1mnist',
    load_from=None,
    objects_per_sample=1,
    n_iterations=5,
    n_groups=4,
    valid_batch_size=1000,
    batch_size=1000,
    )

mnist_exp = tagger_exp.TaggerExperiment.load(MNIST_RUN, p_override=mnist_override)
mnist_exp1 = tagger_exp.TaggerExperiment.load(MNIST_RUN, p_override=mnist_override2)
mnist_it = mnist_exp.streams['test'].get_epoch_iterator(as_dict=True)
mnist_it2 = mnist_exp1.streams['test'].get_epoch_iterator(as_dict=True)
mnist_mb = next(mnist_it)
mnist_mb2 = next(mnist_it2)

mnist_acts = mnist_exp.tagger.eval_acts(mnist_mb)
mnist_acts2 = mnist_exp1.tagger.eval_acts(mnist_mb2)
index_to_plot = mnist_acts.clean.ami_score_per_sample[-1].argsort()[154:1000:90][3:]

index_to_zoom = index_to_plot[-1]

special_pairs = [
    {
        'acts': mnist_acts2,
        'mb': mnist_mb2,
        'index': 19
    },
    {
        'path_x': './pretrained_models/mnist-results/mnist_removal_example_v3.npz',
        'type': 'm'
    },
    {
        'path_x': './pretrained_models/mnist-results/mnist_removal_example_v3.npz',
        'type': 'm_removed'
    }
]

f = analyze_plot_publication(index_to_zoom, index_to_plot[::-1], mnist_acts, mnist_mb, 
                             S=(28, 28), specials=special_pairs, plot_classification=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10926573426573427, 'fraction_numerical': 0.03175990675990676, 'mean_word_length': 4.101040118870728, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '335971', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1259, 'n_words': 220, 'path': 'publication_visualization.ipynb', 'repo_name': 'CuriousAI/tagger', 'size': '3432'}