All models

nezha

A Chinese BERT variant from Huawei with fixed sinusoidal relative position encoding and whole word masking.

Language · 570 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (18 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
101.9M
Operations
570
Framework
PyTorch
Recurrent
No
Published
2019
Cited by
155 (as of 29 November 2026)
Authors
Junqiu Wei, Xiaozhe Ren, Xiaoguang Li and others
License
Apache-2.0
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m7690
Graph hash
a2b232b5c7498ad1f86edd90e06d285ed8b01ac86eb70a6add2981c9f12047e1
Skeleton hash
0808088ced8703ac254996b39b13cf3ba396e81807e600b45d75a0cb39c09e9e
Architecture hash
4077d2a7c2fb32c87e257b0d15f7cb4feb54f9109d592870bcf3479bf3c00304
Diagram SHA-256
b553fac0e8c264575e07450d3ef6de836fa4ff26951513e9e751a4c95ac238d1
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

NEZHA, short for NEural contextualiZed representation for CHinese lAnguage understanding, is a pre-trained language model trained on Chinese corpora and finetuned for Chinese natural language understanding tasks. The current version is based on BERT with a collection of proven improvements, which include Functional Relative Positional Encoding, Whole Word Masking, Mixed Precision Training and the LAMB Optimizer. Attempts to train models specifically for Chinese before it included Google’s BERT for Chinese, ERNIE-Baidu and BERT-WWM.

BERT itself is a stack of Transformer encoders, each a multi-head self-attention layer followed by a position-wise feed-forward network. The signature change in NEZHA is functional relative positional encoding, which encodes the relative positions in self-attention by pre-defined functions without any trainable parameter. The computation of the outputs and attention scores involves sinusoidal functions of the relative position, an idea inspired by the functional absolute positional encoding of the original Transformer. The wavelengths form a geometric progression from 2π to 10000 · 2π, and the authors chose fixed sinusoids mainly because they may allow the model to extrapolate to sequence lengths longer than those seen in training. In whole word masking, once a Chinese character is masked, the other characters belonging to the same Chinese word are all masked together, with Jieba used for word segmentation.

NEZHA was pre-trained on three Chinese corpora, listed in the report as Wikipedia+Baike+News. Training ran on 10 servers on Huawei Cloud, each with 8 NVIDIA Tesla V100 GPUs with 32GB memory. Finetuning experiments covered named entity recognition on People’s Daily NER, sentence matching on LCQMC, Chinese sentiment classification on ChnSenti and natural language inference on XNLI. Among both the base and large groups, either ERNIE-Baidu 2.0 or NEZHA achieved the best performances. In the ablation, functional relative positional encoding showed a notable advantage compared with other positional encoding methods. The authors also caution that part of the results were copied from the original papers, so the comparison may not be entirely fair. On the Hugging Face Hub, the model card asks users to pair Bert tokenizer classes with Nezha model classes. The original checkpoints can be found in the huawei-noah Pretrained-Language-Model repository.

Key idea. NEZHA's distinctive technique is functional relative positional encoding, which encodes relative positions in self-attention with fixed sinusoidal functions and no trainable parameters, combined with whole word masking, mixed precision training and the LAMB optimizer on top of BERT.

  • nezha
  • neural contextualized representation for chinese language understanding
  • chinese pre-trained language model
  • functional relative positional encoding
  • frpe
  • whole word masking
  • wwm
  • lamb optimizer
  • mixed precision training
  • bert
  • huawei noah's ark lab
  • sijunhe/nezha-cn-base

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{wei2021nezhaneuralcontextualizedrepresentation,
      title={NEZHA: Neural Contextualized Representation for Chinese Language Understanding}, 
      author={Junqiu Wei and Xiaozhe Ren and Xiaoguang Li and Wenyong Huang and Yi Liao and Yasheng Wang and Jiashu Lin and Xin Jiang and Xiao Chen and Qun Liu},
      year={2021},
      eprint={1909.00204},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/1909.00204}, 
}