|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "20a04b0c-06cb-4f29-8381-a6a0d4a20ccd", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Wordcloud plots\n", |
| 9 | + "For text exploration, it might make sense to visualize texts as data points and interact with them." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 1, |
| 15 | + "id": "8d301701-368f-4365-b555-dae6f06d8bea", |
| 16 | + "metadata": {}, |
| 17 | + "outputs": [], |
| 18 | + "source": [ |
| 19 | + "import stackview\n", |
| 20 | + "import pandas as pd" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "markdown", |
| 25 | + "id": "a991df41-86ab-4188-af47-e6e0cf6d7b32", |
| 26 | + "metadata": {}, |
| 27 | + "source": [ |
| 28 | + "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)." |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": 2, |
| 34 | + "id": "bb75ed7e-aa83-4015-a74b-8dfb9405ecf1", |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [ |
| 37 | + { |
| 38 | + "data": { |
| 39 | + "text/html": [ |
| 40 | + "<div>\n", |
| 41 | + "<style scoped>\n", |
| 42 | + " .dataframe tbody tr th:only-of-type {\n", |
| 43 | + " vertical-align: middle;\n", |
| 44 | + " }\n", |
| 45 | + "\n", |
| 46 | + " .dataframe tbody tr th {\n", |
| 47 | + " vertical-align: top;\n", |
| 48 | + " }\n", |
| 49 | + "\n", |
| 50 | + " .dataframe thead th {\n", |
| 51 | + " text-align: right;\n", |
| 52 | + " }\n", |
| 53 | + "</style>\n", |
| 54 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 55 | + " <thead>\n", |
| 56 | + " <tr style=\"text-align: right;\">\n", |
| 57 | + " <th></th>\n", |
| 58 | + " <th>Unnamed: 0</th>\n", |
| 59 | + " <th>sentence</th>\n", |
| 60 | + " <th>UMAP0</th>\n", |
| 61 | + " <th>UMAP1</th>\n", |
| 62 | + " </tr>\n", |
| 63 | + " </thead>\n", |
| 64 | + " <tbody>\n", |
| 65 | + " <tr>\n", |
| 66 | + " <th>0</th>\n", |
| 67 | + " <td>0</td>\n", |
| 68 | + " <td>A Hitchhiker’s Guide through the Bio-image Ana...</td>\n", |
| 69 | + " <td>-2.863276</td>\n", |
| 70 | + " <td>8.680281</td>\n", |
| 71 | + " </tr>\n", |
| 72 | + " <tr>\n", |
| 73 | + " <th>1</th>\n", |
| 74 | + " <td>1</td>\n", |
| 75 | + " <td>Modern research in the life sciences is unthin...</td>\n", |
| 76 | + " <td>-3.731295</td>\n", |
| 77 | + " <td>7.875060</td>\n", |
| 78 | + " </tr>\n", |
| 79 | + " <tr>\n", |
| 80 | + " <th>2</th>\n", |
| 81 | + " <td>2</td>\n", |
| 82 | + " <td>In the past decade, we observed a dramatic inc...</td>\n", |
| 83 | + " <td>-4.748690</td>\n", |
| 84 | + " <td>6.128065</td>\n", |
| 85 | + " </tr>\n", |
| 86 | + " <tr>\n", |
| 87 | + " <th>3</th>\n", |
| 88 | + " <td>3</td>\n", |
| 89 | + " <td>As it is increasingly difficult to keep track ...</td>\n", |
| 90 | + " <td>-4.183692</td>\n", |
| 91 | + " <td>6.847530</td>\n", |
| 92 | + " </tr>\n", |
| 93 | + " <tr>\n", |
| 94 | + " <th>4</th>\n", |
| 95 | + " <td>4</td>\n", |
| 96 | + " <td>We give guidance on which aspects to consider ...</td>\n", |
| 97 | + " <td>-4.912832</td>\n", |
| 98 | + " <td>6.691180</td>\n", |
| 99 | + " </tr>\n", |
| 100 | + " </tbody>\n", |
| 101 | + "</table>\n", |
| 102 | + "</div>" |
| 103 | + ], |
| 104 | + "text/plain": [ |
| 105 | + " Unnamed: 0 sentence UMAP0 \\\n", |
| 106 | + "0 0 A Hitchhiker’s Guide through the Bio-image Ana... -2.863276 \n", |
| 107 | + "1 1 Modern research in the life sciences is unthin... -3.731295 \n", |
| 108 | + "2 2 In the past decade, we observed a dramatic inc... -4.748690 \n", |
| 109 | + "3 3 As it is increasingly difficult to keep track ... -4.183692 \n", |
| 110 | + "4 4 We give guidance on which aspects to consider ... -4.912832 \n", |
| 111 | + "\n", |
| 112 | + " UMAP1 \n", |
| 113 | + "0 8.680281 \n", |
| 114 | + "1 7.875060 \n", |
| 115 | + "2 6.128065 \n", |
| 116 | + "3 6.847530 \n", |
| 117 | + "4 6.691180 " |
| 118 | + ] |
| 119 | + }, |
| 120 | + "execution_count": 2, |
| 121 | + "metadata": {}, |
| 122 | + "output_type": "execute_result" |
| 123 | + } |
| 124 | + ], |
| 125 | + "source": [ |
| 126 | + "df = pd.read_csv(\"data/sentence_embeddings.csv\")\n", |
| 127 | + "df.head()" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "markdown", |
| 132 | + "id": "b5a69daa-2282-47d6-a020-cf3f8a5539fe", |
| 133 | + "metadata": {}, |
| 134 | + "source": [ |
| 135 | + "A word cloud plot is an interactive plot where you can select texts and from your selection, a wordcloud is generated." |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "code", |
| 140 | + "execution_count": 3, |
| 141 | + "id": "99720165-0a6c-4c0a-8922-e6350b5a70f3", |
| 142 | + "metadata": {}, |
| 143 | + "outputs": [ |
| 144 | + { |
| 145 | + "data": { |
| 146 | + "application/vnd.jupyter.widget-view+json": { |
| 147 | + "model_id": "b30463a9357f4846827c31acb06fc0bc", |
| 148 | + "version_major": 2, |
| 149 | + "version_minor": 0 |
| 150 | + }, |
| 151 | + "text/plain": [ |
| 152 | + "VBox(children=(HBox(children=(HBox(children=(VBox(children=(VBox(children=(HBox(children=(VBox(children=(Image…" |
| 153 | + ] |
| 154 | + }, |
| 155 | + "execution_count": 3, |
| 156 | + "metadata": {}, |
| 157 | + "output_type": "execute_result" |
| 158 | + } |
| 159 | + ], |
| 160 | + "source": [ |
| 161 | + "stackview.wordcloudplot(df, column_text=\"sentence\", column_x=\"UMAP0\", column_y=\"UMAP1\")" |
| 162 | + ] |
| 163 | + }, |
| 164 | + { |
| 165 | + "cell_type": "code", |
| 166 | + "execution_count": null, |
| 167 | + "id": "39c71ab5-43f3-4768-9e99-973905082950", |
| 168 | + "metadata": {}, |
| 169 | + "outputs": [], |
| 170 | + "source": [] |
| 171 | + } |
| 172 | + ], |
| 173 | + "metadata": { |
| 174 | + "kernelspec": { |
| 175 | + "display_name": "Python 3 (ipykernel)", |
| 176 | + "language": "python", |
| 177 | + "name": "python3" |
| 178 | + }, |
| 179 | + "language_info": { |
| 180 | + "codemirror_mode": { |
| 181 | + "name": "ipython", |
| 182 | + "version": 3 |
| 183 | + }, |
| 184 | + "file_extension": ".py", |
| 185 | + "mimetype": "text/x-python", |
| 186 | + "name": "python", |
| 187 | + "nbconvert_exporter": "python", |
| 188 | + "pygments_lexer": "ipython3", |
| 189 | + "version": "3.11.10" |
| 190 | + } |
| 191 | + }, |
| 192 | + "nbformat": 4, |
| 193 | + "nbformat_minor": 5 |
| 194 | +} |
0 commit comments