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
. 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
dataset.
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
), QA tasks (e.g.,
SQuAD
), and sequence tagging tasks (e.g.,
text chunking
).
How to use the discriminator in
transformers
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.squeeze().tolist()]
Runs of google electra-small-discriminator on huggingface.co
222.9K
Total runs
0
24-hour runs
-1.3K
3-day runs
-13.9K
7-day runs
22.4K
30-day runs
More Information About electra-small-discriminator huggingface.co Model
More electra-small-discriminator license Visit here:
electra-small-discriminator huggingface.co is an AI model on huggingface.co that provides electra-small-discriminator's model effect (), which can be used instantly with this google electra-small-discriminator model. huggingface.co supports a free trial of the electra-small-discriminator model, and also provides paid use of the electra-small-discriminator. Support call electra-small-discriminator model through api, including Node.js, Python, http.
electra-small-discriminator huggingface.co is an online trial and call api platform, which integrates electra-small-discriminator's modeling effects, including api services, and provides a free online trial of electra-small-discriminator, you can try electra-small-discriminator online for free by clicking the link below.
google electra-small-discriminator online free url in huggingface.co:
electra-small-discriminator is an open source model from GitHub that offers a free installation service, and any user can find electra-small-discriminator on GitHub to install. At the same time, huggingface.co provides the effect of electra-small-discriminator install, users can directly use electra-small-discriminator installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
electra-small-discriminator install url in huggingface.co: