Repo: MindMapDigital/Bhed-v0.1
English: Bhed (भेद — distinction) is a multilingual PII redaction model for Spanish, English, and Hindi / Hinglish. Give it a legal or tax query and it returns the same text with personal data replaced by typed tags such as [PER_1], [TAX_ID_1], [BANK_ACCOUNT_1].
हिन्दी: भेद एक बहुभाषी PII (व्यक्तिगत जानकारी) रेडैक्शन मॉडल है — स्पेनिश, अंग्रेज़ी और हिन्दी / हिंग्लिश के लिए। इसे कानूनी या कर संबंधी प्रश्न दीजिए; यह वही पाठ लौटाता है जिसमें व्यक्तिगत जानकारी को टैग से बदल दिया गया हो, जैसे [PER_1], [TAX_ID_1], [BANK_ACCOUNT_1]।
The package name is bhed. Loading, prompting, decoding, and deterministic post-processing are all done through that package.
पैकेज का नाम bhed है। लोडिंग, प्रॉम्प्ट, डिकोडिंग और निश्चित पोस्ट-प्रोसेसिंग — सब इसी पैकेज से होता है।
These are installed with the package / पैकेज के साथ ये इंस्टॉल होते हैं:
| Package | Version |
|---|---|
| torch | >= 2.1 |
| transformers | >= 4.45 |
| huggingface_hub | >= 0.23 |
From this directory / इस डायरेक्टरी से:
pip install -e .
That installs the bhed package and the bhed command. The weight files stay in this directory. Bhed() finds them next to the package.
इससे bhed पैकेज और bhed कमांड इंस्टॉल होते हैं। वेट फ़ाइलें यहीं रहती हैं। Bhed() उन्हें पैकेज के पास खोजता है।
from bhed import Bhed
model = Bhed.from_pretrained("MindMapDigital/Bhed-v0.1")
print(model.redact("I'm Dana Brooks, account 4470912233, phone +1 415 555 0199."))
redact returns / redact लौटाता है:
I'm [PER_1], account [BANK_ACCOUNT_1], phone [PHONE_1].
Hindi / Hinglish example · हिन्दी उदाहरण:
from bhed import Bhed
model = Bhed.from_pretrained("MindMapDigital/Bhed-v0.1")
print(model.redact(
"मेरा नाम दीपक चौहान है और मेरा आधार 7392 4810 5567 है। "
"मैंने इंदौर में अपना फ्लैट ₹48,50,000 में बेचा।"
))
Example output / उदाहरण आउटपुट:
मेरा नाम [PER_1] है और मेरा आधार [NATIONAL_ID_1] है। मैंने [LOC_1] में अपना फ्लैट [MONEY_1] में बेचा।
Mapping and privacy flags / मैपिंग और प्राइवेसी फ़्लैग:
from bhed import Bhed
model = Bhed.from_pretrained("MindMapDigital/Bhed-v0.1")
result = model.analyze("मेरा नाम दीपक चौहान है, PAN CKLPT9087Q।")
print(result["sanitized"])
print(result["mapping"])
print(result["blocked"])
Spanish example · स्पेनिश उदाहरण:
print(model.redact(
"La empresa Innovaciones Digitales SL, con NIF B98765432, "
"compró un servidor en Madrid por 15.000€."
))
CLI / कमांड लाइन:
bhed "I'm Dana Brooks, account 4470912233."
bhed "मेरा नाम सुनीता अग्रवाल है, PAN BQRPA4821M।" --json
bhed "La empresa Innovaciones Digitales SL, con NIF B98765432…" --json
from bhed import Bhed
bhed.__version__ is "0.1.0".
Bhed(source=None, device=None, dtype=None)Loads the weights and prepares the model for redaction.
वेट लोड करके रेडैक्शन के लिए मॉडल तैयार करता है।
| Argument | Default | Meaning · अर्थ |
|---|---|---|
source |
this directory | Directory with Bhed weights and tokenizer / वेट और टोकनाइज़र वाली डायरेक्टरी |
device |
"cuda" if available, else "cpu" |
Device / डिवाइस |
dtype |
bfloat16 on CUDA when supported, else float16 / float32 |
Weight dtype / वेट का डेटा-टाइप |
import torch
from bhed import Bhed
model = Bhed(device="cuda", dtype=torch.bfloat16)
Bhed.from_pretrained(source, device=None, dtype=None)Same loader, with source required (local path or Hub id).
वही लोडर; source ज़रूरी है (लोकल पथ या Hub id)।
from bhed import Bhed
model = Bhed.from_pretrained("MindMapDigital/Bhed-v0.1")
Bhed.redact(text, max_new_tokens=256) -> strRuns greedy decoding and deterministic post-processing. Returns the redacted text. Faithfulness outside tags is 100% by construction: original wording is kept; only matched spans are replaced.
लालची (greedy) डिकोडिंग और निश्चित पोस्ट-प्रोसेसिंग चलाता है। रेडैक्टेड पाठ लौटाता है। टैग के बाहर का पाठ मूल जैसा रहता है — केवल चिन्हित हिस्से बदलते हैं।
| Argument | Default | Meaning · अर्थ |
|---|---|---|
text |
Query (ES / EN / HI) / प्रश्न (स्पेनिश / अंग्रेज़ी / हिन्दी) | |
max_new_tokens |
256 | Max generated tokens / अधिकतम नए टोकन |
Bhed.analyze(text, max_new_tokens=256) -> dictSame pipeline as redact, with structured fields.redact जैसा ही पाइपलाइन, संरचित फ़ील्ड के साथ।
| Key | Meaning · अर्थ |
|---|---|
sanitized |
Redacted text / रेडैक्टेड पाठ |
mapping |
{ "[PER_1]": "…", … } |
model_output |
Raw JSON mapping / कच्चा JSON मैपिंग |
blocked |
True if unparseable or residual ID-like leaks / पार्स न हो या ID लीक रहे तो True |
flags |
Post-processing notes / पोस्ट-प्रोसेस नोट्स |
entities |
Spans with type, value, offsets / प्रकार, मान, ऑफ़सेट सहित स्पैन |
Bhed.extract(text, max_new_tokens=256) -> strRaw JSON mapping only, without post-processing.
केवल कच्चा JSON मैपिंग, बिना पोस्ट-प्रोसेसिंग।
One Bhed instance can redact many queries — load once, call redact again.
एक Bhed इंस्टेंस कई प्रश्नों को रेडैक्ट कर सकता है — एक बार लोड करें, बार-बार redact चलाएँ।
The prompt is fixed by the package. Callers pass only the user text.
प्रॉम्प्ट पैकेज में तय है। कॉलर केवल उपयोगकर्ता का पाठ देते हैं।
Personal data is returned as typed tags, numbered per type by first appearance.
व्यक्तिगत जानकारी टाइप किए टैग के रूप में आती है, प्रत्येक प्रकार पर पहली उपस्थिति के क्रम में संख्यांकित:
[PER_1] [ORG_1] [ADDRESS_1] [LOC_1] [MONEY_1]
[NATIONAL_ID_1] [TAX_ID_1] [COMPANY_REG_1] [PASSPORT_1]
[BANK_ACCOUNT_1] [CARD_1] [PHONE_1] [EMAIL_1] [DATE_1]
[PROPERTY_ID_1] [CASE_ID_1] [VEHICLE_ID_1] [ONLINE_ID_1]
[EMPLOYEE_ID_1] [HEALTH_1] [SENSITIVE_1]
Countries, public authorities, law sections, tax years, and rates are left untagged.
देश, सरकारी संस्थाएँ, कानून की धाराएँ, कर वर्ष और दरें टैग नहीं होतीं।
Decoding is greedy: no sampling. Default cap 256 new tokens. Then post-processing:
डिकोडिंग greedy है — सैंपलिंग नहीं। डिफ़ॉल्ट सीमा 256 नए टोकन। फिर पोस्ट-प्रोसेसिंग:
| File | Role · भूमिका |
|---|---|
*.safetensors + loader config |
Bhed weights / भेद वेट्स |
tokenizer.json / tokenizer.model / tokenizer_config.json |
Tokenizer / टोकनाइज़र |
bhed/ |
The bhed package / bhed पैकेज |
pyproject.toml |
Package metadata · name bhed, version 0.1.0 |
benchmarks/ |
Peer comparisons / पीयर तुलना |
Held-out peer comparison (same instruction, temperature 0, same post-processing):
पीयर तुलना (एक ही निर्देश, temperature 0, एक ही पोस्ट-प्रोसेसिंग):
| Model | Strict F1 (28) | Leak rate | Exact pass |
|---|---|---|---|
| Bhed · भेद | 0.966 | 4.0% | 24/28 |
| Llama 3.2 3B Instruct | 0.474 | 24% | 3/28 |
| Qwen2.5 1.5B Instruct | 0.460 | 48% | 2/28 |
| Llama 3.2 1B Instruct | 0.248 | 84% | 3/28 |
Multilingual §7 bench (9 queries · ES / EN / HI):
बहुभाषी §7 बेंच (9 प्रश्न · स्पेनिश / अंग्रेज़ी / हिन्दी):
| Model | Strict F1 | Exact pass |
|---|---|---|
| Bhed · भेद | 0.986 | 8/9 |
| Qwen2.5 1.5B Instruct | 0.627 | 0/9 |
| Llama 3.2 3B Instruct | 0.513 | 2/9 |
| Llama 3.2 1B Instruct | 0.207 | 0/9 |
By language on the 28-query suite (Bhed): English F1 0.951, Hindi F1 0.979.
28-प्रश्न सूट पर भाषावार (भेद): अंग्रेज़ी F1 0.951, हिन्दी F1 0.979।
Full tables: benchmarks/peer_comparison.json.