Visualisations — vectorai 0.1.0 documentation

# Visualisations

Visualisations

Plotting functions of Vi go here.

class vectorai.analytics.viz.VizMixin(username: str, api_key: str, url: str = 'https://api.vctr.ai')

  Visualisation submodule for the library.

  plot_dimensionality_reduced_vectors(collection: Union[str, List[Dict]], point_label: str, dim_reduction_field: str, cluster_field: Optional[str] = None, cluster_label: Optional[str] = None, include_centroids: bool = False, color: Optional[str] = None, alias: Optional[str] = None, mode: str = 'markers')

    Returns a 2D plot of vectors that have been dimensionally reduced.

    Parameters

      - collection – A collection or the name of a collection

      - point_label – The label of every point. This should be found in the document.

      - dim_reduction_field – The dimensionally-reduced vectors.

      - cluster_field – The field by which it is clustered.

      - cluster_label – The name of the clusters

      - include_centroids – Whether to include the centroids of every cluster

    Returns

      Plotly figure object

    See example from: https://colab.research.google.com/drive/10u7b3lkIVJ-lceCmr34ywscOGueIFd0I?usp=sharing

    Example

        >>> collection_name = 'nlp-qa'
        >>> cluster_field = 'question_vector_'
        >>> cluster_label = 'category'
        >>> alias = '1st_cluster'
        >>> dim_reduction_field = '_dr_.default.2.question_vectors_' # the '.' in names implies nested dictionaries in Vi
        >>> vi_client.plot_dimensionality_reduced_vectors(collection=collection_name,
                cluster_field=cluster_field,
                cluster_label=cluster_label,
                point_label='question_title',
                dim_reduction_field=dim_reduction_field,
                include_centroids=True,
                alias=alias)

  plot_1d_cosine_similarity(documents: list, vector_fields: List[str], label: str, anchor_document: Optional[dict] = None, anchor_index: Union[str, int] = 0, orientation: int = 'h', barmode: int = 'group', num_cols: Optional[int] = None, y_axis_tickangle: int = - 15, x_axis_tickangle: int = 15)

    Compare 1 document against other documents. Ensure that the name is unique, otherwise the plot will simply take the mean.

    Parameters

      - documents – list of documents (dictionaries) to feed in

      - vector_fields – vector field to calculate cosine similarity on

      - label – the x label for the bar plot

      - anchor_document – the document to compare it on

      - anchor_index – the anchor index to compare it on

      - orientation – The orientation of the bar chart. Can be ‘v’ (vertical) or ‘h’ (horizontal)

      - num_cols – The number of columns. The default will put everything into 1 row. If you want to

      - things into multiple rows (put) –

      - please reduce the number of columns. (then) –

      - y_axis_tickangle – This will change the tick angles of the y axis in the vertical chart.

      - x_axis_tickangle – This will change the tick angels of the x axis in the vertical chart.

    Returns

      returns a horizontal barplot showing cosine similarity scores.

    Return type

      Plotly Figure

    Example

        >>> cluster_field = 'question_vector_'
        >>> cluster_label = 'category'
        >>> alias = '1st_cluster'
        >>> dim_reduction_field = '_dr_.default.2.question_vectors_' # the '.' in names implies nested dictionaries in Vi
        >>> vi_client.plot_1d_cosine_similarity(collection=collection_name,
                cluster_field=cluster_field,
                cluster_label=cluster_label,
                point_label='question_title',
                dim_reduction_field=dim_reduction_field,
                include_centroids=True,
                alias=alias)

  plot_2d_cosine_similarity(documents: List[Dict], anchor_documents: List[Dict], vector_fields: List[str], label: str, mode='markers+text', textposition='top center', show_spikes=True, text_label_font_size: int = 12, text_label_font_family='Rockwell', text_label_bgcolor='white', marker_colors=['purple', 'aquamarine'], metric='cosine', plot_bgcolor='#e6e6fa', spikedash='dot', spikethickness=1.5)

    Plotting 2D cosine similarity plots :param documents: The documents to :param anchor_documents: Documents by which to compare against :param vector_fields: The list of vectors to accept :param Label: The document field to label :param Mode: Whether to include markers or text (view Plotly documentation for more information) :param textposition: where the text labels should be in relation to the marker :param show_spikes: show the spikes in comparison to the x and y labels :param text_label_font_family: The font of the text :param text_label_font_size: The font size of the text :param marker_colors: The color of the markers If the number of colors do not :param match then we it randomly generates.: :param metric: The metric to use. Currently only supports cosine similarity :param plot_bgcolor: The background color of the plot :param spikethickness: The thickness of the spikes :param spikedash: Type of line the spikes should be.

    Example

        >>> vi_client = ViClient()
        >>> collection_name = 'ecommerce'
        >>> docs = vi_client.random_documents(collection_name)['documents']
        >>> vi_client.plot_2d_cosine_similarity(docs, docs[0:2],
        vector_fields=['use_vector_'], label='name')

  plot_radar_across_documents(docs: List[Dict], anchor_documents: List[Dict], vector_field: str, label_field: str, range: List = [0, 1], fill: Optional[str] = None, scoring_metric='cosine')

    Radar plot for 1D cosine similarity across documents. :param docs: A list of documents :param anchor_document: The document to compare against :param vector_field: The vector vector field :param label_field: The field of the documents to get labels.

  plot_radar_across_vector_fields(docs: List[Dict], anchor_document: Dict, vector_fields: List[str], label_field: str, range=[0, 1], fill=None, scoring_metric='cosine')

    Radar plot for 1D cosine similarity across different vector spaces. :param docs: A list of documents :param anchor_document: The document to compare against :param vector_fields: the different vector fields :param label_field: The field of the documents to get labels.