introduction_en.ipynb 4.3 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
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "366980e6",
   "metadata": {},
   "source": [
    "# Cross-Encoder for MS Marco\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c7d726e",
   "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": "1535e90f",
   "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": "3eda3140",
   "metadata": {},
   "source": [
    "## How to use\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74d5bcd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install --upgrade paddlenlp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59553cde",
   "metadata": {},
   "outputs": [],
   "source": [
    "import paddle\n",
53
    "from paddlenlp.transformers import BertForSequenceClassification\n",
54
    "\n",
55
    "model = BertForSequenceClassification.from_pretrained(\"cross-encoder/ms-marco-MiniLM-L-12-v2\")\n",
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    "input_ids = paddle.randint(100, 200, shape=[1, 20])\n",
    "print(model(input_ids))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b6883fa",
   "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": "e04ad9db",
   "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": "18e7124d",
   "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-MiniLM-L-12-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L-12-v2) and were converted to PaddlePaddle format for ease of use in PaddleNLP.\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}