|
1 | | -# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | | -# SPDX-License-Identifier: Apache-2.0 |
3 | | - |
4 | 1 | # --- |
5 | 2 | # jupyter: |
6 | 3 | # jupytext: |
|
15 | 12 | # --- |
16 | 13 |
|
17 | 14 | # %% [markdown] |
| 15 | +# <!-- |
| 16 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 17 | +# SPDX-License-Identifier: Apache-2.0 |
| 18 | +# --> |
18 | 19 | # # 🕵️ Inspecting Detected Entities |
19 | 20 | # |
20 | 21 | # Dig into the entity detection pipeline output -- what was detected, |
|
26 | 27 | # We use **Annotate** mode because it preserves the original text while tagging each entity |
27 | 28 | # with its label, making it ideal for reviewing detection quality. |
28 | 29 | # |
| 30 | +# > **Privacy warning:** `Annotate` does not anonymize the text. Sensitive values |
| 31 | +# > remain in the output, so use it only for inspection -- not as a privacy-safe |
| 32 | +# > production strategy. |
| 33 | +# |
29 | 34 | # #### 📚 What you'll learn |
30 | 35 | # |
31 | 36 | # - Run the detection pipeline and inspect its output using Annotate mode |
|
100 | 105 | # %% [markdown] |
101 | 106 | # ## 📋 Columns |
102 | 107 | # |
103 | | -# - `trace_dataframe` contains all internal columns from the pipeline |
104 | | -# (detection, validation, replacement, etc.). |
| 108 | +# - `result.dataframe["final_entities"]` is the stable, public entity output. |
| 109 | +# - `trace_dataframe` contains internal pipeline columns for deeper debugging; |
| 110 | +# those underscore-prefixed columns may change between releases. |
105 | 111 |
|
106 | 112 | # %% |
107 | | -df = result.trace_dataframe |
108 | | -print(f"Records: {len(df)}") |
109 | | -print(f"Columns: {list(df.columns)}") |
| 113 | +trace_df = result.trace_dataframe |
| 114 | +final_entities = result.dataframe["final_entities"] |
| 115 | +print(f"Records: {len(trace_df)}") |
| 116 | +print(f"Columns: {list(trace_df.columns)}") |
110 | 117 |
|
111 | 118 | # %% [markdown] |
112 | 119 | # ## 🎯 Detected entities |
|
116 | 123 |
|
117 | 124 | # %% |
118 | 125 | row_idx = 0 |
119 | | -raw = df.loc[row_idx, "_detected_entities"] |
| 126 | +raw = final_entities.iloc[row_idx] |
120 | 127 | entities = raw["entities"] if isinstance(raw, dict) else raw |
121 | 128 | print(f"Record {row_idx}: {len(entities)} entities detected\n") |
122 | 129 |
|
|
132 | 139 |
|
133 | 140 | # %% |
134 | 141 | label_counts = Counter() |
135 | | -for raw in df["_detected_entities"]: |
| 142 | +for raw in final_entities: |
136 | 143 | entity_list = raw["entities"] if isinstance(raw, dict) else raw |
137 | 144 | for entity in entity_list: |
138 | 145 | label_counts[entity["label"]] += 1 |
|
152 | 159 |
|
153 | 160 | # %% |
154 | 161 | source_counts = Counter() |
155 | | -for raw in df["_detected_entities"]: |
| 162 | +for raw in final_entities: |
156 | 163 | entity_list = raw["entities"] if isinstance(raw, dict) else raw |
157 | 164 | for entity in entity_list: |
158 | 165 | source_counts[entity.get("source", "unknown")] += 1 |
|
168 | 175 |
|
169 | 176 | # %% |
170 | 177 | row_idx = 0 |
171 | | -raw_bv = df.loc[row_idx, "_entities_by_value"] |
| 178 | +raw_bv = trace_df.loc[row_idx, "_entities_by_value"] |
172 | 179 | by_value = raw_bv["entities_by_value"] if isinstance(raw_bv, dict) else raw_bv |
173 | 180 | print(f"Record {row_idx}: {len(by_value)} unique entity values\n") |
174 | 181 |
|
|
0 commit comments