electra large discriminator squad2 512
Overview
The ELECTRA-Large Discriminator, fine-tuned on SQuAD 2.0, is a specialized encoder model designed for high-precision extractive question answering. Unlike traditional BERT-based models that use masked language modeling, ELECTRA's replaced token detection pre-training allows it to learn more efficiently from the same amount of data, often resulting in superior performance on NLU benchmarks. This specific iteration supports a 512-token context window, making it suitable for analyzing medium-length documents to extract exact answer spans. For developers, this model is an ideal drop-in replacement for BERT-large in RAG pipelines or knowledge-base search tools where accuracy in identifying 'no-answer' scenarios (a key feature of SQuAD 2.0) is critical. It integrates seamlessly with the Hugging Face Transformers ecosystem, ensuring low friction for deployment in Python-based environments.
Highlights
- Optimized for extractive QA with SQuAD 2.0 fine-tuning
- Efficient replaced token detection for higher NLU accuracy
- Supports context windows up to 512 tokens
- Seamless integration via Hugging Face Transformers library
- Apache-2.0 license for flexible commercial deployment
Usage
Install
# Install Hugging Face transformers
pip install transformers torch
SDK Usage
# Load model with transformers
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("ahotrod/electra_large_discriminator_squad2_512")
tokenizer = AutoTokenizer.from_pretrained("ahotrod/electra_large_discriminator_squad2_512")
Hugging Face Download
We recommend downloading the model via the Hugging Face CLI or Hub SDK.
Guidance:Before downloading, install huggingface_hub with:
Guidance
pip install -U huggingface_hub
CLI Download
Download the full repository
Download the full repository
huggingface-cli download ahotrod/electra_large_discriminator_squad2_512
Download a single file to a local folder (e.g. config.json into ./dir)
Download a single file to a local folder (e.g. config.json into ./dir)
huggingface-cli download ahotrod/electra_large_discriminator_squad2_512 config.json --local-dir ./dir
See the official docs for more CLI options
SDK Download
SDK Download
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('ahotrod/electra_large_discriminator_squad2_512')
Git Download
Make sure git-lfs is installed first
Git Download
git lfs install
git clone https://huggingface.co/ahotrod/electra_large_discriminator_squad2_512
To skip LFS large-file downloads, use:
Skip LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/ahotrod/electra_large_discriminator_squad2_512
Model files are hosted on the Hugging Face Hub — download directly via HF CLI / SDK / Git, not through this site.
PyTorch / Transformers Usage
Install Transformers
Install Transformers
pip install -U transformers torch
Load the model and run inference
Load the model and run inference
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('ahotrod/electra_large_discriminator_squad2_512')
tokenizer = AutoTokenizer.from_pretrained('ahotrod/electra_large_discriminator_squad2_512')
Full Documentation
来源: HuggingFace
ELECTRA_large_discriminator language model fine-tuned on SQuAD2.0
with the following results:
code
"exact": 87.09677419354838,
"f1": 89.98343832723452,
"total": 11873,
"HasAns_exact": 84.66599190283401,
"HasAns_f1": 90.44759839056285,
"HasAns_total": 5928,
"NoAns_exact": 89.52060555088309,
"NoAns_f1": 89.52060555088309,
"NoAns_total": 5945,
"best_exact": 87.09677419354838,
"best_exact_thresh": 0.0,
"best_f1": 89.98343832723432,
"best_f1_thresh": 0.0from script:
code
python ${EXAMPLES}/run_squad.py \
--model_type electra \
--model_name_or_path google/electra-large-discriminator \
--do_train \
--do_eval \
--train_file ${SQUAD}/train-v2.0.json \
--predict_file ${SQUAD}/dev-v2.0.json \
--version_2_with_negative \
--do_lower_case \
--num_train_epochs 3 \
--warmup_steps 306 \
--weight_decay 0.01 \
--learning_rate 3e-5 \
--max_grad_norm 0.5 \
--adam_epsilon 1e-6 \
--max_seq_length 512 \
--doc_stride 128 \
--per_gpu_train_batch_size 8 \
--gradient_accumulation_steps 16 \
--per_gpu_eval_batch_size 128 \
--fp16 \
--fp16_opt_level O1 \
--threads 12 \
--logging_steps 50 \
--save_steps 1000 \
--overwrite_output_dir \
--output_dir ${MODEL_PATH}using the following system & software:
code
Transformers: 2.11.0
PyTorch: 1.5.0
TensorFlow: 2.2.0
Python: 3.8.1
OS/Platform: Linux-5.3.0-59-generic-x86_64-with-glibc2.10
CPU/GPU: Intel i9-9900K / NVIDIA Titan RTX 24GB