From 39a34cc375ed79d18888464289b83713fc20f7d4 Mon Sep 17 00:00:00 2001 From: Julien Chaumond Date: Mon, 6 Apr 2020 11:43:33 -0400 Subject: [PATCH] [model_cards] ELECTRA (w/ examples of usage) Co-Authored-By: Kevin Clark Co-Authored-By: Lysandre Debut --- .../electra-base-discriminator/README.md | 34 +++++++++++++++++++ .../google/electra-base-generator/README.md | 29 ++++++++++++++++ .../electra-large-discriminator/README.md | 34 +++++++++++++++++++ .../google/electra-large-generator/README.md | 29 ++++++++++++++++ .../electra-small-discriminator/README.md | 34 +++++++++++++++++++ .../google/electra-small-generator/README.md | 29 ++++++++++++++++ 6 files changed, 189 insertions(+) create mode 100644 model_cards/google/electra-base-discriminator/README.md create mode 100644 model_cards/google/electra-base-generator/README.md create mode 100644 model_cards/google/electra-large-discriminator/README.md create mode 100644 model_cards/google/electra-large-generator/README.md create mode 100644 model_cards/google/electra-small-discriminator/README.md create mode 100644 model_cards/google/electra-small-generator/README.md diff --git a/model_cards/google/electra-base-discriminator/README.md b/model_cards/google/electra-base-discriminator/README.md new file mode 100644 index 0000000000..06de5a4d41 --- /dev/null +++ b/model_cards/google/electra-base-discriminator/README.md @@ -0,0 +1,34 @@ +--- +language: english +thumbnail: https://huggingface.co/front/thumbnails/google.png +--- + +## ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators + +**ELECTRA** is a new method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). At small scale, ELECTRA achieves strong results even when trained on a single GPU. At large scale, ELECTRA achieves state-of-the-art results on the [SQuAD 2.0](https://rajpurkar.github.io/SQuAD-explorer/) dataset. + +For a detailed description and experimental results, please refer to our paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB). + +This repository contains code to pre-train ELECTRA, including small ELECTRA models on a single GPU. It also supports fine-tuning ELECTRA on downstream tasks including classification tasks (e.g,. [GLUE](https://gluebenchmark.com/)), QA tasks (e.g., [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)), and sequence tagging tasks (e.g., [text chunking](https://www.clips.uantwerpen.be/conll2000/chunking/)). + +## How to use the discriminator in `transformers` + +```python +from transformers import ElectraForPreTraining, ElectraTokenizerFast +import torch + +discriminator = ElectraForPreTraining.from_pretrained("google/electra-base-discriminator") +tokenizer = ElectraTokenizerFast.from_pretrained("google/electra-base-discriminator") + +sentence = "The quick brown fox jumps over the lazy dog" +fake_sentence = "The quick brown fox fake over the lazy dog" + +fake_tokens = tokenizer.tokenize(fake_sentence) +fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt") +discriminator_outputs = discriminator(fake_inputs) +predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2) + +[print("%7s" % token, end="") for token in fake_tokens] + +[print("%7s" % int(prediction), end="") for prediction in predictions.tolist()] +``` diff --git a/model_cards/google/electra-base-generator/README.md b/model_cards/google/electra-base-generator/README.md new file mode 100644 index 0000000000..ed6d7be648 --- /dev/null +++ b/model_cards/google/electra-base-generator/README.md @@ -0,0 +1,29 @@ +--- +language: english +thumbnail: https://huggingface.co/front/thumbnails/google.png +--- + +## ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators + +**ELECTRA** is a new method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). At small scale, ELECTRA achieves strong results even when trained on a single GPU. At large scale, ELECTRA achieves state-of-the-art results on the [SQuAD 2.0](https://rajpurkar.github.io/SQuAD-explorer/) dataset. + +For a detailed description and experimental results, please refer to our paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB). + +This repository contains code to pre-train ELECTRA, including small ELECTRA models on a single GPU. It also supports fine-tuning ELECTRA on downstream tasks including classification tasks (e.g,. [GLUE](https://gluebenchmark.com/)), QA tasks (e.g., [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)), and sequence tagging tasks (e.g., [text chunking](https://www.clips.uantwerpen.be/conll2000/chunking/)). + +## How to use the generator in `transformers` + +```python +from transformers import pipeline + +fill_mask = pipeline( + "fill-mask", + model="google/electra-base-generator", + tokenizer="google/electra-base-generator" +) + +print( + fill_mask(f"HuggingFace is creating a {nlp.tokenizer.mask_token} that the community uses to solve NLP tasks.") +) + +``` diff --git a/model_cards/google/electra-large-discriminator/README.md b/model_cards/google/electra-large-discriminator/README.md new file mode 100644 index 0000000000..efdc1020a1 --- /dev/null +++ b/model_cards/google/electra-large-discriminator/README.md @@ -0,0 +1,34 @@ +--- +language: english +thumbnail: https://huggingface.co/front/thumbnails/google.png +--- + +## ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators + +**ELECTRA** is a new method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). At small scale, ELECTRA achieves strong results even when trained on a single GPU. At large scale, ELECTRA achieves state-of-the-art results on the [SQuAD 2.0](https://rajpurkar.github.io/SQuAD-explorer/) dataset. + +For a detailed description and experimental results, please refer to our paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB). + +This repository contains code to pre-train ELECTRA, including small ELECTRA models on a single GPU. It also supports fine-tuning ELECTRA on downstream tasks including classification tasks (e.g,. [GLUE](https://gluebenchmark.com/)), QA tasks (e.g., [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)), and sequence tagging tasks (e.g., [text chunking](https://www.clips.uantwerpen.be/conll2000/chunking/)). + +## How to use the discriminator in `transformers` + +```python +from transformers import ElectraForPreTraining, ElectraTokenizerFast +import torch + +discriminator = ElectraForPreTraining.from_pretrained("google/electra-large-discriminator") +tokenizer = ElectraTokenizerFast.from_pretrained("google/electra-large-discriminator") + +sentence = "The quick brown fox jumps over the lazy dog" +fake_sentence = "The quick brown fox fake over the lazy dog" + +fake_tokens = tokenizer.tokenize(fake_sentence) +fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt") +discriminator_outputs = discriminator(fake_inputs) +predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2) + +[print("%7s" % token, end="") for token in fake_tokens] + +[print("%7s" % int(prediction), end="") for prediction in predictions.tolist()] +``` diff --git a/model_cards/google/electra-large-generator/README.md b/model_cards/google/electra-large-generator/README.md new file mode 100644 index 0000000000..34812aa109 --- /dev/null +++ b/model_cards/google/electra-large-generator/README.md @@ -0,0 +1,29 @@ +--- +language: english +thumbnail: https://huggingface.co/front/thumbnails/google.png +--- + +## ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators + +**ELECTRA** is a new method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). At small scale, ELECTRA achieves strong results even when trained on a single GPU. At large scale, ELECTRA achieves state-of-the-art results on the [SQuAD 2.0](https://rajpurkar.github.io/SQuAD-explorer/) dataset. + +For a detailed description and experimental results, please refer to our paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB). + +This repository contains code to pre-train ELECTRA, including small ELECTRA models on a single GPU. It also supports fine-tuning ELECTRA on downstream tasks including classification tasks (e.g,. [GLUE](https://gluebenchmark.com/)), QA tasks (e.g., [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)), and sequence tagging tasks (e.g., [text chunking](https://www.clips.uantwerpen.be/conll2000/chunking/)). + +## How to use the generator in `transformers` + +```python +from transformers import pipeline + +fill_mask = pipeline( + "fill-mask", + model="google/electra-large-generator", + tokenizer="google/electra-large-generator" +) + +print( + fill_mask(f"HuggingFace is creating a {nlp.tokenizer.mask_token} that the community uses to solve NLP tasks.") +) + +``` diff --git a/model_cards/google/electra-small-discriminator/README.md b/model_cards/google/electra-small-discriminator/README.md new file mode 100644 index 0000000000..ae9097ebfb --- /dev/null +++ b/model_cards/google/electra-small-discriminator/README.md @@ -0,0 +1,34 @@ +--- +language: english +thumbnail: https://huggingface.co/front/thumbnails/google.png +--- + +## ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators + +**ELECTRA** is a new method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). At small scale, ELECTRA achieves strong results even when trained on a single GPU. At large scale, ELECTRA achieves state-of-the-art results on the [SQuAD 2.0](https://rajpurkar.github.io/SQuAD-explorer/) dataset. + +For a detailed description and experimental results, please refer to our paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB). + +This repository contains code to pre-train ELECTRA, including small ELECTRA models on a single GPU. It also supports fine-tuning ELECTRA on downstream tasks including classification tasks (e.g,. [GLUE](https://gluebenchmark.com/)), QA tasks (e.g., [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)), and sequence tagging tasks (e.g., [text chunking](https://www.clips.uantwerpen.be/conll2000/chunking/)). + +## How to use the discriminator in `transformers` + +```python +from transformers import ElectraForPreTraining, ElectraTokenizerFast +import torch + +discriminator = ElectraForPreTraining.from_pretrained("google/electra-small-discriminator") +tokenizer = ElectraTokenizerFast.from_pretrained("google/electra-small-discriminator") + +sentence = "The quick brown fox jumps over the lazy dog" +fake_sentence = "The quick brown fox fake over the lazy dog" + +fake_tokens = tokenizer.tokenize(fake_sentence) +fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt") +discriminator_outputs = discriminator(fake_inputs) +predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2) + +[print("%7s" % token, end="") for token in fake_tokens] + +[print("%7s" % int(prediction), end="") for prediction in predictions.tolist()] +``` diff --git a/model_cards/google/electra-small-generator/README.md b/model_cards/google/electra-small-generator/README.md new file mode 100644 index 0000000000..c6cc1a851b --- /dev/null +++ b/model_cards/google/electra-small-generator/README.md @@ -0,0 +1,29 @@ +--- +language: english +thumbnail: https://huggingface.co/front/thumbnails/google.png +--- + +## ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators + +**ELECTRA** is a new method for self-supervised language representation learning. It can be used to pre-train transformer networks using relatively little compute. ELECTRA models are trained to distinguish "real" input tokens vs "fake" input tokens generated by another neural network, similar to the discriminator of a [GAN](https://arxiv.org/pdf/1406.2661.pdf). At small scale, ELECTRA achieves strong results even when trained on a single GPU. At large scale, ELECTRA achieves state-of-the-art results on the [SQuAD 2.0](https://rajpurkar.github.io/SQuAD-explorer/) dataset. + +For a detailed description and experimental results, please refer to our paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB). + +This repository contains code to pre-train ELECTRA, including small ELECTRA models on a single GPU. It also supports fine-tuning ELECTRA on downstream tasks including classification tasks (e.g,. [GLUE](https://gluebenchmark.com/)), QA tasks (e.g., [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/)), and sequence tagging tasks (e.g., [text chunking](https://www.clips.uantwerpen.be/conll2000/chunking/)). + +## How to use the generator in `transformers` + +```python +from transformers import pipeline + +fill_mask = pipeline( + "fill-mask", + model="google/electra-small-generator", + tokenizer="google/electra-small-generator" +) + +print( + fill_mask(f"HuggingFace is creating a {nlp.tokenizer.mask_token} that the community uses to solve NLP tasks.") +) + +```