{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from topicnet.cooking_machine import Dataset\n", "import pandas as pd\n", "\n", "dataset = Dataset('MKB10.csv', batch_vectorizer_path=\"./mkb_batches2\")\n", "\n", "data_orig = pd.read_pickle(\"MKB10.pkl\")\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "data_orig.title = data_orig.title.str.replace(\" \", \"_\")\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'@letter', '@ngram', '@text'}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dataset.get_possible_modalities()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "\n", "import numpy as np\n", "\n", "# all articles are from category \"Симптомы по алфавиту\", so threshold is 1\n", "THRESHOLD = 1\n", "\n", "def randomly_select(data_orig, point_a, should_intersect):\n", " attempts_left = 100\n", " while attempts_left > 0:\n", " rnd_idx_b = np.random.choice(data_orig.shape[0])\n", " point_b = data_orig.iloc[rnd_idx_b]\n", " intersection = set(point_b.categories) & set(point_a.categories)\n", " is_big = (len(intersection) > THRESHOLD)\n", " if should_intersect == is_big:\n", " # if is_big:\n", " # print(point_a.title, point_b.title, intersection)\n", " return point_b.title, rnd_idx_b, intersection\n", " attempts_left -= 1\n", " return None, None, None\n", "\n", "def generate_triplet(data_orig):\n", "\n", " rnd_idx_a = np.random.choice(data_orig.shape[0])\n", " point_a = data_orig.iloc[rnd_idx_a]\n", " point_b, rnd_idx_b, intersection = randomly_select(data_orig, point_a, should_intersect=True)\n", " point_c, rnd_idx_c, empty_intersection = randomly_select(data_orig, point_a, should_intersect=False)\n", " # return [point_a, point_b, point_c]\n", " return [point_a.title, point_b, point_c, intersection]\n", " # return [rnd_idx_a, rnd_idx_b, rnd_idx_c]\n", "\n", " \n", " " ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 10000/10000 [00:57<00:00, 173.50it/s]\n" ] }, { "data": { "text/plain": [ "7221" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from tqdm import tqdm\n", "\n", "triplets = []\n", "\n", "for i in tqdm(range(10000)):\n", " a, b, c, explanation = generate_triplet(data_orig)\n", " if b is not None and c is not None:\n", " triplets.append( (a, b, c, explanation) )\n", "\n", "len(triplets)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "\n", "with open(\"triplets_mkb.p\", \"wb\") as f:\n", " pickle.dump(triplets, f)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Scoring model by ranking quality" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "from topicnet.cooking_machine.models import BaseScore as BaseTopicNetScore, TopicModel\n", "\n", "\n", "class ValidationRankingQuality(BaseTopicNetScore):\n", " def __init__(self, validation_dataset, triplets):\n", " super().__init__()\n", "\n", " self.validation_dataset = validation_dataset\n", " self.triplets = triplets\n", "\n", " def call(self, model: TopicModel):\n", " theta = model.get_theta(dataset=self.validation_dataset)\n", " \n", " correct_rankings = 0\n", "\n", " for (a, b, c, _) in self.triplets:\n", " # L1 distance, just for example\n", " similar_dist = sum(abs(theta[a] - theta[b]))\n", " diffrnt_dist = sum(abs(theta[a] - theta[c]))\n", "\n", " correct_rankings += (similar_dist < diffrnt_dist)\n", "\n", " return correct_rankings / len(self.triplets)\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "import artm\n", "\n", "artm_model = artm.ARTM(\n", " num_topics=20, \n", " dictionary=dataset.get_dictionary(),\n", " class_ids={'@lemmatized': 1, '@ngram': 50}, # absolute values, just for example\n", " theta_columns_naming=\"title\"\n", ")\n", "\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "tm = TopicModel(artm_model, custom_scores={\"ranking\": ValidationRankingQuality(dataset, triplets)})" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "scrolled": true }, "outputs": [], "source": [ "tm._fit(dataset.get_batch_vectorizer(), 10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.641600886303836\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXzV9Z3v8debhATCDgmIgLIYVFTUGlcURYtF2+LMdMal01Y7U5eZsfa2nc7V3rmtpbP1Tmc607ncadGx7bQu7Wir2FJxGevWqgRFkSCKQSCsYQ9bQpLP/eOcwCEEcwIJv+Sc9/PxOA/Ob83nHM37/PI9v+/3q4jAzMxyV6+kCzAzs67loDczy3EOejOzHOegNzPLcQ56M7McV5h0Aa2VlpbG2LFjky7DzKxHWbhw4aaIKGtrW7cL+rFjx1JZWZl0GWZmPYqklYfb5qYbM7Mc56A3M8txDnozsxznoDczy3EOejOzHOegNzPLcQ56M7Mc1+3uozczy3X7mprZsquB2rp6anfWs6munk07GxjUtzefPP+ETv95Dnozs07Q0NjM5l31bKprYNPOdIDvrKc2HeKpME89tu7e1+Y5PnTC4OSCXtIM4F+BAuDeiPiHNva5FrgbCOCNiPhk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DLdYV6KiHUR8Vr6eR2pX+S2ZgXLC5JGAx8F7k26lqRJGghMBf4DICIaImJbslUlrhDoK6kQKKHVfBu5IFeCPtvpDvOOpLHA2cAryVaSqH8B/ooumpi+hxkP1AI/SDdl3SupX9JFJSUi1gDfBlYB64DtEfFkslV1vlwJ+mymO8w7kvoDjwD/IyJ2JF1PEiR9DNgYEQuTrqWbKCQ1y9u/R8TZwC4gb7/TkjSE1F//44DjgX6SPpVsVZ0vV4K+3ekO842k3qRC/v6I+HnS9SRoCjBT0vukmvQul/STZEtKVA1QExEtf+E9TH5P7/lhYEVE1EbEPuDnwEUJ19TpciXo253uMJ+kZ/P6D2BpRPxz0vUkKSLuiojRETGW1P8X/x0ROXfFlq2IWA+slnRyetUV5Pf0nquACySVpH9vriAHv5xudyrBnuBw0x0mXFaSpgCfBhZLWpRe99WImJdgTdZ9fB64P31RVA18NuF6EhMRr0h6GHiN1N1qr5ODwyF4CAQzsxyXK003ZmZ2GA56M7Mc56A3M8txDnozsxznoDczy3EOejOzHOegNzPLcf8fToGulmwQ7GwAAAAASUVORK5CYII=\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "print(tm.scores['ranking'][-1])\n", "plt.plot(tm.scores['ranking'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "theta = artm_model.transform(batch_vectorizer=dataset.get_batch_vectorizer())" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Асимптоматический_хронический_простатит Некротический_фасциит Болезнь_Галлервордена_—_Шпатца\n", "{'Синдромы по алфавиту', 'Бактериальные инфекции'}\n", "Листериоз Трихофития Дермацентороз\n", "{'Инфекционные заболевания', 'Синдромы по алфавиту'}\n", "Гестоз Маловодие Психогенное_переедание\n", "{'Патология беременности', 'Синдромы по алфавиту'}\n" ] } ], "source": [ "for (a, b, c, explanation) in triplets[:10]:\n", " # L1 distance, just for example\n", " similar_dist = sum(abs(theta[a] - theta[b])) \n", " diffrnt_dist = sum(abs(theta[a] - theta[c]))\n", "\n", " if (similar_dist > diffrnt_dist):\n", " print(a, b, c)\n", " print(explanation)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.11" } }, "nbformat": 4, "nbformat_minor": 2 }