{ "cells": [ { "cell_type": "markdown", "id": "2d373572", "metadata": {}, "source": [ "# GPT-2\n", "\n", "You can get more details from [GPT2 in PaddleNLP](https://github.com/PaddlePaddle/PaddleNLP/blob/develop/model_zoo/gpt/README.md)." ] }, { "cell_type": "markdown", "id": "00be5831", "metadata": {}, "source": [ "Test the whole generation capabilities here: https://transformer.huggingface.co/doc/gpt2-large\n" ] }, { "cell_type": "markdown", "id": "b5857cc2", "metadata": {}, "source": [ "Pretrained model on English language using a causal language modeling (CLM) objective. It was introduced in\n", "[this paper](https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)\n", "and first released at [this page](https://openai.com/blog/better-language-models/).\n" ] }, { "cell_type": "markdown", "id": "b0abac76", "metadata": {}, "source": [ "Disclaimer: The team releasing GPT-2 also wrote a\n", "[model card](https://github.com/openai/gpt-2/blob/master/model_card.md) for their model. Content from this model card\n", "has been written by the Hugging Face team to complete the information they provided and give specific examples of bias.\n" ] }, { "cell_type": "markdown", "id": "fa2c7f4b", "metadata": {}, "source": [ "## Model description\n" ] }, { "cell_type": "markdown", "id": "294521bd", "metadata": {}, "source": [ "GPT-2 is a transformers model pretrained on a very large corpus of English data in a self-supervised fashion. This\n", "means it was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots\n", "of publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely,\n", "it was trained to guess the next word in sentences.\n" ] }, { "cell_type": "markdown", "id": "b1204c32", "metadata": {}, "source": [ "More precisely, inputs are sequences of continuous text of a certain length and the targets are the same sequence,\n", "shifted one token (word or piece of word) to the right. The model uses internally a mask-mechanism to make sure the\n", "predictions for the token `i` only uses the inputs from `1` to `i` but not the future tokens.\n" ] }, { "cell_type": "markdown", "id": "a019cc9e", "metadata": {}, "source": [ "This way, the model learns an inner representation of the English language that can then be used to extract features\n", "useful for downstream tasks. The model is best at what it was pretrained for however, which is generating texts from a\n", "prompt.\n" ] }, { "cell_type": "markdown", "id": "54ae8500", "metadata": {}, "source": [ "## How to use" ] }, { "cell_type": "code", "execution_count": null, "id": "d33fddda", "metadata": {}, "outputs": [], "source": [ "!pip install --upgrade paddlenlp" ] }, { "cell_type": "code", "execution_count": null, "id": "d0e160c6", "metadata": {}, "outputs": [], "source": [ "import paddle\n", "from paddlenlp.transformers import AutoModel\n", "\n", "model = AutoModel.from_pretrained(\"gpt2\")\n", "input_ids = paddle.randint(100, 200, shape=[1, 20])\n", "print(model(input_ids))" ] }, { "cell_type": "markdown", "id": "fcb8a843", "metadata": {}, "source": [ "## Citation\n", "\n", "```\n", "@article{radford2019language,\n", "title={Language Models are Unsupervised Multitask Learners},\n", "author={Radford, Alec and Wu, Jeff and Child, Rewon and Luan, David and Amodei, Dario and Sutskever, Ilya},\n", "year={2019}\n", "}\n", "```" ] }, { "cell_type": "markdown", "id": "513848f8", "metadata": {}, "source": [ "\n", "\n", "\n", "\n", "\n", "> The model introduction and model weights originate from [https://huggingface.co/gpt2](https://huggingface.co/gpt2) 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.7.13" } }, "nbformat": 4, "nbformat_minor": 5 }