Visualizers#

asent.visualize#

asent.visualize.visualize(doc: Union[Span, Doc, DocPolarityOutput, SpanPolarityOutput], style: Literal['prediction', 'analysis', 'prediction-no-overlap', 'sentence-prediction'] = 'prediction', cmap: str = 'RdYlGn') str[source]#

Render displaCy visualisation of model prediction of sentiment or analysis of sentiment.

Parameters:
  • doc – The span or document you wish to apply the visualizer to.

  • style

    A string indicating whether it should visualize “prediction” or “analysis”.

    • ”prediction”, color codes positive or negative spans according to the cmap.

    • ”analysis” visualize for each sentimental word whether it has been negated or intensified by a word, and which words.

      it also shows the valence of each word, both raw and taking into account negation and intensification.

    • ”sentence-prediction”, same as “prediction” but for each sentence instead of per. word.

    If you are looking for the previous visualizer for “prediction”, use “prediction-no-overlap”. Note that this does not allow for overlapping spans and thus it can lead to odd results.

  • cmap – The color map derived from matplotlib.

Returns:

Rendered HTML markup.

Examples

>>> nlp = spacy.load("en_core_web_lg")
>>> # add the rule-based sentiment model
>>> nlp.add_pipe("asent_en_v1")
>>> # try an example
>>> text = "I am not very happy"
>>> doc = nlp(text)
>>> # visualize model prediction
>>> asent.visualize(doc, style="prediction")
>>> asent.visualize(doc, style="analysis")
asent.visualize.visualize_sentence_prediction(document_obj: Union[Span, Doc, DocPolarityOutput, SpanPolarityOutput], cmap: str = 'RdYlGn') str[source]#

Render displaCy visualisation of model prediction of sentiment.

Parameters:
  • document_obj – The span or document you wish to apply the visualizer to.

  • cmap – The color map derived from matplotlib.

Returns:

Rendered HTML markup.