Visualisations¶
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: str = None, cluster_label: str = None, include_centroids: bool = False, color: str = None, alias: 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: dict = None, anchor_index: Union[str, int] = 0, orientation: int = 'h', barmode: int = 'group', num_cols: 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[str, Any]], anchor_documents: List[Dict[str, Any]], vector_fields: Union[str, List[str]], label: str, mode: str = 'markers+text')¶ Plot cosine similarity with 2 anchor documents to compare with against other documents.
- Parameters
documents – list of documents (dictionaries) to feed in
vector_field – 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
- Returns
A scatterplot showing cosine similarity scores with each axes being a specific document.
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_2d_cosine_similarity(documents=documents[2:], anchor_documents=documents[:2], vector_fields=vector_field, label=label )
-
plot_radar_across_documents
(docs: List[Dict], anchor_documents: List[Dict], vector_field: str, label_field: str, range: List = [0, 1], fill: 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.
-