{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-1 fw=all -->\n",
    "\n",
    "# Sequence-Aware Recommender Systems\n",
    "\n",
    "In previous sections, we abstract the recommendation task as a matrix completion problem without considering users' short-term behaviors. In this section, we will introduce a recommendation model that takes  the sequentially-ordered user interaction logs into account.  It is a sequence-aware recommender [@Quadrana.Cremonesi.Jannach.2018] where the input is an ordered and often timestamped list of past user actions.  A number of recent literatures have demonstrated the usefulness of incorporating such information in modeling users' temporal behavioral patterns and discovering their interest drift.\n",
    "\n",
    "The model we will introduce, Caser [@Tang.Wang.2018], short for convolutional sequence embedding recommendation model, adopts convolutional neural networks capture the dynamic pattern influences of users' recent activities. The main component of Caser consists of a horizontal convolutional network and a vertical convolutional network, aiming to uncover the union-level and point-level sequence patterns, respectively.  Point-level pattern indicates the impact of single item in the historical sequence on the target item, while union level pattern implies the influences of several previous actions on the subsequent target. For example, buying both milk and butter together leads to higher probability of buying flour than just buying one of them. Moreover, users' general interests, or long term preferences are also modeled in the last fully connected layers, resulting in a more comprehensive modeling of user interests. Details of the model are described as follows.\n",
    "\n",
    "## Model Architectures\n",
    "\n",
    "In sequence-aware recommendation system, each user is associated with a sequence of some items from the item set. Let $S^u = (S_1^u, ... S_{|S_u|}^u)$ denotes the ordered sequence. The goal of Caser is to recommend item by considering user general tastes as well as short-term intention. Suppose we take the previous $L$ items into consideration, an embedding matrix that represents the former interactions for time step $t$ can be constructed:\n",
    "\n",
    "$$\n",
    "\\mathbf{E}^{(u, t)} = \\begin{bmatrix} \\mathbf{q}_{S_{t-L}^u} \\\\ \\vdots \\\\ \\mathbf{q}_{S_{t-2}^u} \\\\ \\mathbf{q}_{S_{t-1}^u} \\end{bmatrix},\n",
    "$$\n",
    "\n",
    "where $\\mathbf{Q} \\in \\mathbb{R}^{n \\times k}$ represents item embeddings and $\\mathbf{q}_i$ denotes the $i^\\textrm{th}$ row. $\\mathbf{E}^{(u, t)} \\in \\mathbb{R}^{L \\times k}$ can be used to infer the transient interest of user $u$ at time-step $t$. We can view the input matrix $\\mathbf{E}^{(u, t)}$ as an image which is the input of the subsequent two convolutional components.\n",
    "\n",
    "The horizontal convolutional layer has $d$ horizontal filters $\\mathbf{F}^j \\in \\mathbb{R}^{h \\times k}, 1 \\leq j \\leq d, h = \\{1, ..., L\\}$, and the vertical convolutional layer has $d'$ vertical filters $\\mathbf{G}^j \\in \\mathbb{R}^{ L \\times 1}, 1 \\leq j \\leq d'$. After a series of convolutional and pool operations, we get the two outputs:\n",
    "\n",
    "$$\n",
    "\\mathbf{o} = \\textrm{HConv}(\\mathbf{E}^{(u, t)}, \\mathbf{F}) \\\\\n",
    "\\mathbf{o}'= \\textrm{VConv}(\\mathbf{E}^{(u, t)}, \\mathbf{G}) ,\n",
    "$$\n",
    "\n",
    "where $\\mathbf{o} \\in \\mathbb{R}^d$ is the output of horizontal convolutional network and $\\mathbf{o}' \\in \\mathbb{R}^{kd'}$ is the output of vertical convolutional network. For simplicity, we omit the details of convolution and pool operations. They are concatenated and fed into a fully connected neural network layer to get more high-level representations.\n",
    "\n",
    "$$\n",
    "\\mathbf{z} = \\phi(\\mathbf{W}[\\mathbf{o}, \\mathbf{o}']^\\top + \\mathbf{b}),\n",
    "$$\n",
    "\n",
    "where $\\mathbf{W} \\in \\mathbb{R}^{k \\times (d + kd')}$ is the weight matrix and $\\mathbf{b} \\in \\mathbb{R}^k$ is the bias. The learned vector $\\mathbf{z} \\in \\mathbb{R}^k$ is the representation of user's short-term intent.\n",
    "\n",
    "At last, the prediction function combines users' short-term and general taste together, which is defined as:\n",
    "\n",
    "$$\n",
    "\\hat{y}_{uit} = \\mathbf{v}_i \\cdot [\\mathbf{z}, \\mathbf{p}_u]^\\top + \\mathbf{b}'_i,\n",
    "$$\n",
    "\n",
    "where $\\mathbf{V} \\in \\mathbb{R}^{n \\times 2k}$ is another item embedding matrix. $\\mathbf{b}' \\in \\mathbb{R}^n$ is the item specific bias.  $\\mathbf{P} \\in \\mathbb{R}^{m \\times k}$ is the user embedding matrix for users' general tastes. $\\mathbf{p}_u \\in \\mathbb{R}^{ k}$ is the $u^\\textrm{th}$ row of $P$ and $\\mathbf{v}_i \\in \\mathbb{R}^{2k}$ is the $i^\\textrm{th}$ row of $\\mathbf{V}$.\n",
    "\n",
    "The model can be learned with BPR or Hinge loss. The architecture of Caser is shown below:\n",
    "\n",
    "![Illustration of the Caser Model](../img/rec-caser.svg)\n",
    "\n",
    "We first import the required libraries."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "seqrec-model-architectures"
   },
   "source": [
    "from d2l import torch as d2l\n",
    "import torch\n",
    "from torch import nn\n",
    "import random"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-2 fw=all -->\n",
    "\n",
    "## Model Implementation\n",
    "The following code implements the Caser model. It consists of a vertical convolutional layer, a horizontal convolutional layer, and a full-connected layer."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "seqrec-model-implementation"
   },
   "source": [
    "class Caser(nn.Module):\n",
    "    def __init__(self, num_factors, num_users, num_items, L=5, d=16,\n",
    "                 d_prime=4, drop_ratio=0.05):\n",
    "        super().__init__()\n",
    "        self.P = nn.Embedding(num_users, num_factors)\n",
    "        self.Q = nn.Embedding(num_items, num_factors)\n",
    "        self.d_prime, self.d = d_prime, d\n",
    "        # Vertical convolution layer\n",
    "        self.conv_v = nn.Conv2d(1, d_prime, (L, 1))\n",
    "        # Horizontal convolution layer\n",
    "        h = [i + 1 for i in range(L)]\n",
    "        self.conv_h = nn.ModuleList(\n",
    "            [nn.Conv2d(1, d, (i, num_factors)) for i in h])\n",
    "        self.max_pool = nn.ModuleList(\n",
    "            [nn.MaxPool1d(L - i + 1) for i in h])\n",
    "        # Fully connected layer\n",
    "        self.fc1_dim_v, self.fc1_dim_h = d_prime * num_factors, d * len(h)\n",
    "        self.fc = nn.Sequential(\n",
    "            nn.Linear(d_prime * num_factors + d * L, num_factors),\n",
    "            nn.ReLU())\n",
    "        self.Q_prime = nn.Embedding(num_items, num_factors * 2)\n",
    "        self.b = nn.Embedding(num_items, 1)\n",
    "        self.dropout = nn.Dropout(drop_ratio)\n",
    "\n",
    "    def forward(self, user_id, seq, item_id):\n",
    "        item_embs = self.Q(seq).unsqueeze(1)\n",
    "        user_emb = self.P(user_id)\n",
    "        out, out_h, out_v, out_hs = None, None, None, []\n",
    "        if self.d_prime:\n",
    "            out_v = self.conv_v(item_embs)\n",
    "            out_v = out_v.reshape(out_v.shape[0], self.fc1_dim_v)\n",
    "        if self.d:\n",
    "            for conv, maxp in zip(self.conv_h, self.max_pool):\n",
    "                conv_out = torch.relu(conv(item_embs)).squeeze(3)\n",
    "                t = maxp(conv_out)\n",
    "                pool_out = t.squeeze(2)\n",
    "                out_hs.append(pool_out)\n",
    "            out_h = torch.cat(out_hs, dim=1)\n",
    "        out = torch.cat([out_v, out_h], dim=1)\n",
    "        z = self.fc(self.dropout(out))\n",
    "        x = torch.cat([z, user_emb], dim=1)\n",
    "        # batch_size is 4096 here, so bare squeeze (collapsing all singleton\n",
    "        # axes) is safe and produces matched shapes for the positive\n",
    "        # (item_id shape (B,1)) and negative (item_id shape (B,)) paths.\n",
    "        q_prime_i = self.Q_prime(item_id).squeeze()\n",
    "        b = self.b(item_id).squeeze()\n",
    "        res = (x * q_prime_i).sum(1) + b\n",
    "        return res"
   ],
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-3 fw=all -->\n",
    "\n",
    "## Sequential Dataset with Negative Sampling\n",
    "To process the sequential interaction data, we need to reimplement the `Dataset` class. The following code creates a new dataset class named `SeqDataset`. In each sample, it outputs the user identity, his previous $L$ interacted items as a sequence and the next item he interacts as the target. The following figure demonstrates the data loading process for one user. Suppose that this user liked 9 movies, we organize these nine movies in chronological order. The latest movie is left out as the test item. For the remaining eight movies, we can get three training samples, with each sample containing a sequence of five ($L=5$) movies and its subsequent item as the target item. Negative samples are also included in the customized dataset.\n",
    "\n",
    "![Illustration of the data generation process](../img/rec-seq-data.svg)"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "seqrec-sequential-dataset-with-negative-sampling"
   },
   "source": [
    "class SeqDataset(torch.utils.data.Dataset):\n",
    "    def __init__(self, user_ids, item_ids, L, num_users, num_items,\n",
    "                 candidates, test_items=None):\n",
    "        user_ids = torch.tensor(user_ids, dtype=torch.long)\n",
    "        item_ids = torch.tensor(item_ids, dtype=torch.long)\n",
    "        sort_idx = sorted(range(len(user_ids)),\n",
    "                          key=lambda k: user_ids[k].item())\n",
    "        sort_idx = torch.tensor(sort_idx, dtype=torch.long)\n",
    "        u_ids, i_ids = user_ids[sort_idx], item_ids[sort_idx]\n",
    "        temp, u_ids_np = {}, u_ids.numpy()\n",
    "        # Precompute each user's negative pool once: items the user has not\n",
    "        # interacted with in train AND not held out as a test positive\n",
    "        # (excluding test positives prevents leakage into the BPR loss).\n",
    "        all_items = set(range(num_items))\n",
    "        test_items = test_items or {}\n",
    "        self.neg_pool = {\n",
    "            u: list(all_items - set(candidates.get(u, [])) - set(test_items.get(u, [])))\n",
    "            for u in candidates}\n",
    "        [temp.setdefault(u_ids_np[i], []).append(i)\n",
    "         for i, _ in enumerate(u_ids_np)]\n",
    "        temp = sorted(temp.items(), key=lambda x: x[0])\n",
    "        u_ids = torch.tensor([i[0] for i in temp], dtype=torch.long)\n",
    "        idx = torch.tensor([i[1][0] for i in temp], dtype=torch.long)\n",
    "        self.ns = ns = int(sum([c - L if c >= L + 1 else 1 for c\n",
    "                                in [len(i[1]) for i in temp]]))\n",
    "        self.seq_items = torch.zeros(ns, L, dtype=torch.long)\n",
    "        self.seq_users = torch.zeros(ns, dtype=torch.long)\n",
    "        self.seq_tgt = torch.zeros(ns, 1, dtype=torch.long)\n",
    "        self.test_seq = torch.zeros(num_users, L, dtype=torch.long)\n",
    "        test_users, _uid = torch.empty(num_users), None\n",
    "        for i, (uid, i_seq) in enumerate(self._seq(u_ids, i_ids, idx, L + 1)):\n",
    "            if uid != _uid:\n",
    "                self.test_seq[uid][:] = i_seq[-L:]\n",
    "                test_users[uid], _uid = uid, uid\n",
    "            self.seq_tgt[i][:] = i_seq[-1:]\n",
    "            self.seq_items[i][:], self.seq_users[i] = i_seq[:L], uid\n",
    "\n",
    "    def _win(self, tensor, window_size, step_size=1):\n",
    "        if len(tensor) - window_size >= 0:\n",
    "            for i in range(len(tensor), 0, - step_size):\n",
    "                if i - window_size >= 0:\n",
    "                    yield tensor[i - window_size:i]\n",
    "                else:\n",
    "                    break\n",
    "        else:\n",
    "            yield tensor\n",
    "\n",
    "    def _seq(self, u_ids, i_ids, idx, max_len):\n",
    "        for i in range(len(idx)):\n",
    "            stop_idx = None if i >= len(idx) - 1 else int(idx[i + 1])\n",
    "            for s in self._win(i_ids[int(idx[i]):stop_idx], max_len):\n",
    "                yield (int(u_ids[i]), s)\n",
    "\n",
    "    def __len__(self):\n",
    "        return self.ns\n",
    "\n",
    "    def __getitem__(self, idx):\n",
    "        neg = self.neg_pool[int(self.seq_users[idx])]\n",
    "        i = random.randint(0, len(neg) - 1)\n",
    "        return (self.seq_users[idx], self.seq_items[idx], self.seq_tgt[idx],\n",
    "                neg[i])"
   ],
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-4 fw=all -->\n",
    "\n",
    "## Load the MovieLens 100K dataset\n",
    "\n",
    "Afterwards, we read and split the MovieLens 100K dataset in sequence-aware mode and load the training data with sequential dataloader implemented above."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "seqrec-load-the-movielens-100k-dataset"
   },
   "source": [
    "TARGET_NUM, L, batch_size = 1, 5, 4096\n",
    "df, num_users, num_items = d2l.read_data_ml100k()\n",
    "train_data, test_data = d2l.split_data_ml100k(df, num_users, num_items,\n",
    "                                              'seq-aware')\n",
    "users_train, items_train, ratings_train, candidates = d2l.load_data_ml100k(\n",
    "    train_data, num_users, num_items, feedback=\"implicit\")\n",
    "users_test, items_test, ratings_test, test_iter = d2l.load_data_ml100k(\n",
    "    test_data, num_users, num_items, feedback=\"implicit\")\n",
    "train_seq_data = SeqDataset(users_train, items_train, L, num_users,\n",
    "                            num_items, candidates, test_items=test_iter)\n",
    "train_iter = torch.utils.data.DataLoader(train_seq_data, batch_size,\n",
    "                                         shuffle=True, drop_last=True,\n",
    "                                         num_workers=d2l.get_dataloader_workers())\n",
    "test_seq_iter = train_seq_data.test_seq\n",
    "train_seq_data[0]"
   ],
   "execution_count": 4,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(tensor(0), tensor([241, 170, 110, 255,   4]), tensor([101]), 509)"
     },
     "metadata": {},
     "execution_count": 4
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-5 fw=all -->\n",
    "\n",
    "The training data structure is shown above. The first element is the user identity, the second is the list of the last five items this user liked, the third is the target item this user liked after those five, and the fourth is a randomly sampled negative item.\n",
    "\n",
    "## Train the Model\n",
    "Now, let's train the model. We use the same setting as NeuMF, including learning rate, optimizer, and $k$, in the last section so that the results are comparable."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "seqrec-train-the-model"
   },
   "source": [
    "devices = d2l.try_all_gpus()\n",
    "net = Caser(10, num_users, num_items, L)\n",
    "def _init(m):\n",
    "    # Match MX's `init.Normal(0.01)` semantics: initialize weights *and*\n",
    "    # biases, so biases don't keep their default uniform fan-in init.\n",
    "    if hasattr(m, 'weight') and m.weight is not None:\n",
    "        nn.init.normal_(m.weight, 0, 0.01)\n",
    "    if hasattr(m, 'bias') and m.bias is not None:\n",
    "        nn.init.zeros_(m.bias)\n",
    "net.apply(_init)\n",
    "net = net.to(devices[0])\n",
    "lr, num_epochs, wd, optimizer = 0.04, 8, 1e-5, 'adam'\n",
    "loss = d2l.BPRLoss()\n",
    "trainer = torch.optim.Adam(net.parameters(), lr=lr, weight_decay=wd)\n",
    "\n",
    "# `evaluate_ranking` is the bottleneck — it scores every (user, item)\n",
    "# pair that the user has not interacted with, so per-epoch evaluation\n",
    "# dominates total runtime. Setting `eval_step=num_epochs` defers\n",
    "# evaluation to the final epoch only, which keeps the cell well under\n",
    "# an hour while still reporting hit-rate / AUC for the trained model.\n",
    "d2l.train_ranking(net, train_iter, test_iter, loss, trainer,\n",
    "                  test_seq_iter, num_users, num_items, num_epochs,\n",
    "                  devices, d2l.evaluate_ranking, candidates,\n",
    "                  eval_step=num_epochs)"
   ],
   "execution_count": 5,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "train loss 0.127, test hit rate 0.409, test AUC 0.890\n896.7 examples/sec on [device(type='cuda', index=0)]\n"
     ]
    },
    {
     "output_type": "display_data",
     "data": {
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"235.784375pt\" height=\"187.155469pt\" viewBox=\"0 0 235.784375 187.155469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2026-07-19T14:01:47.315539</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.8, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 187.155469 \nL 235.784375 187.155469 \nL 235.784375 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 30.103125 149.599219 \nL 225.403125 149.599219 \nL 225.403125 10.999219 \nL 30.103125 10.999219 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 58.003125 149.599219 \nL 58.003125 10.999219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m97c6bf8f16\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m97c6bf8f16\" x=\"58.003125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 2 -->\n      <g transform=\"translate(54.821875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 113.803125 149.599219 \nL 113.803125 10.999219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m97c6bf8f16\" x=\"113.803125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 4 -->\n      <g transform=\"translate(110.621875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 169.603125 149.599219 \nL 169.603125 10.999219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m97c6bf8f16\" x=\"169.603125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 6 -->\n      <g transform=\"translate(166.421875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-36\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 225.403125 149.599219 \nL 225.403125 10.999219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m97c6bf8f16\" x=\"225.403125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 8 -->\n      <g transform=\"translate(222.221875 164.197656) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-38\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_5\">\n     <!-- epoch -->\n     <g transform=\"translate(112.525 177.875781) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \nL 3122 2828 \nQ 2878 2963 2633 3030 \nQ 2388 3097 2138 3097 \nQ 1578 3097 1268 2742 \nQ 959 2388 959 1747 \nQ 959 1106 1268 751 \nQ 1578 397 2138 397 \nQ 2388 397 2633 464 \nQ 2878 531 3122 666 \nL 3122 134 \nQ 2881 22 2623 -34 \nQ 2366 -91 2075 -91 \nQ 1284 -91 818 406 \nQ 353 903 353 1747 \nQ 353 2603 823 3093 \nQ 1294 3584 2113 3584 \nQ 2378 3584 2631 3529 \nQ 2884 3475 3122 3366 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-65\"/>\n      <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(61.523438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(186.181641 0)\"/>\n      <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(241.162109 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_9\">\n      <path d=\"M 30.103125 149.599219 \nL 225.403125 149.599219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <defs>\n       <path id=\"m19aa1d7f5c\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m19aa1d7f5c\" x=\"30.103125\" y=\"149.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 0.0 -->\n      <g transform=\"translate(7.2 153.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_11\">\n      <path d=\"M 30.103125 121.879219 \nL 225.403125 121.879219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m19aa1d7f5c\" x=\"30.103125\" y=\"121.879219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0.2 -->\n      <g transform=\"translate(7.2 125.678438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_13\">\n      <path d=\"M 30.103125 94.159219 \nL 225.403125 94.159219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m19aa1d7f5c\" x=\"30.103125\" y=\"94.159219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0.4 -->\n      <g transform=\"translate(7.2 97.958438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_15\">\n      <path d=\"M 30.103125 66.439219 \nL 225.403125 66.439219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m19aa1d7f5c\" x=\"30.103125\" y=\"66.439219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 0.6 -->\n      <g transform=\"translate(7.2 70.238437) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_17\">\n      <path d=\"M 30.103125 38.719219 \nL 225.403125 38.719219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#m19aa1d7f5c\" x=\"30.103125\" y=\"38.719219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 0.8 -->\n      <g transform=\"translate(7.2 42.518438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-38\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_6\">\n     <g id=\"line2d_19\">\n      <path d=\"M 30.103125 10.999219 \nL 225.403125 10.999219 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_20\">\n      <g>\n       <use xlink:href=\"#m19aa1d7f5c\" x=\"30.103125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 1.0 -->\n      <g transform=\"translate(7.2 14.798438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_21\">\n    <path d=\"M 225.403125 92.865815 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_22\">\n    <path d=\"M 225.403125 26.233974 \n\" clip-path=\"url(#p2a5d567837)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 30.103125 149.599219 \nL 30.103125 10.999219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 225.403125 149.599219 \nL 225.403125 10.999219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 30.103125 149.599219 \nL 225.403125 149.599219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 30.103125 10.999219 \nL 225.403125 10.999219 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"legend_1\">\n    <g id=\"patch_7\">\n     <path d=\"M 127.495313 48.355469 \nL 218.403125 48.355469 \nQ 220.403125 48.355469 220.403125 46.355469 \nL 220.403125 17.999219 \nQ 220.403125 15.999219 218.403125 15.999219 \nL 127.495313 15.999219 \nQ 125.495313 15.999219 125.495313 17.999219 \nL 125.495313 46.355469 \nQ 125.495313 48.355469 127.495313 48.355469 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_23\">\n     <path d=\"M 129.495313 24.097656 \nL 139.495313 24.097656 \nL 149.495313 24.097656 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_12\">\n     <!-- test hit rate -->\n     <g transform=\"translate(157.495313 27.597656) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(100.732422 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(152.832031 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(192.041016 0)\"/>\n      <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(223.828125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(287.207031 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(314.990234 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(354.199219 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(385.986328 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(427.099609 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(488.378906 0)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(527.587891 0)\"/>\n     </g>\n    </g>\n    <g id=\"line2d_24\">\n     <path d=\"M 129.495313 38.775781 \nL 139.495313 38.775781 \nL 149.495313 38.775781 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_13\">\n     <!-- test AUC -->\n     <g transform=\"translate(157.495313 42.275781) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-41\" d=\"M 2188 4044 \nL 1331 1722 \nL 3047 1722 \nL 2188 4044 \nz\nM 1831 4666 \nL 2547 4666 \nL 4325 0 \nL 3669 0 \nL 3244 1197 \nL 1141 1197 \nL 716 0 \nL 50 0 \nL 1831 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-55\" d=\"M 556 4666 \nL 1191 4666 \nL 1191 1831 \nQ 1191 1081 1462 751 \nQ 1734 422 2344 422 \nQ 2950 422 3222 751 \nQ 3494 1081 3494 1831 \nL 3494 4666 \nL 4128 4666 \nL 4128 1753 \nQ 4128 841 3676 375 \nQ 3225 -91 2344 -91 \nQ 1459 -91 1007 375 \nQ 556 841 556 1753 \nL 556 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-43\" d=\"M 4122 4306 \nL 4122 3641 \nQ 3803 3938 3442 4084 \nQ 3081 4231 2675 4231 \nQ 1875 4231 1450 3742 \nQ 1025 3253 1025 2328 \nQ 1025 1406 1450 917 \nQ 1875 428 2675 428 \nQ 3081 428 3442 575 \nQ 3803 722 4122 1019 \nL 4122 359 \nQ 3791 134 3420 21 \nQ 3050 -91 2638 -91 \nQ 1578 -91 968 557 \nQ 359 1206 359 2328 \nQ 359 3453 968 4101 \nQ 1578 4750 2638 4750 \nQ 3056 4750 3426 4639 \nQ 3797 4528 4122 4306 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-74\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(39.208984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(100.732422 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(152.832031 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(192.041016 0)\"/>\n      <use xlink:href=\"#DejaVuSans-41\" transform=\"translate(223.828125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-55\" transform=\"translate(292.236328 0)\"/>\n      <use xlink:href=\"#DejaVuSans-43\" transform=\"translate(365.429688 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p2a5d567837\">\n   <rect x=\"30.103125\" y=\"10.999219\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-6 fw=all -->\n",
    "\n",
    "## Summary\n",
    "* Inferring a user's short-term and long-term interests can make prediction of the next item that he preferred more effectively.\n",
    "* Convolutional neural networks can be utilized to capture users' short-term interests from sequential interactions.\n",
    "\n",
    "## Exercises\n",
    "\n",
    "* Conduct an ablation study by removing one of the horizontal and vertical convolutional networks, which component is the more important ?\n",
    "* Vary the hyperparameter $L$. Does longer historical interactions bring higher accuracy?\n",
    "* Apart from the sequence-aware recommendation task we introduced above, there is another type of sequence-aware recommendation task called session-based recommendation [@Hidasi.Karatzoglou.Baltrunas.ea.2015]. Can you explain the differences between these two tasks?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=seqrec-md-7 fw=pytorch -->\n",
    "\n",
    "[Discussions](https://d2l.discourse.group/t/404)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-pytorch",
   "display_name": "d2l (PyTorch)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
