Skip to content

Commit 021c84c

Browse files
committed
docs: update visualization tutorial
1 parent 125d90f commit 021c84c

File tree

4 files changed

+94
-49
lines changed

4 files changed

+94
-49
lines changed

docs/assets/stylesheets/extra.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,8 @@ body, input {
166166
.md-typeset code a:not(.md-annotation__index) {
167167
border-bottom: 1px dashed var(--md-typeset-a-color);
168168
}
169+
170+
.md-typeset .compact-table.md-typeset__table th, .md-typeset .compact-table.md-typeset__table td {
171+
min-width: initial !important;
172+
padding: .5em 0.75em;
173+
}

docs/tutorials/quick-examples.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

docs/tutorials/visualization.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Visualization
2+
3+
Let's see how to display the output of a pipeline on a single text.
4+
5+
```python
6+
import edsnlp, edsnlp.pipes as eds
7+
8+
nlp = edsnlp.blank("eds")
9+
nlp.add_pipe(eds.normalizer())
10+
nlp.add_pipe(eds.sentences())
11+
nlp.add_pipe(eds.covid())
12+
nlp.add_pipe(eds.negation())
13+
nlp.add_pipe(eds.hypothesis())
14+
nlp.add_pipe(eds.family())
15+
16+
txt = "Le patient a le covid."
17+
```
18+
19+
## Visualize entities in a document
20+
21+
To print a text and highlight the entities in it, you can use `spacy.displacy`.
22+
23+
```{ .python .no-check }
24+
from spacy import displacy
25+
26+
doc = nlp(txt)
27+
displacy.render(doc, style="ent")
28+
```
29+
30+
will render like this:
31+
32+
<center>
33+
<div class="entities" style="line-height: 2.5; direction: ltr">Le patient a le
34+
<mark class="entity" style="background: #ddd; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;">
35+
covid
36+
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">covid</span>
37+
</mark>
38+
.</div>
39+
</center>
40+
41+
## Visualize entities as a table
42+
43+
To quickly visualize the output of a pipeline on a document, including the annotated extensions/qualifiers, you can convert the output to a DataFrame and display it.
44+
45+
```{ .python .no-check }
46+
nlp.pipe([txt]).to_pandas(
47+
converter="ents",
48+
# Add any extension you want to display
49+
span_attributes=["negation", "hypothesis", "family"],
50+
# Shows the entities in doc.ents by default
51+
# span_getter=["ents"]
52+
)
53+
```
54+
55+
<div class="md-typeset">
56+
<div class="md-typeset__table compact-table">
57+
58+
<table>
59+
<thead>
60+
<tr style="text-align: right;">
61+
<th>note_id</th>
62+
<th>start</th>
63+
<th>end</th>
64+
<th>label</th>
65+
<th>lexical_variant</th>
66+
<th>span_type</th>
67+
<th>negation</th>
68+
<th>hypothesis</th>
69+
<th>family</th>
70+
</tr>
71+
</thead>
72+
<tbody>
73+
<tr>
74+
<td>None</td>
75+
<td>16</td>
76+
<td>21</td>
77+
<td>covid</td>
78+
<td>covid</td>
79+
<td>ents</td>
80+
<td>False</td>
81+
<td>False</td>
82+
<td>False</td>
83+
</tr>
84+
</tbody>
85+
</table>
86+
87+
</div>
88+
</div>

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ nav:
5353
- advanced-tutorials/fastapi.md
5454
- tutorials/training.md
5555
- tutorials/make-a-training-script.md
56-
- tutorials/quick-examples.md
56+
- tutorials/visualization.md
5757
- Pipes:
5858
- Overview: pipes/index.md
5959
- Core Pipelines:

0 commit comments

Comments
 (0)