# 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
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-display/blob/main/tutorials/Spark_NLP_Display.ipynb)
https://github.com/JohnSnowLabs/spark-nlp-display/blob/main/tutorials/Spark_NLP_Display.ipynb
### Requirements
- spark-nlp
- ipython
- svgwrite
- pandas
- numpy
### Installation
```bash
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:
```python
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
pipeline_result = ner_light_pipeline.fullAnnotate(text) ##light pipeline
#pipeline_result = ner_full_pipeline.transform(df).collect()##full pipeline
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)
```
![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/ner_viz.png)
### Jupyter
To save the visualization as html, provide the export file path: `save_path='./export.html'` for each visualizer.
#### Dependency Parser
```python
from sparknlp_display import DependencyParserVisualizer
dependency_vis = DependencyParserVisualizer()
pipeline_result = dp_pipeline.fullAnnotate(text)
#pipeline_result = dp_full_pipeline.transform(df).collect()##full pipeline
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
save_path='./export.html' # optional - to save viz as html. (default: None)
)
```
![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/dp_viz.png)
#### Named Entity Recognition
```python
from sparknlp_display import NerVisualizer
ner_vis = NerVisualizer()
pipeline_result = ner_light_pipeline.fullAnnotate(text)
#pipeline_result = ner_full_pipeline.transform(df).collect()##full pipeline
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)
save_path='./export.html' # optional - to save viz as html. (default: None)
)
## To set custom label colors:
ner_vis.set_label_colors({'LOC':'#800080', 'PER':'#77b5fe'}) #set label colors by specifying hex codes
```
![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/ner_viz.png)
#### Entity Resolution
```python
from sparknlp_display import EntityResolverVisualizer
er_vis = EntityResolverVisualizer()
pipeline_result = er_light_pipeline.fullAnnotate(text)
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')
save_path='./export.html' # optional - to save viz as html. (default: None)
)
## To set custom label colors:
er_vis.set_label_colors({'TREATMENT':'#800080', 'PROBLEM':'#77b5fe'}) #set label colors by specifying hex codes
```
![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/er_viz.png)
#### Relation Extraction
```python
from sparknlp_display import RelationExtractionVisualizer
re_vis = RelationExtractionVisualizer()
pipeline_result = re_light_pipeline.fullAnnotate(text)
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)
save_path='./export.html' # optional - to save viz as html. (default: None)
)
```
![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/re_viz.png)
#### Assertion Status
```python
from sparknlp_display import AssertionVisualizer
assertion_vis = AssertionVisualizer()
pipeline_result = ner_assertion_light_pipeline.fullAnnotate(text)
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')
save_path='./export.html' # optional - to save viz as html. (default: None)
)
## To set custom label colors:
assertion_vis.set_label_colors({'TREATMENT':'#008080', 'problem':'#800080'}) #set label colors by specifying hex codes
```
![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/assertion_viz.png)
Raw data
{
"_id": null,
"home_page": "http://nlp.johnsnowlabs.com",
"name": "spark-nlp-display",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7",
"maintainer_email": "",
"keywords": "",
"author": "John Snow Labs",
"author_email": "john@johnsnowlabs.com",
"download_url": "https://files.pythonhosted.org/packages/94/45/c5b0fa0b31675946a13859fd2bad8a6816bdb08f30e64d8379820e67e409/spark-nlp-display-5.0.tar.gz",
"platform": null,
"description": "# spark-nlp-display\nA library for the simple visualization of different types of Spark NLP annotations. \n\n## Supported Visualizations:\n- Dependency Parser\n- Named Entity Recognition\n- Entity Resolution\n- Relation Extraction\n- Assertion Status\n\n## Complete Tutorial\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-display/blob/main/tutorials/Spark_NLP_Display.ipynb)\n\nhttps://github.com/JohnSnowLabs/spark-nlp-display/blob/main/tutorials/Spark_NLP_Display.ipynb\n\n### Requirements\n- spark-nlp\n- ipython\n- svgwrite\n- pandas\n- numpy\n\n### Installation\n```bash\npip install spark-nlp-display\n```\n\n### How to use\n\n### Databricks\n#### 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:\n```python\nfrom sparknlp_display import NerVisualizer\n\nner_vis = NerVisualizer()\n\n## To set custom label colors:\nner_vis.set_label_colors({'LOC':'#800080', 'PER':'#77b5fe'}) #set label colors by specifying hex codes\n\npipeline_result = ner_light_pipeline.fullAnnotate(text) ##light pipeline\n#pipeline_result = ner_full_pipeline.transform(df).collect()##full pipeline\n\nvis_html = ner_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe\n label_col='entities', #specify the entity column\n document_col='document', #specify the document column (default: 'document')\n labels=['PER'], #only allow these labels to be displayed. (default: [] - all labels will be displayed)\n return_html=True)\n\ndisplayHTML(vis_html)\n```\n![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/ner_viz.png)\n\n### Jupyter\n\nTo save the visualization as html, provide the export file path: `save_path='./export.html'` for each visualizer.\n\n\n#### Dependency Parser\n```python\nfrom sparknlp_display import DependencyParserVisualizer\n\ndependency_vis = DependencyParserVisualizer()\n\npipeline_result = dp_pipeline.fullAnnotate(text)\n#pipeline_result = dp_full_pipeline.transform(df).collect()##full pipeline\n\ndependency_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe.\n pos_col = 'pos', #specify the pos column\n dependency_col = 'dependency', #specify the dependency column\n dependency_type_col = 'dependency_type', #specify the dependency type column\n save_path='./export.html' # optional - to save viz as html. (default: None)\n )\n```\n\n![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/dp_viz.png)\n\n#### Named Entity Recognition\n\n```python\nfrom sparknlp_display import NerVisualizer\n\nner_vis = NerVisualizer()\n\npipeline_result = ner_light_pipeline.fullAnnotate(text)\n#pipeline_result = ner_full_pipeline.transform(df).collect()##full pipeline\n\nner_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe\n label_col='entities', #specify the entity column\n document_col='document', #specify the document column (default: 'document')\n labels=['PER'], #only allow these labels to be displayed. (default: [] - all labels will be displayed)\n save_path='./export.html' # optional - to save viz as html. (default: None)\n )\n\n## To set custom label colors:\nner_vis.set_label_colors({'LOC':'#800080', 'PER':'#77b5fe'}) #set label colors by specifying hex codes\n\n```\n\n![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/ner_viz.png)\n\n#### Entity Resolution\n\n```python\nfrom sparknlp_display import EntityResolverVisualizer\n\ner_vis = EntityResolverVisualizer()\n\npipeline_result = er_light_pipeline.fullAnnotate(text)\n\ner_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe\n label_col='entities', #specify the ner result column\n resolution_col = 'resolution',\n document_col='document', #specify the document column (default: 'document')\n save_path='./export.html' # optional - to save viz as html. (default: None)\n )\n\n## To set custom label colors:\ner_vis.set_label_colors({'TREATMENT':'#800080', 'PROBLEM':'#77b5fe'}) #set label colors by specifying hex codes\n\n```\n\n![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/er_viz.png)\n\n#### Relation Extraction\n```python\nfrom sparknlp_display import RelationExtractionVisualizer\n\nre_vis = RelationExtractionVisualizer()\n\npipeline_result = re_light_pipeline.fullAnnotate(text)\n\nre_vis.display(pipeline_result[0], #should be the results of a single example, not the complete dataframe\n relation_col = 'relations', #specify relations column\n document_col = 'document', #specify document column\n show_relations=True, #display relation names on arrows (default: True)\n save_path='./export.html' # optional - to save viz as html. (default: None)\n )\n\n```\n\n![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/re_viz.png)\n\n#### Assertion Status\n```python\nfrom sparknlp_display import AssertionVisualizer\n\nassertion_vis = AssertionVisualizer()\n\npipeline_result = ner_assertion_light_pipeline.fullAnnotate(text)\n\nassertion_vis.display(pipeline_result[0], \n label_col = 'entities', #specify the ner result column\n assertion_col = 'assertion', #specify assertion column\n document_col = 'document', #specify the document column (default: 'document')\n save_path='./export.html' # optional - to save viz as html. (default: None)\n )\n \n## To set custom label colors:\nassertion_vis.set_label_colors({'TREATMENT':'#008080', 'problem':'#800080'}) #set label colors by specifying hex codes\n\n```\n\n![title](https://raw.githubusercontent.com/JohnSnowLabs/spark-nlp-display/main/assets/assertion_viz.png)\n",
"bugtrack_url": null,
"license": "",
"summary": "Visualization package for Spark NLP",
"version": "5.0",
"project_urls": {
"Homepage": "http://nlp.johnsnowlabs.com"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "401e41eb41a6c69df8cb6a2906d7f44672118834af10cdb5b8f0f360e82ac988",
"md5": "28ac92b19ddfff122e3a21d0db9b2b1b",
"sha256": "ede785f68cd4299d4a93e389d26be90eeb0e24372de99d30b107ad19464c87e0"
},
"downloads": -1,
"filename": "spark_nlp_display-5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "28ac92b19ddfff122e3a21d0db9b2b1b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=2.7",
"size": 95601,
"upload_time": "2023-08-29T19:11:58",
"upload_time_iso_8601": "2023-08-29T19:11:58.315305Z",
"url": "https://files.pythonhosted.org/packages/40/1e/41eb41a6c69df8cb6a2906d7f44672118834af10cdb5b8f0f360e82ac988/spark_nlp_display-5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9445c5b0fa0b31675946a13859fd2bad8a6816bdb08f30e64d8379820e67e409",
"md5": "c9951302ea8858ac8a19e46692cacd90",
"sha256": "46faa77553d3eb3fc968eb434303752f7baf39b39b03f17cd0934466b6a86620"
},
"downloads": -1,
"filename": "spark-nlp-display-5.0.tar.gz",
"has_sig": false,
"md5_digest": "c9951302ea8858ac8a19e46692cacd90",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7",
"size": 85472,
"upload_time": "2023-08-29T19:11:59",
"upload_time_iso_8601": "2023-08-29T19:11:59.993525Z",
"url": "https://files.pythonhosted.org/packages/94/45/c5b0fa0b31675946a13859fd2bad8a6816bdb08f30e64d8379820e67e409/spark-nlp-display-5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-29 19:11:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "spark-nlp-display"
}