---
title: electra-small-discriminator
canonical_url: "https://www.modelscope.cn/models/google/electra-small-discriminator"
md_url: "https://www.modelscope.cn/models/google/electra-small-discriminator.md"
repository: google/electra-small-discriminator
last_updated: 2025-04-21
license: apache-2.0
model_type:
  - electra
architectures:
  - ElectraForPreTraining
library_name:
  - pytorch
  - transformer
  - tensorflow
frameworks:
  - pytorch
language:
  - en
downloads: 674
stars: 0
---

# electra-small-discriminator

> electra-small-discriminator - google 在 ModelScope 开源的模型。ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators

google/electra-small-discriminator 是 ModelScope 魔搭社区上的机器学习模型，采用 apache-2.0 许可。

- **Repository**: google/electra-small-discriminator
- **License**: apache-2.0
- **Downloads**: 674
- **Stars**: 0
- **Last updated**: 2025-04-21

Source: https://www.modelscope.cn/models/google/electra-small-discriminator

---

## 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.squeeze().tolist()]
```
