Electricidad-base-discriminator (uncased) is a
base Electra like model (discriminator in this case) trained on a
Large Spanish Corpus (aka BETO's corpus)
As mentioned in the original
paper:
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.
For a detailed description and experimental results, please refer the paper
ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators.
1from transformers import ElectraForPreTraining, ElectraTokenizerFast
2import torch
3
4discriminator = ElectraForPreTraining.from_pretrained("mrm8488/electricidad-base-discriminator")
5tokenizer = ElectraTokenizerFast.from_pretrained("mrm8488/electricidad-base-discriminator")
6
7sentence = "El rápido zorro marrón salta sobre el perro perezoso"
8fake_sentence = "El rápido zorro marrón amar sobre el perro perezoso"
9
10fake_tokens = tokenizer.tokenize(fake_sentence)
11fake_inputs = tokenizer.encode(fake_sentence, return_tensors="pt")
12discriminator_outputs = discriminator(fake_inputs)
13predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2)
14
15[print("%7s" % token, end="") for token in fake_tokens]
16
17[print("%7s" % prediction, end="") for prediction in predictions.tolist()]
18
19# Output:
20'''
21el rapido zorro marro ##n amar sobre el perro pere ##zoso 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0[None, None, None, None, None, None, None, None, None, None, None, None, None
22'''
I thank
🤗/transformers team for allowing me to train the model (specially to
Julien Chaumond).
1@misc{mromero2020electricidad-base-discriminator,
2 title={Spanish Electra by Manuel Romero},
3 author={Romero, Manuel},
4 publisher={Hugging Face},
5 journal={Hugging Face Hub},
6 howpublished={\url{https://huggingface.co/mrm8488/electricidad-base-discriminator/}},
7 year={2020}
8}