Downloads · 30 days
8
3% of all-time downloads
zilliz/semantic-highlight-bilingual-pre
semantic-highlight-bilingual-pre is a machine learning model from zilliz. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
We have released the official v1 version, which has better performance. This model will be taken offline.
Downloads · 30 days
8
3% of all-time downloads
All-time downloads
253
Public
Parameters
568M
2.3 GB on disk
Likes
5
Public
Click a slice to open those files.
.safetensors2.3 GB · 99%
From the Hugging Face model README
We have released the official v1 version, which has better performance. This model will be taken offline.
Traditional search highlighting works by matching keywords. When you search for "iPhone performance" on an e-commerce site, only the words "iPhone" and "performance" get highlighted in the results. But what if the product description says "Powered by A15 Bionic chip, scores over 1 million in benchmarks, smooth performance with no lag"? This clearly answers the performance question, yet nothing gets highlighted because it doesn't contain the exact word "performance".
Semantic Highlight solves this problem by understanding meaning, not just matching words. It highlights text segments that are semantically relevant to your query, even if they don't contain the exact keywords. This is crucial in RAG (Retrieval-Augmented Generation) scenarios where users need to quickly identify relevant information in long retrieved documents.
Highlighting happens on every search query - it needs to be fast and cost-effective. Large language models would be too slow and expensive for this real-time task. This model is designed to be:
pip install transformers torch
from transformers import AutoModel
model = AutoModel.from_pretrained(
"Zilliz/semantic-highlight-bilingual-pre",
trust_remote_code=True
)
question = "What are the symptoms of dehydration?"
context = """
Dehydration occurs when your body loses more fluid than you take in.
Common signs include feeling thirsty and having a dry mouth.
The human body is composed of about 60% water.
Dark yellow urine and infrequent urination are warning signs.
Water is essential for many bodily functions.
Dizziness, fatigue, and headaches can indicate severe dehydration.
Drinking 8 glasses of water daily is often recommended.
"""
result = model.process(
question=question,
context=context,
threshold=0.5,
language="en",
)
print("Relevant sentences:")
print(result["pruned_context"])
# Output: Only the 3 sentences describing actual symptoms
# - "Common signs include feeling thirsty and having a dry mouth."
# - "Dark yellow urine and infrequent urination are warning signs."
# - "Dizziness, fatigue, and headaches can indicate severe dehydration."
from transformers import AutoModel
model = AutoModel.from_pretrained(
"Zilliz/semantic-highlight-bilingual-pre",
trust_remote_code=True
)
question = "北京有什么好吃的?"
context = """
北京烤鸭是北京最著名的特色美食,皮酥肉嫩,配上薄饼和甜面酱。
故宫是明清两代的皇家宫殿,也是世界上现存规模最大的木质结构古建筑群。
炸酱面是北京的传统面食,用黄酱配上黄瓜丝和豆芽菜。
长城是中国古代的军事防御工程,绵延数千公里。
老北京涮羊肉以铜锅为特色,羊肉鲜嫩,蘸料丰富。
天坛是明清两代皇帝祭天的场所,建筑精美。
豆汁儿是北京独特的传统小吃,口味特别,配上焦圈最地道。
颐和园是清朝的皇家园林,以昆明湖和万寿山为主体。
"""
result = model.process(
question=question,
context=context,
threshold=0.5,
language="zh",
)
print("相关句子:")
print(result["pruned_context"])
# 输出:只有4个关于美食的句子
# - "北京烤鸭是北京最著名的特色美食,皮酥肉嫩,配上薄饼和甜面酱。"
# - "炸酱面是北京的传统面食,用黄酱配上黄瓜丝和豆芽菜。"
# - "老北京涮羊肉以铜锅为特色,羊肉鲜嫩,蘸料丰富。"
# - "豆汁儿是北京独特的传统小吃,口味特别,配上焦圈最地道。"
# (过滤掉了所有关于景点的句子)
question: Query textcontext: Document text to highlightthreshold: Relevance threshold (0-1), default 0.5. Lower values include more sentences.language: Language code ("en", "zh", or "auto")return_sentence_metrics: Return per-sentence relevance scorespruned_context: Highlighted text (relevant sentences only)compression_rate: Percentage of text removedsentence_probabilities: Relevance score for each sentence (if return_sentence_metrics=True)⚠️ This is a preview version. The model is still under development and improvements are ongoing.
This model is built upon the excellent work of Open Provence project. Open Provence pioneered the approach of using lightweight reranker models for context pruning in RAG systems, demonstrating that semantic relevance prediction can be achieved efficiently without relying on large language models.
We extend our sincere gratitude to the Open Provence team for:
This preview model represents our initial exploration of semantic highlighting for bilingual scenarios (Chinese and English), standing on the shoulders of their foundational work.
Same as base model: MIT License
If you use this model, please cite the base model:
@misc{bge-reranker-v2-m3,
title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation},
author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
year={2024},
eprint={2402.03216},
archivePrefix={arXiv},
primaryClass={cs.CL}
}