{ "cells": [ { "cell_type": "markdown", "id": "20a04b0c-06cb-4f29-8381-a6a0d4a20ccd", "metadata": {}, "source": [ "# Wordcloud plots\n", "For text exploration, it might make sense to visualize texts as data points and interact with them." ] }, { "cell_type": "code", "execution_count": 1, "id": "8d301701-368f-4365-b555-dae6f06d8bea", "metadata": {}, "outputs": [], "source": [ "import stackview\n", "import pandas as pd" ] }, { "cell_type": "markdown", "id": "a991df41-86ab-4188-af47-e6e0cf6d7b32", "metadata": {}, "source": [ "Here we reuse a list of sentences and a [UMAP](https://umap-learn.readthedocs.io/en/latest/) produced from their text-embeddings. The sentences are taken from [Haase et al. 2022](https://arxiv.org/abs/2204.07547) which is licensed [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0)." ] }, { "cell_type": "code", "execution_count": 2, "id": "bb75ed7e-aa83-4015-a74b-8dfb9405ecf1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0sentenceUMAP0UMAP1
00A Hitchhiker’s Guide through the Bio-image Ana...-2.8632768.680281
11Modern research in the life sciences is unthin...-3.7312957.875060
22In the past decade, we observed a dramatic inc...-4.7486906.128065
33As it is increasingly difficult to keep track ...-4.1836926.847530
44We give guidance on which aspects to consider ...-4.9128326.691180
\n", "
" ], "text/plain": [ " Unnamed: 0 sentence UMAP0 \\\n", "0 0 A Hitchhiker’s Guide through the Bio-image Ana... -2.863276 \n", "1 1 Modern research in the life sciences is unthin... -3.731295 \n", "2 2 In the past decade, we observed a dramatic inc... -4.748690 \n", "3 3 As it is increasingly difficult to keep track ... -4.183692 \n", "4 4 We give guidance on which aspects to consider ... -4.912832 \n", "\n", " UMAP1 \n", "0 8.680281 \n", "1 7.875060 \n", "2 6.128065 \n", "3 6.847530 \n", "4 6.691180 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv(\"data/sentence_embeddings.csv\")\n", "df.head()" ] }, { "cell_type": "markdown", "id": "b5a69daa-2282-47d6-a020-cf3f8a5539fe", "metadata": {}, "source": [ "A word cloud plot is an interactive plot where you can select texts and from your selection, a wordcloud is generated." ] }, { "cell_type": "code", "execution_count": 3, "id": "99720165-0a6c-4c0a-8922-e6350b5a70f3", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b30463a9357f4846827c31acb06fc0bc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(HBox(children=(VBox(children=(VBox(children=(HBox(children=(VBox(children=(Image…" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.wordcloudplot(df, column_text=\"sentence\", column_x=\"UMAP0\", column_y=\"UMAP1\")" ] }, { "cell_type": "code", "execution_count": null, "id": "39c71ab5-43f3-4768-9e99-973905082950", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.10" } }, "nbformat": 4, "nbformat_minor": 5 }