Visualization package for Spark NLP
Project description
spark-nlp-display
A library for the simple visualization of different types of Spark NLP annotations.
Supported Visualizations:
- Dependency Parser
- Named Entity Recognition
- Entity Resolution
- Relation Extraction
- Assertion Status
Complete Tutorial
https://github.com/JohnSnowLabs/spark-nlp-display/blob/main/tutorials/Spark_NLP_Display.ipynb
Requirements
- spark-nlp
- ipython
- svgwrite
- pandas
- numpy
Installation
pip install spark-nlp-display
How to use
Databricks
For all modules, pass in the additional parameter "return_html=True" in the display function and use Databrick's function displayHTML() to render visualization as explained below:
from sparknlp_display import NerVisualizer
ner_vis = NerVisualizer()
## To set custom label colors:
ner_vis.set_label_colors({'LOC':'#800080', 'PER':'#77b5fe'}) #set label colors by specifying hex codes
vis_html = ner_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe
label_col='entities', #specify the entity column
document_col='document', #specify the document column (default: 'document')
labels=['PER'], #only allow these labels to be displayed. (default: [] - all labels will be displayed)
return_html=True)
displayHTML(vis_html)
Jupyter
Dependency Parser
from sparknlp_display import DependencyParserVisualizer
dependency_vis = DependencyParserVisualizer()
dependency_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe.
pos_col = 'pos', #specify the pos column
dependency_col = 'dependency', #specify the dependency column
dependency_type_col = 'dependency_type' #specify the dependency type column
)
Named Entity Recognition
from sparknlp_display import NerVisualizer
ner_vis = NerVisualizer()
ner_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe
label_col='entities', #specify the entity column
document_col='document' #specify the document column (default: 'document')
labels=['PER'] #only allow these labels to be displayed. (default: [] - all labels will be displayed)
)
## To set custom label colors:
ner_vis.set_label_colors({'LOC':'#800080', 'PER':'#77b5fe'}) #set label colors by specifying hex codes
Entity Resolution
from sparknlp_display import EntityResolverVisualizer
er_vis = EntityResolverVisualizer()
er_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe
label_col='entities', #specify the ner result column
resolution_col = 'resolution'
document_col='document' #specify the document column (default: 'document')
)
## To set custom label colors:
er_vis.set_label_colors({'TREATMENT':'#800080', 'PROBLEM':'#77b5fe'}) #set label colors by specifying hex codes
Relation Extraction
from sparknlp_display import RelationExtractionVisualizer
re_vis = RelationExtractionVisualizer()
re_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe
relation_col = 'relations', #specify relations column
document_col = 'document', #specify document column
show_relations=True #display relation names on arrows (default: True)
)
Assertion Status
from sparknlp_display import AssertionVisualizer
assertion_vis = AssertionVisualizer()
assertion_vis.display(pipeline_result[0],
label_col = 'entities', #specify the ner result column
assertion_col = 'assertion' #specify assertion column
document_col = 'document' #specify the document column (default: 'document')
)
## To set custom label colors:
assertion_vis.set_label_colors({'TREATMENT':'#008080', 'problem':'#800080'}) #set label colors by specifying hex codes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
spark-nlp-display-1.5.tar.gz
(79.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spark-nlp-display-1.5.tar.gz.
File metadata
- Download URL: spark-nlp-display-1.5.tar.gz
- Upload date:
- Size: 79.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c8fefae7462a7239c2beca125b29a5fee9146d9da91732d0010db7ad55a416
|
|
| MD5 |
cab2834e05bd5613bd5cd202df2bb4a2
|
|
| BLAKE2b-256 |
6cadbe29538b534d85258d5491a537a0d8c64db9744bb3c2c8de538d32bcb52e
|
File details
Details for the file spark_nlp_display-1.5-py3-none-any.whl.
File metadata
- Download URL: spark_nlp_display-1.5-py3-none-any.whl
- Upload date:
- Size: 94.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ddb8626adcdf9a254ca220e50e8ca5940a15faed6626552f6aeef134641dbb0
|
|
| MD5 |
20918a78b388a644b31ce6c1fa2ea1cb
|
|
| BLAKE2b-256 |
cf6ae822cccbbc480e7140128836fda52bf56d131adc4f7f83ee1dd71afe7797
|