Skip to main content
Back

text2vec-base-chinese Runs 4.78x Faster on CPU Without Losing Accuracy

A widely used Chinese sentence embedding model now ships ONNX and OpenVINO backends, delivering up to 4.78x faster CPU inference with minimal accuracy loss.

Pro

  • text2vec-base-chinese now ships optimized ONNX and OpenVINO inference backends via sentence-transformers
  • ONNX O4 preserves fp32 accuracy and gives roughly 2x GPU speedup on the same weights
  • OpenVINO int8 quantization reaches 4.78x CPU speedup with only fractional accuracy shifts
  • Base model uses CoSENT ranking loss on hfl/chinese-macbert-base, outputs 768 dim vectors
  • Scores 51.61 average Spearman across the standard Chinese matching benchmarks at 3008 QPS
  • Full details on the Hugging Face model card and text2vec GitHub repo

If you build search, RAG, or clustering pipelines for Chinese text, there's a good chance you've already touched shibing624/text2vec-base-chinese. It's a 100M parameter CoSENT model that maps Chinese sentences into a 768 dimensional vector space, and it has quietly become one of the default embedding backbones for Chinese NLP. The model card was recently expanded with a set of optimized inference backends, including ONNX with O4 graph optimization, OpenVINO for CPU, and an int8 quantized variant, all callable through sentence-transformers.

The headline here is throughput. The same weights now run meaningfully faster on the hardware most teams actually deploy on, without giving up much of the benchmark performance that made the model popular in the first place.

What CoSENT actually does

The base model is trained with CoSENT (Cosine Sentence), a contrastive objective that improves on Sentence-BERT by using a ranking loss over cosine similarities. The training recipe computes cosine similarity from each possible sentence pair in the batch, then applies a rank loss comparing true and false pairs. In practice this means the training signal is closer to how you actually use the model at inference: rank candidates by cosine similarity to a query.

The starting point is hfl/chinese-macbert-base, fine-tuned on shibing624/nli_zh with max sequence length 128, best epoch of 5, and a sentence embedding dimension of 768. Inputs longer than 256 word pieces get truncated, so this is a sentence and short paragraph encoder, not a long document model.

The numbers that matter

On the standard Chinese text matching suite, the base model lands in a competitive middle spot. Measured by Spearman correlation across ATEC, BQ, LCQMC, PAWSX, STS-B and two SOHU splits, shibing624/text2vec-base-chinese scores 51.61 average with roughly 3008 QPS, sitting behind the author's own paraphrase variant but ahead of the multilingual MiniLM baseline. If you need higher accuracy on sentence to paragraph tasks, the text2vec-base-chinese-paraphrase model reaches a 63.08 average by adding s2p data on top of an ERNIE 3.0 base, which is worth knowing before you default to the base checkpoint.

Faster inference without losing accuracy

The model card now documents three optimized variants alongside the fp32 baseline:

  • ONNX Optimized at O4 preserves the baseline scores exactly and delivers roughly a 2x speedup on GPU.
  • OpenVINO also matches baseline scores and gives a 1.12x speedup on CPU.
  • The OpenVINO int8 quantized version, calibrated on Chinese STSB, shows a small hit on some tasks and a tiny gain on others, while reaching a 4.78x CPU speedup.

The quantization tradeoffs are concrete rather than hand waved. The ov-qint8 variant shifts ATEC from 0.31928 to 0.30778 (-3.60%), BQ from 0.42672 to 0.43474 (+1.88%), LCQMC from 0.70157 to 0.69620 (-0.77%), PAWSX from 0.17214 to 0.16662 (-3.20%), and STS-B from 0.79296 to 0.79396 (+0.13%). For a lot of retrieval workloads where recall at top-k matters more than a fractional Spearman point, that's a comfortable tradeoff for nearly 5x throughput on CPU.

Calling the fast backends

The optimized paths are a backend argument in sentence-transformers. Nothing else in your pipeline changes.

from sentence_transformers import SentenceTransformer
# ONNX O4 on GPU
model = SentenceTransformer(
    "shibing624/text2vec-base-chinese",
    backend="onnx",
    model_kwargs={"file_name": "model_O4.onnx"},
)
# OpenVINO int8 on CPU
model = SentenceTransformer(
    "shibing624/text2vec-base-chinese",
    backend="onnx",
    model_kwargs={"file_name": "model_qint8_avx512_vnni.onnx"},
)
embeddings = model.encode(["如何更换花呗绑定银行卡", "花呗更改绑定银行卡"])

The int8 file name signals what it targets: AVX512 with VNNI instructions. If you deploy on modern Intel CPUs, this is where the 4.78x number comes from. On older CPUs you'll still get a speedup, just not that one.

Where it fits, and where it doesn't

The intended use cases are the obvious ones for a dense encoder: producing vectors that capture semantic information for information retrieval, clustering, or sentence similarity. That covers:

  • Chinese semantic search and FAQ retrieval
  • Deduplication and clustering of user messages, tickets, or documents
  • Retrieval augmented generation over Chinese corpora
  • Near duplicate detection for content pipelines

The weak spots are worth being honest about. PAWSX scores stay low across every variant on the leaderboard, which reflects the model's difficulty with adversarial paraphrases where word order flips the meaning. For sentence to paragraph matching the base checkpoint underperforms the paraphrase variant by more than 10 points on average. And because inputs are truncated past 256 word pieces, this is the wrong tool for long document embedding. Multilingual workloads should reach for text2vec-base-multilingual instead.

The broader library it plugs into

The model is one output of the text2vec toolkit, which packages Word2Vec, Sentence-BERT, CoSENT, and BGE style training into a single pip installable library. Version 1.2.9 added multi GPU and multi CPU inference through multi process execution, plus a CLI for batch text vectorization from a script. For teams that want to fine tune on their own Chinese data, the training scripts accept either 0/1 binary labels or 0-5 similarity scores, which makes it straightforward to adapt to domain specific matching datasets.

The practical takeaway: if you're already using this model, swapping to the ONNX or OpenVINO backend is a one line change with real throughput gains. If you haven't picked a Chinese embedding model yet, the combination of Apache 2.0 licensing, deployment ready backends, and a well documented benchmark table makes it a reasonable default to test against BGE and M3E for your specific retrieval task.