--- library_name: bhed pipeline_tag: text-generation language: - es - en - hi tags: - bhed - pii - redaction - privacy - multilingual - spanish - english - hindi - hinglish license: apache-2.0 --- # भेद · Bhed **Repo:** [MindMapDigital/Bhed-v0.1](https://huggingface.co/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` है। लोडिंग, प्रॉम्प्ट, डिकोडिंग और निश्चित पोस्ट-प्रोसेसिंग — सब इसी पैकेज से होता है। ## Requirements · आवश्यकताएँ - Python 3.10 or newer / Python 3.10 या नया - A CUDA GPU is the intended runtime. CPU works, and loads the weights in float32 इच्छित रनटाइम CUDA GPU है। CPU भी चलता है (weights float32 में) - Disk space for the weight files in this directory (~120 MB package files; foundation weights download on first load) इस डायरेक्टरी की वेट फ़ाइलों के लिए डिस्क स्पेस (~120 MB पैकेज; पहली लोड पर foundation weights डाउनलोड) These are installed with the package / पैकेज के साथ ये इंस्टॉल होते हैं: | Package | Version | |---|---| | torch | >= 2.1 | | transformers | >= 4.45 | | huggingface_hub | >= 0.23 | ## Install · इंस्टॉल From this directory / इस डायरेक्टरी से: ```bash 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()` उन्हें पैकेज के पास खोजता है। ## Quick start · त्वरित शुरुआत ```python 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` लौटाता है: ```text I'm [PER_1], account [BANK_ACCOUNT_1], phone [PHONE_1]. ``` Hindi / Hinglish example · हिन्दी उदाहरण: ```python from bhed import Bhed model = Bhed.from_pretrained("MindMapDigital/Bhed-v0.1") print(model.redact( "मेरा नाम दीपक चौहान है और मेरा आधार 7392 4810 5567 है। " "मैंने इंदौर में अपना फ्लैट ₹48,50,000 में बेचा।" )) ``` Example output / उदाहरण आउटपुट: ```text मेरा नाम [PER_1] है और मेरा आधार [NATIONAL_ID_1] है। मैंने [LOC_1] में अपना फ्लैट [MONEY_1] में बेचा। ``` Mapping and privacy flags / मैपिंग और प्राइवेसी फ़्लैग: ```python 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 · स्पेनिश उदाहरण: ```python print(model.redact( "La empresa Innovaciones Digitales SL, con NIF B98765432, " "compró un servidor en Madrid por 15.000€." )) ``` CLI / कमांड लाइन: ```bash bhed "I'm Dana Brooks, account 4470912233." bhed "मेरा नाम सुनीता अग्रवाल है, PAN BQRPA4821M।" --json bhed "La empresa Innovaciones Digitales SL, con NIF B98765432…" --json ``` ## API ```python 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 / वेट का डेटा-टाइप | ```python 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)। ```python from bhed import Bhed model = Bhed.from_pretrained("MindMapDigital/Bhed-v0.1") ``` ### `Bhed.redact(text, max_new_tokens=256) -> str` Runs 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) -> dict` Same 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) -> str` Raw JSON mapping only, without post-processing. केवल कच्चा JSON मैपिंग, बिना पोस्ट-प्रोसेसिंग। One `Bhed` instance can redact many queries — load once, call `redact` again. एक `Bhed` इंस्टेंस कई प्रश्नों को रेडैक्ट कर सकता है — एक बार लोड करें, बार-बार `redact` चलाएँ। ## Prompt · प्रॉम्प्ट The prompt is fixed by the package. Callers pass only the user text. प्रॉम्प्ट पैकेज में तय है। कॉलर केवल उपयोगकर्ता का पाठ देते हैं। ## Transcripts · टैग Personal data is returned as typed tags, numbered per type by first appearance. व्यक्तिगत जानकारी टाइप किए टैग के रूप में आती है, प्रत्येक प्रकार पर पहली उपस्थिति के क्रम में संख्यांकित: ```text [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 · डिकोडिंग Decoding is greedy: no sampling. Default cap 256 new tokens. Then post-processing: डिकोडिंग greedy है — सैंपलिंग नहीं। डिफ़ॉल्ट सीमा 256 नए टोकन। फिर पोस्ट-प्रोसेसिंग: 1. Parses the JSON mapping / JSON मैपिंग पार्स करता है 2. Normalises tag types / टैग प्रकार सामान्य करता है 3. Repairs merged values and boundary splits (e.g. khasra) / जुड़े मान और सीमा विभाजन सुधारता है (जैसे खसरा) 4. Regex backstop for missed structured IDs / छूटे संरचित ID के लिए regex बैकस्टॉप 5. Replaces in the **original** text, longest first / **मूल** पाठ में बदलता है, सबसे लंबे पहले 6. Leak-checks the result / लीक जाँच करता है ## Files · फ़ाइलें | 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 / पीयर तुलना | ## Benchmarks · बेंचमार्क 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`.