# Model Perception Analysis

To perform this analysis, go to the **Dashboard** view on the right, and select `Analyzer` from the list at the top.

## Population Exploration Analysis

The Tensorleap platform tracks how each learned feature, within each layer, responds to each sample. From that information, it constructs a vector that captures how the model ***perceives*** each sample. This allows the platform to create a **similarity map** between samples as they are interpreted by the model. A more intuitive explanation would be that similar samples would activate similar learned features within the model.

{% hint style="info" %}
For more information on model evaluation and training, see [**Evaluate/Train Model**](/user-interface/project/menu-bar/evaluate-a-model.md).
{% endhint %}

**Population Exploration Analysis** takes these vectors and runs dimension reduction algorithms in order to visualize the similarities in the UI and provide helpful insights on how various samples are perceived by the model.

In this section, we will perform a **Population Exploration** analysis. For more information, see [**Population Exploration**](/user-interface/dashboards/dashlets/sample-analysis.md#population-exploration).

After each epoch in the training process, a **Population Exploration** analysis is performed automatically, the results of which can be found under the **Analysis** panel in the **Dashboard** view.

Each dot represents a sample (hover your mouse over it to see the sample's preview), while by default the dot's **size** and **color** represent the sample's loss. This can be changed to fit your preferences. For example, we can change the **color** to represent the ground truth label - `metadata_label`. By doing that, we can easily see the clusters formed for each label. In addition, we can see which label cluster is perceived to be similar to another, and which failing samples are not located within the right cluster.

![Color Dots by Label](/files/FGAblUYyfwccMxSeIrQ2)

Further exploration reveals that the cluster that represents the digit `7` is close to the cluster that represents the number `1`. This means that the network finds these clusters similar relative to the other clusters.

In the default view, the dot **size** represents the loss (error). Large dot size is highly correlated with a failed prediction for that sample.

Exploring some of the samples with high loss reveals possible ambiguities. Once a sample dot is clicked, its details are displayed on the right. For example:

![Sample's Details](/files/AN5jMfKP5vRfmRm8lKeG)

As the above image shows, ground truth is `8` (`metadata_label: 8`), but it can be easily mistaken for a `9`.

{% hint style="info" %}
Note that due to the randomness of the initial weights, your model could converge to a different state, thus rendering different results.
{% endhint %}

## Sample Analysis <a href="#mnist.sample.analysis" id="mnist.sample.analysis"></a>

Analysis of a sample returns results from a variety of explainability algorithms. Details about these algorithms can be found at [**Sample Analysis**](/user-interface/dashboards/dashlets/sample-analysis.md#sample-analysis).&#x20;

**Click** a **sample dot** to select it, then click <img src="/files/tf9RbagIIBeSPWDWAGY3" alt="" data-size="line"> at the bottom right to analyze the selected sample.

Once the analysis completes, we can explore the model's response to the sample. In the example below, we can see that the model's **prediction** was `9` while the **ground truth** is `8`.

![Sample Ground Truth vs Prediction](/files/PILDgkPAdEkwD7UzNUcU)

Additionally, we can see which features contribute to the loss by clicking the **LOSS ANALYSIS** on the right.

![Heatmaps Correlated for the Loss](/files/wc16RD4Oj0BM4D3rv1qg)

By clicking on the **feature\_map** heat-map on the right, we can analyze and see which features activates for each output. Let's explore the heat maps for output classes 8 and 9.&#x20;

Click the 8 tab below to see the heat map highlights features correlated with class `8`. There is a red spot around the upper loop of the digit 8, but it is fairly subtle

Click the 9 tab below to see the heat map for class `9`. The red spots are what the model finds to be highly correlated with class `9`.

{% tabs %}
{% tab title="8" %}
![Input Heat Map for 8](/files/Sp2VoL4hi0FnFYHsJXOv)
{% endtab %}

{% tab title="9" %}
![Input Heat Map for  9](/files/SCdtCs9nNKgWtDZXez8A)
{% endtab %}
{% endtabs %}

Another interesting example is this sample - ![](/files/bSQP2TQXANghquJE2udu) which contains features that can correspond to various digits. In this sample, the model's predictions are non-zero probabilities for various classes.

Below are heat maps for the different classes, each highlights areas that correspond to features in the class:

{% tabs %}
{% tab title="0" %}
![Heat Map for Class 0](/files/jkQtxxsYgTSNX2s58GGy)
{% endtab %}

{% tab title="1" %}
![Heat Map for Class 1](/files/FwZMOwgc4tcBUHanR298)
{% endtab %}

{% tab title="2" %}
![Heat Map for Class 2](/files/glTe9AWKeGAgIvnMAaC6)
{% endtab %}

{% tab title="3" %}
![Heat Map for Class 3](/files/IlbgWzdxBqRhJH4xsbYY)
{% endtab %}

{% tab title="4" %}
![Heat Map for Class 4](/files/fBPtsTucQlWfd2of2oFX)

{% endtab %}

{% tab title="5" %}
![Heat Map for Class 5](/files/Dapos8nDuYJEVe68BkbO)
{% endtab %}

{% tab title="6" %}
![Heat Map for Class 6](/files/iMS7nk0MHOF3UxSADd05)
{% endtab %}

{% tab title="7" %}
![Heat Map for Class 7](/files/FBuJc18LcV935fzkSrL9)
{% endtab %}

{% tab title="8" %}
![Heat Map for Class 8](/files/LF695jWQhph8PxqsQ34J)
{% endtab %}

{% tab title="9" %}
![Heat Map for Class 9](/files/oyqZJCBuA3HTedvM0TUr)
{% endtab %}
{% endtabs %}

## Fetch Similar

As explained, Tensorleap tracks how each learned feature responds to each sample. This allows finding samples that the model considers similar to one another, as they *activate* similar learned features.

To present similar samples, select a sample and click the <img src="/files/fLAwTzpgFz3li5p1clYE" alt="" data-size="line"> button at the bottom right.

![Fetch Similar](/files/5ezy1RE2P1i04HGFZ9ba)

When this task completes, it returns a cluster of similar samples:

![Fetch Similar Results](/files/pOs3zMVFAYrRx80xUDLQ) ![Similar Samples](/files/QWZZBOYUU7YN17dpeX4r)

As can be seen above, the cluster contains various similarly written versions of the number `6`.

#### Investigating the Closed 4 Digit

The MNIST dataset includes two ways of writing the number four: <img src="/files/8W6JeyXIaTG9S0F3YkIO" alt="" data-size="line"> and <img src="/files/PF6BVJ02LLLzEKrsSnkK" alt="" data-size="line">.

Below are samples that are similar to <img src="/files/8W6JeyXIaTG9S0F3YkIO" alt="" data-size="line">. The presented heat maps highlight the areas in the input that define those similarities.

![Similar Samples Heat Map](/files/XESbIzFUyRoin1AtcccJ)

The model detected 4 samples that are similar to <img src="/files/8W6JeyXIaTG9S0F3YkIO" alt="" data-size="line">, while the other samples are mostly `9`. This means two things:

* The model finds <img src="/files/8W6JeyXIaTG9S0F3YkIO" alt="" data-size="line"> to be very similar to 9, and there is a chance that some will be confused by this similarity.
* The model does not have enough samples that are written in this way, and it is recommended to either add such samples to the dataset or label them differently.

There are also two ways of writing the number seven: <img src="/files/pdIaEB5u1BbFQDuGk5Pj" alt="" data-size="line"> and <img src="/files/cChMn3mnY1GU3dai2GkG" alt="" data-size="line">. You can try and analyze this digit in the same manner as above.

## Up Next - Advanced Metrics

Thus far, we've shown how Tensorleap performs population exploration analysis, sample analysis, and analysis using similar samples.&#x20;

Next, we will add custom metadata to help us find more correlations in our samples and model. Let's now move on to [**Advanced Metrics**](/guides/full-guides/mnist-guide/advanced-metrics.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorleap.ai/guides/full-guides/mnist-guide/model-perception-analysis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
