Alvant commited on
Commit
07cb357
1 Parent(s): c81a939

add preproc notebooks

Browse files
preprocessing/MKB-generate-triplets.ipynb ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from topicnet.cooking_machine import Dataset\n",
10
+ "import pandas as pd\n",
11
+ "\n",
12
+ "dataset = Dataset('MKB10.csv', batch_vectorizer_path=\"./mkb_batches2\")\n",
13
+ "\n",
14
+ "data_orig = pd.read_pickle(\"MKB10.pkl\")\n"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 19,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "data_orig.title = data_orig.title.str.replace(\" \", \"_\")\n"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": 5,
29
+ "metadata": {},
30
+ "outputs": [
31
+ {
32
+ "data": {
33
+ "text/plain": [
34
+ "{'@letter', '@ngram', '@text'}"
35
+ ]
36
+ },
37
+ "execution_count": 5,
38
+ "metadata": {},
39
+ "output_type": "execute_result"
40
+ }
41
+ ],
42
+ "source": [
43
+ "dataset.get_possible_modalities()"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": null,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 6,
56
+ "metadata": {},
57
+ "outputs": [],
58
+ "source": [
59
+ "\n",
60
+ "import numpy as np\n",
61
+ "\n",
62
+ "# all articles are from category \"Симптомы по алфавиту\", so threshold is 1\n",
63
+ "THRESHOLD = 1\n",
64
+ "\n",
65
+ "def randomly_select(data_orig, point_a, should_intersect):\n",
66
+ " attempts_left = 100\n",
67
+ " while attempts_left > 0:\n",
68
+ " rnd_idx_b = np.random.choice(data_orig.shape[0])\n",
69
+ " point_b = data_orig.iloc[rnd_idx_b]\n",
70
+ " intersection = set(point_b.categories) & set(point_a.categories)\n",
71
+ " is_big = (len(intersection) > THRESHOLD)\n",
72
+ " if should_intersect == is_big:\n",
73
+ " # if is_big:\n",
74
+ " # print(point_a.title, point_b.title, intersection)\n",
75
+ " return point_b.title, rnd_idx_b, intersection\n",
76
+ " attempts_left -= 1\n",
77
+ " return None, None, None\n",
78
+ "\n",
79
+ "def generate_triplet(data_orig):\n",
80
+ "\n",
81
+ " rnd_idx_a = np.random.choice(data_orig.shape[0])\n",
82
+ " point_a = data_orig.iloc[rnd_idx_a]\n",
83
+ " point_b, rnd_idx_b, intersection = randomly_select(data_orig, point_a, should_intersect=True)\n",
84
+ " point_c, rnd_idx_c, empty_intersection = randomly_select(data_orig, point_a, should_intersect=False)\n",
85
+ " # return [point_a, point_b, point_c]\n",
86
+ " return [point_a.title, point_b, point_c, intersection]\n",
87
+ " # return [rnd_idx_a, rnd_idx_b, rnd_idx_c]\n",
88
+ "\n",
89
+ " \n",
90
+ " "
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 21,
96
+ "metadata": {},
97
+ "outputs": [
98
+ {
99
+ "name": "stderr",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "100%|██████████| 10000/10000 [00:57<00:00, 173.50it/s]\n"
103
+ ]
104
+ },
105
+ {
106
+ "data": {
107
+ "text/plain": [
108
+ "7221"
109
+ ]
110
+ },
111
+ "execution_count": 21,
112
+ "metadata": {},
113
+ "output_type": "execute_result"
114
+ }
115
+ ],
116
+ "source": [
117
+ "from tqdm import tqdm\n",
118
+ "\n",
119
+ "triplets = []\n",
120
+ "\n",
121
+ "for i in tqdm(range(10000)):\n",
122
+ " a, b, c, explanation = generate_triplet(data_orig)\n",
123
+ " if b is not None and c is not None:\n",
124
+ " triplets.append( (a, b, c, explanation) )\n",
125
+ "\n",
126
+ "len(triplets)"
127
+ ]
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "execution_count": null,
132
+ "metadata": {},
133
+ "outputs": [],
134
+ "source": []
135
+ },
136
+ {
137
+ "cell_type": "code",
138
+ "execution_count": 22,
139
+ "metadata": {},
140
+ "outputs": [],
141
+ "source": [
142
+ "import pickle\n",
143
+ "\n",
144
+ "with open(\"triplets_mkb.p\", \"wb\") as f:\n",
145
+ " pickle.dump(triplets, f)\n"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": null,
151
+ "metadata": {},
152
+ "outputs": [],
153
+ "source": []
154
+ },
155
+ {
156
+ "cell_type": "markdown",
157
+ "metadata": {},
158
+ "source": [
159
+ "## Scoring model by ranking quality"
160
+ ]
161
+ },
162
+ {
163
+ "cell_type": "code",
164
+ "execution_count": 23,
165
+ "metadata": {},
166
+ "outputs": [],
167
+ "source": [
168
+ "from topicnet.cooking_machine.models import BaseScore as BaseTopicNetScore, TopicModel\n",
169
+ "\n",
170
+ "\n",
171
+ "class ValidationRankingQuality(BaseTopicNetScore):\n",
172
+ " def __init__(self, validation_dataset, triplets):\n",
173
+ " super().__init__()\n",
174
+ "\n",
175
+ " self.validation_dataset = validation_dataset\n",
176
+ " self.triplets = triplets\n",
177
+ "\n",
178
+ " def call(self, model: TopicModel):\n",
179
+ " theta = model.get_theta(dataset=self.validation_dataset)\n",
180
+ " \n",
181
+ " correct_rankings = 0\n",
182
+ "\n",
183
+ " for (a, b, c, _) in self.triplets:\n",
184
+ " # L1 distance, just for example\n",
185
+ " similar_dist = sum(abs(theta[a] - theta[b]))\n",
186
+ " diffrnt_dist = sum(abs(theta[a] - theta[c]))\n",
187
+ "\n",
188
+ " correct_rankings += (similar_dist < diffrnt_dist)\n",
189
+ "\n",
190
+ " return correct_rankings / len(self.triplets)\n",
191
+ "\n",
192
+ " "
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "execution_count": 24,
198
+ "metadata": {},
199
+ "outputs": [],
200
+ "source": [
201
+ "import artm\n",
202
+ "\n",
203
+ "artm_model = artm.ARTM(\n",
204
+ " num_topics=20, \n",
205
+ " dictionary=dataset.get_dictionary(),\n",
206
+ " class_ids={'@lemmatized': 1, '@ngram': 50}, # absolute values, just for example\n",
207
+ " theta_columns_naming=\"title\"\n",
208
+ ")\n",
209
+ "\n"
210
+ ]
211
+ },
212
+ {
213
+ "cell_type": "code",
214
+ "execution_count": 25,
215
+ "metadata": {},
216
+ "outputs": [],
217
+ "source": [
218
+ "tm = TopicModel(artm_model, custom_scores={\"ranking\": ValidationRankingQuality(dataset, triplets)})"
219
+ ]
220
+ },
221
+ {
222
+ "cell_type": "code",
223
+ "execution_count": 26,
224
+ "metadata": {
225
+ "scrolled": true
226
+ },
227
+ "outputs": [],
228
+ "source": [
229
+ "tm._fit(dataset.get_batch_vectorizer(), 10)"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "execution_count": null,
235
+ "metadata": {},
236
+ "outputs": [],
237
+ "source": []
238
+ },
239
+ {
240
+ "cell_type": "code",
241
+ "execution_count": 27,
242
+ "metadata": {},
243
+ "outputs": [
244
+ {
245
+ "name": "stdout",
246
+ "output_type": "stream",
247
+ "text": [
248
+ "0.641600886303836\n"
249
+ ]
250
+ },
251
+ {
252
+ "data": {
253
+ "text/plain": [
254
+ "[<matplotlib.lines.Line2D at 0x7f133d31e8d0>]"
255
+ ]
256
+ },
257
+ "execution_count": 27,
258
+ "metadata": {},
259
+ "output_type": "execute_result"
260
+ },
261
+ {
262
+ "data": {
263
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXzV9Z3v8debhATCDgmIgLIYVFTUGlcURYtF2+LMdMal01Y7U5eZsfa2nc7V3rmtpbP1Tmc607ncadGx7bQu7Wir2FJxGevWqgRFkSCKQSCsYQ9bQpLP/eOcwCEEcwIJv+Sc9/PxOA/Ob83nHM37/PI9v+/3q4jAzMxyV6+kCzAzs67loDczy3EOejOzHOegNzPLcQ56M7McV5h0Aa2VlpbG2LFjky7DzKxHWbhw4aaIKGtrW7cL+rFjx1JZWZl0GWZmPYqklYfb5qYbM7Mc56A3M8txDnozsxznoDczy3EOejOzHOegNzPLcQ56M7Mc1+3uozczy3X7mprZsquB2rp6anfWs6munk07GxjUtzefPP+ETv95Dnozs07Q0NjM5l31bKprYNPOdIDvrKc2HeKpME89tu7e1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nAmefy+SBoF3AFURMTppAZuvD7ZqjpfTgQ9GdMdRkQD0DLdYV6KiHUR8Vr6eR2pX+S2ZgXLC5JGAx8F7k26lqRJGghMBf4DICIaImJbslUlrhDoK6kQKKHVfBu5IFeCPtvpDvOOpLHA2cAryVaSqH8B/ooumpi+hxkP1AI/SDdl3SupX9JFJSUi1gDfBlYB64DtEfFkslV1vlwJ+mymO8w7kvoDjwD/IyJ2JF1PEiR9DNgYEQuTrqWbKCQ1y9u/R8TZwC4gb7/TkjSE1F//44DjgX6SPpVsVZ0vV4K+3ekO842k3qRC/v6I+HnS9SRoCjBT0vukmvQul/STZEtKVA1QExEtf+E9TH5P7/lhYEVE1EbEPuDnwEUJ19TpciXo253uMJ+kZ/P6D2BpRPxz0vUkKSLuiojRETGW1P8X/x0ROXfFlq2IWA+slnRyetUV5Pf0nquACySVpH9vriAHv5xudyrBnuBw0x0mXFaSpgCfBhZLWpRe99WImJdgTdZ9fB64P31RVA18NuF6EhMRr0h6GHiN1N1qr5ODwyF4CAQzsxyXK003ZmZ2GA56M7Mc56A3M8txDnozsxznoDczy3EOejOzHOegNzPLcf8fToGulmwQ7GwAAAAASUVORK5CYII=\n",
264
+ "text/plain": [
265
+ "<Figure size 432x288 with 1 Axes>"
266
+ ]
267
+ },
268
+ "metadata": {
269
+ "needs_background": "light"
270
+ },
271
+ "output_type": "display_data"
272
+ }
273
+ ],
274
+ "source": [
275
+ "import matplotlib.pyplot as plt\n",
276
+ "%matplotlib inline\n",
277
+ "\n",
278
+ "print(tm.scores['ranking'][-1])\n",
279
+ "plt.plot(tm.scores['ranking'])"
280
+ ]
281
+ },
282
+ {
283
+ "cell_type": "code",
284
+ "execution_count": null,
285
+ "metadata": {},
286
+ "outputs": [],
287
+ "source": []
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": 28,
292
+ "metadata": {},
293
+ "outputs": [],
294
+ "source": [
295
+ "theta = artm_model.transform(batch_vectorizer=dataset.get_batch_vectorizer())"
296
+ ]
297
+ },
298
+ {
299
+ "cell_type": "code",
300
+ "execution_count": 30,
301
+ "metadata": {},
302
+ "outputs": [
303
+ {
304
+ "name": "stdout",
305
+ "output_type": "stream",
306
+ "text": [
307
+ "Асимптоматический_хронический_простатит Некротический_фасциит Болезнь_Галлервордена_—_Шпатца\n",
308
+ "{'Синдромы по алфавиту', 'Бактериальные инфекции'}\n",
309
+ "Листериоз Трихофития Дермацентороз\n",
310
+ "{'Инфекционные заболевания', 'Синдромы по алфавиту'}\n",
311
+ "Гестоз Маловодие Психогенное_переедание\n",
312
+ "{'Патология беременности', 'Синдромы по алфавиту'}\n"
313
+ ]
314
+ }
315
+ ],
316
+ "source": [
317
+ "for (a, b, c, explanation) in triplets[:10]:\n",
318
+ " # L1 distance, just for example\n",
319
+ " similar_dist = sum(abs(theta[a] - theta[b])) \n",
320
+ " diffrnt_dist = sum(abs(theta[a] - theta[c]))\n",
321
+ "\n",
322
+ " if (similar_dist > diffrnt_dist):\n",
323
+ " print(a, b, c)\n",
324
+ " print(explanation)\n"
325
+ ]
326
+ },
327
+ {
328
+ "cell_type": "code",
329
+ "execution_count": null,
330
+ "metadata": {},
331
+ "outputs": [],
332
+ "source": []
333
+ },
334
+ {
335
+ "cell_type": "code",
336
+ "execution_count": null,
337
+ "metadata": {},
338
+ "outputs": [],
339
+ "source": []
340
+ }
341
+ ],
342
+ "metadata": {
343
+ "kernelspec": {
344
+ "display_name": "Python 3",
345
+ "language": "python",
346
+ "name": "python3"
347
+ },
348
+ "language_info": {
349
+ "codemirror_mode": {
350
+ "name": "ipython",
351
+ "version": 3
352
+ },
353
+ "file_extension": ".py",
354
+ "mimetype": "text/x-python",
355
+ "name": "python",
356
+ "nbconvert_exporter": "python",
357
+ "pygments_lexer": "ipython3",
358
+ "version": "3.8.11"
359
+ }
360
+ },
361
+ "nbformat": 4,
362
+ "nbformat_minor": 2
363
+ }
preprocessing/MKB-obtain.ipynb ADDED
The diff for this file is too large to render. See raw diff