introduction_en.ipynb 3.9 KB
Notebook
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "545c6ec0",
   "metadata": {},
   "source": [
    "# Cross-Encoder for MS Marco\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbd27361",
   "metadata": {},
   "source": [
    "This model was trained on the [MS Marco Passage Ranking](https://github.com/microsoft/MSMARCO-Passage-Ranking) task.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "185acb77",
   "metadata": {},
   "source": [
    "The model can be used for Information Retrieval: Given a query, encode the query will all possible passages (e.g. retrieved with ElasticSearch). Then sort the passages in a decreasing order. See [SBERT.net Retrieve & Re-rank](https://www.sbert.net/examples/applications/retrieve_rerank/README.html) for more details. The training code is available here: [SBERT.net Training MS Marco](https://github.com/UKPLab/sentence-transformers/tree/master/examples/training/ms_marco)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1fb83fc3",
   "metadata": {},
   "source": [
    "## How to use\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2cf01d71",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install --upgrade paddlenlp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d24e4eb7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import paddle\n",
    "from paddlenlp.transformers import AutoModel\n",
    "\n",
    "model = AutoModel.from_pretrained(\"cross-encoder/ms-marco-TinyBERT-L-2\")\n",
    "input_ids = paddle.randint(100, 200, shape=[1, 20])\n",
    "print(model(input_ids))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7eb19416",
   "metadata": {},
   "source": [
    "## Performance\n",
    "In the following table, we provide various pre-trained Cross-Encoders together with their performance on the [TREC Deep Learning 2019](https://microsoft.github.io/TREC-2019-Deep-Learning/) and the [MS Marco Passage Reranking](https://github.com/microsoft/MSMARCO-Passage-Ranking/) dataset.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e51901bb",
   "metadata": {},
   "source": [
    "| Model-Name        | NDCG@10 (TREC DL 19) | MRR@10 (MS Marco Dev)  | Docs / Sec |\n",
    "| ------------- |:-------------| -----| --- |\n",
    "| **Version 2 models** | | |\n",
    "| cross-encoder/ms-marco-TinyBERT-L-2-v2 | 69.84 | 32.56 | 9000\n",
    "| cross-encoder/ms-marco-MiniLM-L-2-v2 | 71.01 | 34.85 | 4100\n",
    "| cross-encoder/ms-marco-MiniLM-L-4-v2 | 73.04 | 37.70 | 2500\n",
    "| cross-encoder/ms-marco-MiniLM-L-6-v2 | 74.30 | 39.01 | 1800\n",
    "| cross-encoder/ms-marco-MiniLM-L-12-v2 | 74.31 | 39.02 | 960\n",
    "| **Version 1 models** | | |\n",
    "| cross-encoder/ms-marco-TinyBERT-L-2  | 67.43 | 30.15  | 9000\n",
    "| cross-encoder/ms-marco-TinyBERT-L-4  | 68.09 | 34.50  | 2900\n",
    "| cross-encoder/ms-marco-TinyBERT-L-6 |  69.57 | 36.13  | 680\n",
    "| cross-encoder/ms-marco-electra-base | 71.99 | 36.41 | 340\n",
    "| **Other models** | | |\n",
    "| nboost/pt-tinybert-msmarco | 63.63 | 28.80 | 2900\n",
    "| nboost/pt-bert-base-uncased-msmarco | 70.94 | 34.75 | 340\n",
    "| nboost/pt-bert-large-msmarco | 73.36 | 36.48 | 100\n",
    "| Capreolus/electra-base-msmarco | 71.23 | 36.89 | 340\n",
    "| amberoad/bert-multilingual-passage-reranking-msmarco | 68.40 | 35.54 | 330\n",
    "| sebastian-hofstaetter/distilbert-cat-margin_mse-T2-msmarco | 72.82 | 37.88 | 720\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2318843",
   "metadata": {},
   "source": [
    "Note: Runtime was computed on a V100 GPU.\n",
    "> The model introduction and model weights originate from [https://huggingface.co/cross-encoder/ms-marco-TinyBERT-L-2](https://huggingface.co/cross-encoder/ms-marco-TinyBERT-L-2) and were converted to PaddlePaddle format for ease of use in PaddleNLP.\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}