Skip to content

Commit 5b6d540

Browse files
lindsaydbringabegmaJosephMarinier
authored
Class overlap comms, in-app and in docs (#312)
Including "Class Analysis" -> "Class Overlap" Co-authored-by: Gabrielle Gauthier Melancon <[email protected]> Co-authored-by: joseph.marinier <[email protected]>
1 parent 8271902 commit 5b6d540

21 files changed

+274
-257
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Released changes are shown in the
1414
- Azimuth now works on French datasets (and pipelines)! Language can be selected in the config,
1515
and language-specific defaults for syntax-tagging and behavioral tests (neutral tokens) will be
1616
set dynamically (or can be altered manually).
17-
- New class analysis section, with class overlap detection. More details are available in the User Guide and in the Key Concepts.
17+
- New class overlap section, with class overlap detection. More details are available in the User Guide and in the Key Concepts.
1818
- Pipeline pre/post-processing steps breakdown in the utterance detail page.
1919

2020
### Changed

azimuth/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def create_app() -> FastAPI:
164164
api_router.include_router(admin_router, prefix="/admin")
165165
api_router.include_router(
166166
class_overlap_router,
167-
prefix="/class_analysis",
167+
prefix="/class_overlap",
168168
dependencies=[Depends(require_application_ready)],
169169
)
170170
api_router.include_router(tags_router, prefix="/tags", dependencies=[])

azimuth/routers/v1/class_overlap.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from azimuth.task_manager import TaskManager
1515
from azimuth.types import DatasetSplitName, ModuleOptions, SupportedModule
1616
from azimuth.types.class_overlap import (
17-
ClassAnalysisClassPair,
18-
ClassAnalysisResponse,
1917
ClassOverlapPlotResponse,
2018
ClassOverlapResponse,
19+
ClassOverlapTableClassPair,
20+
ClassOverlapTableResponse,
2121
)
2222
from azimuth.types.model_performance import ConfusionMatrixResponse
2323
from azimuth.utils.project import similarity_available
@@ -90,15 +90,15 @@ def get_class_overlap_plot(
9090
summary="Get class overlap table.",
9191
description="Get data for class overlap, confusion, and related utterance counts.",
9292
tags=TAGS,
93-
response_model=ClassAnalysisResponse,
93+
response_model=ClassOverlapTableResponse,
9494
)
95-
def get_class_analysis(
95+
def get_class_overlap(
9696
task_manager: TaskManager = Depends(get_task_manager),
9797
dataset_split_managers: Dict[DatasetSplitName, DatasetSplitManager] = Depends(
9898
get_all_dataset_split_managers
9999
),
100100
pipeline_index: Optional[int] = Depends(query_pipeline_index),
101-
) -> ClassAnalysisResponse:
101+
) -> ClassOverlapTableResponse:
102102
dm = dataset_split_managers[DatasetSplitName.train]
103103
class_counts_train = dm.class_distribution()
104104
class_counts_eval = dataset_split_managers[DatasetSplitName.eval].class_distribution()
@@ -133,7 +133,7 @@ def get_class_analysis(
133133
)
134134

135135
class_pairs_list = [
136-
ClassAnalysisClassPair(
136+
ClassOverlapTableClassPair(
137137
source_class=class_names[i],
138138
target_class=class_names[j],
139139
overlap_score_train=class_overlap_result.s_matrix[i, j],
@@ -151,6 +151,6 @@ def get_class_analysis(
151151
)
152152
]
153153

154-
api_result = ClassAnalysisResponse(class_pairs=class_pairs_list)
154+
api_result = ClassOverlapTableResponse(class_pairs=class_pairs_list)
155155

156156
return api_result

azimuth/types/class_overlap.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ClassOverlapPlotResponse(AliasModel):
3030
default_overlap_threshold: float
3131

3232

33-
class ClassAnalysisClassPair(AliasModel):
33+
class ClassOverlapTableClassPair(AliasModel):
3434
source_class: str = Field(..., title="Source class")
3535
target_class: str = Field(..., title="Target class")
3636
overlap_score_train: float = Field(..., title="Overlap score on train")
@@ -46,5 +46,5 @@ class ClassAnalysisClassPair(AliasModel):
4646
)
4747

4848

49-
class ClassAnalysisResponse(AliasModel):
50-
class_pairs: List[ClassAnalysisClassPair] = Field(..., title="Class pair overlap data")
49+
class ClassOverlapTableResponse(AliasModel):
50+
class_pairs: List[ClassOverlapTableClassPair] = Field(..., title="Class pair overlap data")

docs/docs/key-concepts/class-similarity.md

-73
This file was deleted.

docs/docs/key-concepts/similarity.md

+40-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ analysis can be quite powerful given that **no trained ML model is needed**; onl
77
be supplied.
88

99
Within Azimuth, different similarity analyses are provided to determine how similar utterances are
10-
within a class, across classes, and so on. This can help indicate whether classes are well-defined,
10+
within a class, between classes, and so on. This can help indicate whether classes are well-defined,
1111
or whether changes should be made to improve the dataset, such as by redefining classes, relabeling
1212
or omitting data, or augmenting the dataset.
1313

1414
## Where is this used in Azimuth?
1515

1616
In Azimuth, the similarity analysis is used to derive [:material-link: Smart Tags](smart-tags.md),
1717
and also to show the most similar utterances in both dataset splits on
18-
the [:material-link: Utterances Details](../user-guide/exploration-space/utterance-details.md).
18+
the [:material-link: Utterances Details](../user-guide/exploration-space/utterance-details.md)
19+
(see below).
20+
21+
Similarity is also used for class overlap, which assesses the semantic overlap between pairs of
22+
classes. Class overlap is presented in the [Class Overlap Dashboard
23+
Section](../user-guide/index.md#class-overlap) as well as the
24+
[:material-link: Class Overlap](../user-guide/class-overlap.md) page.
1925

2026
<figure markdown>
2127
![Image title](../_static/images/exploration-space/utterance-details-similarity.png)
@@ -62,6 +68,35 @@ and/or `conflicting_neighbors_eval`, based on which dataset split is being exami
6268
utterance in the test set will be compared to its neighbors in both the training and evaluation
6369
dataset splits.)
6470

71+
### Class Overlap
72+
73+
#### Class Overlap Value
74+
75+
Class overlap is calculated using utterance embeddings, which are computed as described above.
76+
77+
Class overlap for class *C<sub>i</sub>* (source class) with class *C<sub>j</sub>* (target class) is
78+
defined as the area of the feature (embedding) space in which an utterance in class
79+
*C<sub>i</sub>* has a greater probability of being in class *C<sub>j</sub>* than in class
80+
*C<sub>i</sub>*.
81+
82+
To approximate this probability, we make use of the
83+
[`spectral-metric`](https://github.com/Dref360/spectral-metric) package
84+
([Branchaud-Charron, 2019](https://arxiv.org/abs/1905.07299)[^2]). The probability of a sample
85+
being in a specified class is determined based on the representation of this class in the
86+
sample's 5 nearest neighbors, as well as the hypervolume containing these neighbors (Parzen
87+
window). Class overlap for the *C<sub>i</sub>* with the *C<sub>j</sub>* is calculated as the mean
88+
probability across all samples in *C<sub>i</sub>*. The similarity matrix *S* from `spectral-metric`
89+
contains these probabilities for all class pairs. Note that probabilities are normalized by the
90+
source class, to sum to 1.
91+
92+
#### Samples with overlap
93+
94+
Individual samples from a source class are determined to have overlap with a target class when
95+
their probability of being in the target class is greater than 0, which is the same as saying
96+
that at least one of their 5 nearest neighbors are from the target class. This is a
97+
conservative metric, on which we anticipate iterating in the future.
98+
99+
65100
### Configuration
66101

67102
[:material-link: Similarity Analysis Configuration](../reference/configuration/analyses/similarity.md)
@@ -71,5 +106,8 @@ the smart tags.
71106

72107
[^1]: Reimers, Nils, and Iryna Gurevych. "Sentence-bert: Sentence embeddings using siamese
73108
bert-networks." arXiv preprint arXiv:1908.10084 (2019).
109+
[^2]: Branchaud-Charron, Frederic, Andrew Achkar, and Pierre-Marc Jodoin. "Spectral metric for
110+
dataset complexity assessment." Proceedings of the IEEE/CVF Conference on Computer Vision and
111+
Pattern Recognition. 2019.
74112

75113
--8<-- "includes/abbreviations.md"

docs/docs/user-guide/class-analysis.md

-61
This file was deleted.

docs/docs/user-guide/class-overlap.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Class Overlap
2+
3+
Class overlap assesses the semantic overlap between pairs of classes. In some cases, high
4+
overlap may be associated with poor class definitions, mislabelling, and/or model confusion.
5+
6+
Class overlap is determined with a dataset alone, based on the locations of utterances in
7+
embedding space, as described in
8+
[:material-link: Similarity Analysis](../key-concepts/similarity.md).
9+
10+
## Class Overlap Plot
11+
12+
The Class Overlap plot shows the extent to which source classes semantically overlap target
13+
classes, all in the training data. The source class is the class label, and the target class is
14+
the class that the source class may look like, based on its nearest neighbors. As such, flows
15+
between class nodes indicate whether samples in a source class are in neighborhoods typified
16+
by other classes (class overlap) or its own class (self overlap). For each source class, class
17+
overlap and self-overlap values sum to 1, unless values are scaled by class size.
18+
19+
Overlap is displayed as flows from source class (nodes on the left) to target classes (right).
20+
Nodes are ordered with flows for greatest overlap values towards the top, so as to highlight these
21+
class pairs. Wider flows indicate greater overlap values. Colors group flows from the same
22+
source class. The plot is interactive, in that nodes can be moved and reordered via dragging.
23+
24+
### Plot options
25+
26+
* **Minimum displayed overlap value**: This value determines which overlap flows will be displayed
27+
on the plot. Vary this value to focus on class pairs with greatest overlap, or to see all
28+
overlap to better understand the complexity of the dataset. The default value is set to the
29+
tenth-highest class overlap value for ease of visualization alone, and will differ across
30+
different datasets.
31+
* **Self-overlap**: This toggle determines whether to show flows for overlap of a class with
32+
itself, to get a sense of the relative magnitude (and possibly importance) of class overlap.
33+
* **Scale by class size**: Overlap values are normalized by source class, such that the sum of
34+
all class overlap and self-overlap values for a source class is 1. This toggle multiples overlap
35+
values by class sample sizes, changing node size and flow width accordingly.
36+
37+
### Suggested workflow
38+
39+
The plot options described above allow for exploration of different aspects of class overlap. To
40+
navigate them, we suggest the following workflow:
41+
42+
#### 1. Default view: `Self-overlap` off, `Scale by class size` on
43+
44+
- Start here. This view shows you the class pairs with the greatest (scaled) semantic overlap
45+
scores in the dataset. Vary the `Minimum displayed overlap value` to see all dataset overlap or
46+
to focus on the class pairs with the greatest overlap scores.
47+
- Because `Scale by class size` is on, this view will emphasize overlapping classes with greater
48+
sample counts. This is useful if you are less concerned about class overlap from
49+
source classes with few samples in the training data. However, if you want to further investigate
50+
classes with high overlap values but fewer samples, either for better understanding your dataset
51+
or because some classes might have high business value, then you can toggle `Scale by class size`
52+
to off, as explained in step 2.
53+
54+
#### 2. Toggle `Scale by class size` off:
55+
56+
- When `Scale by class size` is turned off, total flows (class overlap and self-overlap) sum to 1.
57+
This view emphasizes class pairs with the greatest class overlap scores, regardless of
58+
whether the source class has many samples in it.
59+
- This is useful to further understand class overlap for classes that have relatively fewer
60+
samples in them, which might not have been as visible during the analysis at step 1.
61+
62+
#### 3. Toggle `Self-overlap` on:
63+
64+
- For any given class, turning on `Self-overlap` lets you compare the extent to which its samples
65+
semantically overlap other classes (class overlap) vs. samples of its own class (self-overlap).
66+
For example, if self-overlap is much higher than class overlap, class overlap may be less
67+
problematic for this class, and vice versa.
68+
69+
!!! tip
70+
71+
:material-restart: Click the reset button next to the overlap threshold value to reset to
72+
the default threshold.
73+
74+
<figure markdown>
75+
![](../_static/images/key-concepts/class-overlap-plot.png)
76+
<figcaption>
77+
Class Overlap plot on the Class Overlap page, accessed via the Dashboard.
78+
</figcaption>
79+
</figure>
80+

0 commit comments

Comments
 (0)