julien-c HF staff commited on
Commit
704a03e
1 Parent(s): 3cfad39

Migrate model card from transformers-repo

Browse files

Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/mrm8488/electricidad-small-discriminator/README.md

Files changed (1) hide show
  1. README.md +74 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: es
3
+ thumbnail: https://i.imgur.com/uxAvBfh.png
4
+
5
+
6
+ ---
7
+
8
+ ## ELECTRICIDAD: The Spanish Electra [Imgur](https://imgur.com/uxAvBfh)
9
+
10
+ **ELECTRICIDAD** is a small Electra like model (discriminator in this case) trained on a + 20 GB of the [OSCAR](https://oscar-corpus.com/) Spanish corpus.
11
+
12
+ As mentioned in the original [paper](https://openreview.net/pdf?id=r1xMH1BtvB):
13
+ **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.
14
+
15
+ For a detailed description and experimental results, please refer the paper [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://openreview.net/pdf?id=r1xMH1BtvB).
16
+
17
+ ## Model details ⚙
18
+
19
+ |Param| # Value|
20
+ |-----|--------|
21
+ |Layers| 12 |
22
+ |Hidden |256 |
23
+ |Params| 14M|
24
+
25
+ ## Evaluation metrics (for discriminator) 🧾
26
+
27
+ |Metric | # Score |
28
+ |-------|---------|
29
+ |Accuracy| 0.94|
30
+ |Precision| 0.76|
31
+ |AUC | 0.92|
32
+
33
+ ## Benchmarks 🔨
34
+
35
+ WIP 🚧
36
+
37
+ ## How to use the discriminator in `transformers`
38
+
39
+ ```python
40
+ from transformers import ElectraForPreTraining, ElectraTokenizerFast
41
+ import torch
42
+
43
+ discriminator = ElectraForPreTraining.from_pretrained("mrm8488/electricidad-small-discriminator")
44
+ tokenizer = ElectraTokenizerFast.from_pretrained("mrm8488/electricidad-small-discriminator")
45
+
46
+ sentence = "el zorro rojo es muy rápido"
47
+ fake_sentence = "el zorro rojo es muy ser"
48
+
49
+ fake_tokens = tokenizer.tokenize(sentence)
50
+ fake_inputs = tokenizer.encode(sentence, return_tensors="pt")
51
+ discriminator_outputs = discriminator(fake_inputs)
52
+ predictions = torch.round((torch.sign(discriminator_outputs[0]) + 1) / 2)
53
+
54
+ [print("%7s" % token, end="") for token in fake_tokens]
55
+
56
+ [print("%7s" % int(prediction), end="") for prediction in predictions.tolist()[1:-1]]
57
+
58
+ # Output:
59
+ '''
60
+ el zorro rojo es muy ser 0 0 0 0 0 1[None, None, None, None, None, None]
61
+ '''
62
+ ```
63
+
64
+ As you can see there is a **1** in the place where the model detected the fake token (**ser**). So, it works! 🎉
65
+
66
+ ## Acknowledgments
67
+
68
+ I thank [🤗/transformers team](https://github.com/huggingface/transformers) for answering my doubts and Google for helping me with the [TensorFlow Research Cloud](https://www.tensorflow.org/tfrc) program.
69
+
70
+
71
+
72
+ > Created by [Manuel Romero/@mrm8488](https://twitter.com/mrm8488)
73
+
74
+ > Made with <span style="color: #e25555;">&hearts;</span> in Spain