mdeberta v3 base

Providermicrosoft
Categoryfill-mask
Licensemit
Downloads1.0K
Stars2

Overview

mdeberta-v3-base is a refined encoder-only transformer that optimizes the DeBERTa architecture for superior performance on NLU tasks. Unlike standard BERT models, it utilizes a disentangled attention mechanism and an enhanced masked language modeling (MLM) objective, specifically replacing token masking with replaced token detection (RTD). For developers, this means significantly better accuracy on benchmarks like GLUE and SuperGLUE without increasing the computational footprint. It is an ideal drop-in replacement for those building classifiers, named entity recognition (NER) systems, or semantic similarity tools who require high precision in a base-sized model. Integration is straightforward via the Hugging Face Transformers library, maintaining compatibility with existing PyTorch and TensorFlow pipelines.

Highlights

  • Enhanced RTD objective for superior linguistic understanding
  • Disentangled attention improves performance on NLU benchmarks
  • Efficient base-sized footprint for low-latency inference
  • Seamless integration with Hugging Face Transformers library
  • MIT license ensures 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("microsoft/mdeberta-v3-base")
tokenizer = AutoTokenizer.from_pretrained("microsoft/mdeberta-v3-base")

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 microsoft/mdeberta-v3-base

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 microsoft/mdeberta-v3-base 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('microsoft/mdeberta-v3-base')

Git Download

Make sure git-lfs is installed first

Git Download
git lfs install
git clone https://huggingface.co/microsoft/mdeberta-v3-base

To skip LFS large-file downloads, use:

Skip LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/microsoft/mdeberta-v3-base

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('microsoft/mdeberta-v3-base')
tokenizer = AutoTokenizer.from_pretrained('microsoft/mdeberta-v3-base')

Model Download

We recommend downloading the model via the ModelScope CLI or SDK.

Guidance:Before downloading, install ModelScope with:

Guidance
pip install modelscope

CLI Download

Download the full repository

Download the full repository
modelscope download --model microsoft/mdeberta-v3-base

Download a single file to a local folder (e.g. README.md into ./dir)

Download a single file to a local folder (e.g. README.md into ./dir)
modelscope download --model microsoft/mdeberta-v3-base README.md --local_dir ./dir

See the docs for more CLI options

SDK Download

SDK Download
# 模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('microsoft/mdeberta-v3-base')

Git Download

Make sure git-lfs is installed first

Git Download
git lfs install
git clone https://www.modelscope.cn/microsoft/mdeberta-v3-base.git

To skip LFS large-file downloads, use:

Skip LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/microsoft/mdeberta-v3-base.git

ModelScope 模型页直接下载模型文件;无需将模型文件放在本站服务器。

Notebook Quickstart

Install the ModelScope library

Install the ModelScope library
pip install "modelscope[audio,cv,nlp,multi-modal,science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

Load the model and run inference

Load the model and run inference
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

p = pipeline('text-generation', 'microsoft/mdeberta-v3-base')

Full Documentation

来源: HuggingFace

---
language:

  • multilingual

  • en

  • ar

  • bg

  • de

  • el

  • es

  • fr

  • hi

  • ru

  • sw

  • th

  • tr

  • ur

  • vi

  • zh

tags:
- deberta
- deberta-v3
- mdeberta
- fill-mask
thumbnail: https://huggingface.co/front/thumbnails/microsoft.png
license: mit
---

DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing

DeBERTa improves the BERT and RoBERTa models using disentangled attention and enhanced mask decoder. With those two improvements, DeBERTa out perform RoBERTa on a majority of NLU tasks with 80GB training data.

In DeBERTa V3, we further improved the efficiency of DeBERTa using ELECTRA-Style pre-training with Gradient Disentangled Embedding Sharing. Compared to DeBERTa, our V3 version significantly improves the model performance on downstream tasks. You can find more technique details about the new model from our paper.

Please check the official repository for more implementation details and updates.

mDeBERTa is multilingual version of DeBERTa which use the same structure as DeBERTa and was trained with CC100 multilingual data.
The mDeBERTa V3 base model comes with 12 layers and a hidden size of 768. It has 86M backbone parameters with a vocabulary containing 250K tokens which introduces 190M parameters in the Embedding layer. This model was trained using the 2.5T CC100 data as XLM-R.

#### Fine-tuning on NLU tasks

We present the dev results on XNLI with zero-shot cross-lingual transfer setting, i.e. training with English data only, test on other languages.

| Model |avg | en | fr| es | de | el | bg | ru |tr |ar |vi | th | zh | hi | sw | ur |
|--------------| ----|----|----|---- |-- |-- |-- | -- |-- |-- |-- | -- | -- | -- | -- | -- |
| XLM-R-base |76.2 |85.8|79.7|80.7 |78.7 |77.5 |79.6 |78.1 |74.2 |73.8 |76.5 |74.6 |76.7| 72.4| 66.5| 68.3|
| mDeBERTa-base|79.8+/-0.2|88.2|82.6|84.4 |82.7 |82.3 |82.4 |80.8 |79.5 |78.5 |78.1 |76.4 |79.5| 75.9| 73.9| 72.4|

#### Fine-tuning with HF transformers

bash
#!/bin/bash

cd transformers/examples/pytorch/text-classification/

pip install datasets

output_dir="ds_results"

num_gpus=8

batch_size=4

python -m torch.distributed.launch --nproc_per_node=${num_gpus} \
run_xnli.py \
--model_name_or_path microsoft/mdeberta-v3-base \
--task_name $TASK_NAME \
--do_train \
--do_eval \
--train_language en \
--language en \
--evaluation_strategy steps \
--max_seq_length 256 \
--warmup_steps 3000 \
--per_device_train_batch_size ${batch_size} \
--learning_rate 2e-5 \
--num_train_epochs 6 \
--output_dir $output_dir \
--overwrite_output_dir \
--logging_steps 1000 \
--logging_dir $output_dir

Citation

If you find DeBERTa useful for your work, please cite the following papers:

`` latex
@misc{he2021debertav3,
title={DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing},
author={Pengcheng He and Jianfeng Gao and Weizhu Chen},
year={2021},
eprint={2111.09543},
archivePrefix={arXiv},
primaryClass={cs.CL}
}

code
latex
@inproceedings{
he2021deberta,
title={DEBERTA: DECODING-ENHANCED BERT WITH DISENTANGLED ATTENTION},
author={Pengcheng He and Xiaodong Liu and Jianfeng Gao and Weizhu Chen},
booktitle={International Conference on Learning Representations},
year={2021},
url={https://openreview.net/forum?id=XPZIaotutsD}
}
``

Join our Telegram