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 Lyon28 Electra-Small on huggingface.co
3
Total runs
0
24-hour runs
0
3-day runs
1
7-day runs
0
30-day runs
More Information About Electra-Small huggingface.co Model
Electra-Small huggingface.co is an AI model on huggingface.co that provides Electra-Small's model effect (), which can be used instantly with this Lyon28 Electra-Small model. huggingface.co supports a free trial of the Electra-Small model, and also provides paid use of the Electra-Small. Support call Electra-Small model through api, including Node.js, Python, http.
Electra-Small huggingface.co is an online trial and call api platform, which integrates Electra-Small's modeling effects, including api services, and provides a free online trial of Electra-Small, you can try Electra-Small online for free by clicking the link below.
Lyon28 Electra-Small online free url in huggingface.co:
Electra-Small is an open source model from GitHub that offers a free installation service, and any user can find Electra-Small on GitHub to install. At the same time, huggingface.co provides the effect of Electra-Small install, users can directly use Electra-Small installed effect in huggingface.co for debugging and trial. It also supports api for free installation.