introduction_cn.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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4e448d86",
   "metadata": {},
   "source": [
    "# 🤗 + 📚 dbmdz BERT and ELECTRA models\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bcf089b",
   "metadata": {},
   "source": [
    "In this repository the MDZ Digital Library team (dbmdz) at the Bavarian State\n",
    "Library open sources Italian BERT and ELECTRA models 🎉\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb9adbdd",
   "metadata": {},
   "source": [
    "# Italian BERT\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5a80c49",
   "metadata": {},
   "source": [
    "The source data for the Italian BERT model consists of a recent Wikipedia dump and\n",
    "various texts from the [OPUS corpora](http://opus.nlpl.eu/) collection. The final\n",
    "training corpus has a size of 13GB and 2,050,057,573 tokens.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3513aa96",
   "metadata": {},
   "source": [
    "For sentence splitting, we use NLTK (faster compared to spacy).\n",
    "Our cased and uncased models are training with an initial sequence length of 512\n",
    "subwords for ~2-3M steps.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca0e58ee",
   "metadata": {},
   "source": [
    "For the XXL Italian models, we use the same training data from OPUS and extend\n",
    "it with data from the Italian part of the [OSCAR corpus](https://traces1.inria.fr/oscar/).\n",
    "Thus, the final training corpus has a size of 81GB and 13,138,379,147 tokens.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "744e0851",
   "metadata": {},
   "source": [
    "Note: Unfortunately, a wrong vocab size was used when training the XXL models.\n",
    "This explains the mismatch of the \"real\" vocab size of 31102, compared to the\n",
    "vocab size specified in `config.json`. However, the model is working and all\n",
    "evaluations were done under those circumstances.\n",
    "See [this issue](https://github.com/dbmdz/berts/issues/7) for more information.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3bb28396",
   "metadata": {},
   "source": [
    "The Italian ELECTRA model was trained on the \"XXL\" corpus for 1M steps in total using a batch\n",
    "size of 128. We pretty much following the ELECTRA training procedure as used for\n",
    "[BERTurk](https://github.com/stefan-it/turkish-bert/tree/master/electra).\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c0c2ecb",
   "metadata": {},
   "source": [
    "## Usage\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e059cf91",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install --upgrade paddlenlp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95a883f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import paddle\n",
    "from paddlenlp.transformers import AutoModel\n",
    "\n",
    "model = AutoModel.from_pretrained(\"dbmdz/bert-base-italian-xxl-cased\")\n",
    "input_ids = paddle.randint(100, 200, shape=[1, 20])\n",
    "print(model(input_ids))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6b2c856e",
   "metadata": {},
   "source": [
    "# Reference"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffdf7223",
   "metadata": {},
   "source": [
    "> 此模型介绍及权重来源于[https://huggingface.co/dbmdz/bert-base-italian-xxl-cased](https://huggingface.co/dbmdz/bert-base-italian-xxl-cased),并转换为飞桨模型格式。\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.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}