Skip to main content

No project description provided

Project description

GLLM Privacy

Description

A library to protect Personal Identifiable Information (PII) in a Generative AI project.

Installation

Prerequisites

Mandatory:

  1. Python 3.11+ — Install here
  2. pip — Install here
  3. uv — Install here

Extras (required only for Artifact Registry installations):

  1. gcloud CLI (for authentication) — Install here, then log in using:
    gcloud auth login
    

Option 1: Install from Artifact Registry

This option requires authentication via the gcloud CLI.

uv pip install \
  --extra-index-url "https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/" \
  gllm-privacy

Option 2: Install from PyPI

This option requires no authentication. However, it installs the binary wheel version of the package, which is fully usable but does not include source code.

uv pip install gllm-privacy-binary

Local Development Setup

Prerequisites

  1. Python 3.11+ — Install here

  2. pip — Install here

  3. uv — Install here

  4. gcloud CLI — Install here, then log in using:

    gcloud auth login
    
  5. Git — Install here

  6. Access to the GDP Labs SDK GitHub repository


1. Clone Repository

git clone git@github.com:GDP-ADMIN/gl-sdk.git
cd gl-sdk/libs/gllm-privacy

2. Setup Authentication

Set the following environment variables to authenticate with internal package indexes:

export UV_INDEX_GEN_AI_INTERNAL_USERNAME=oauth2accesstoken
export UV_INDEX_GEN_AI_INTERNAL_PASSWORD="$(gcloud auth print-access-token)"
export UV_INDEX_GEN_AI_USERNAME=oauth2accesstoken
export UV_INDEX_GEN_AI_PASSWORD="$(gcloud auth print-access-token)"

3. Quick Setup

Run:

make setup

4. Activate Virtual Environment

source .venv/bin/activate

Local Development Utilities

The following Makefile commands are available for quick operations:

Install uv

make install-uv

Install Pre-Commit

make install-pre-commit

Install Dependencies

make install

Update Dependencies

make update

Run Tests

make test

Usage

from gllm_privacy.pii_detector import TextAnalyzer, TextAnonymizer
from gllm_privacy.pii_detector.constants import Entities
from gllm_privacy.pii_detector.anonymizer import Operation
from asyncio import run

text = """
    contoh nomor ktp 3525011212941001
    repeat nomor ktp 3525011212941001
    contoh email john.doe@example.com
    contoh nomor telepon +628121729819 dan 0812898029384.
    contoh npwp 01.123.456.7-891.234
"""
text_analyzer = TextAnalyzer()
entities = [Entities.EMAIL_ADDRESS, Entities.KTP, Entities.NPWP, Entities.PHONE_NUMBER]

text_anonymizer = TextAnonymizer(text_analyzer)
anonymized_text = run(text_anonymizer.run(text=text, entities=entities))
print(anonymized_text)

deanonymized_text = run(text_anonymizer.run(text=text, entities=entities, operation=Operation.DEANONYMIZE))
print(deanonymized_text)

If you need to detect person, organization, or location entities in text written in Bahasa Indonesia, you can use either TransformersRecognizer or ProsaRemoteRecognizer. To use the TransformersRecognizer, you can use it like this:

from gllm_privacy.pii_detector.recognizer.config import CAHYA_BERT_CONFIGURATION
from gllm_privacy.pii_detector.recognizer.transformers_recognizer import TransformersRecognizer
from gllm_privacy.pii_detector import TextAnalyzer, TextAnonymizer
from gllm_privacy.pii_detector.constants import Entities

# Load the model, if you run it for the first time, it will download the model from the Hugging Face model hub
transformers_recognizer = TransformersRecognizer(
  model_path=CAHYA_BERT_CONFIGURATION.get("DEFAULT_MODEL_PATH"),
  supported_entities=CAHYA_BERT_CONFIGURATION.get("PRESIDIO_SUPPORTED_ENTITIES"),
)
transformers_recognizer.load_transformer(**CAHYA_BERT_CONFIGURATION)
analyzer = TextAnalyzer(additional_recognizers=[transformers_recognizer])

text = "John Doe adalah seorang karyawan PT ABCD yang berlokasi di Jakarta."
text_analyzer = TextAnalyzer(additional_recognizers=[transformers_recognizer])
entities = [Entities.PERSON, Entities.LOCATION]

text_anonymizer = TextAnonymizer(text_analyzer)
anonymized_text = text_anonymizer.anonymize(text=text, entities=entities)
print(anonymized_text)

deanonymized_text = text_anonymizer.deanonymize(text=text)
print(deanonymized_text)

Enhanced TransformersRecognizer with Optimum

The TransformersRecognizer now supports Hugging Face Optimum for improved performance:

  • ONNX Runtime with CUDA: GPU-accelerated inference using ONNX Runtime with CUDA provider
  • ONNX Runtime with CPU: Optimized CPU inference for better performance on laptops/servers
  • Apple Silicon MPS: GPU acceleration on Apple Silicon Macs
  • Auto-detection: Automatically selects the best available backend
  • Fallback compatibility: Works on any hardware with standard transformers

Available Backends:

  • onnx: ONNX Runtime with CPU provider (optimized for NER tasks)
  • cuda: ONNX Runtime with CUDA provider (GPU acceleration)
  • mps: Apple Silicon MPS for GPU acceleration on Mac
  • transformers: Standard transformers as fallback

Configuration Options:

You can configure the backend behavior in your configuration:

config = {
    "USE_OPTIMUM": True,                    # Enable/disable Optimum
    "OPTIMUM_BACKEND": "auto",              # "auto", "onnx", "cuda", "mps", "transformers"
    "OPTIMUM_DEVICE": "auto",               # "auto", "cuda", "cpu", "mps"
    "OPTIMUM_QUANTIZATION": False,          # Enable quantization
    "OPTIMUM_MAX_BATCH_SIZE": 8,           # Max batch size
}

Usage Example:

from gllm_privacy.pii_detector import TextAnalyzer
from gllm_privacy.pii_detector.recognizer.config import CAHYA_BERT_CONFIGURATION
from gllm_privacy.pii_detector.recognizer.transformers_recognizer import TransformersRecognizer

transformers_recognizer = TransformersRecognizer(
    model_path=CAHYA_BERT_CONFIGURATION.get("DEFAULT_MODEL_PATH"),
    supported_entities=CAHYA_BERT_CONFIGURATION.get("PRESIDIO_SUPPORTED_ENTITIES"),
    use_optimum=True
)

transformers_recognizer.load_transformer(**CAHYA_BERT_CONFIGURATION)

pipeline_info = transformers_recognizer.get_pipeline_info()
print(f"Backend: {pipeline_info['backend']}")
print(f"Device: {pipeline_info['device']}")
print(f"Optimizations: {pipeline_info['optimizations']}")

# Use as before
analyzer = TextAnalyzer(additional_recognizers=[transformers_recognizer])

To use the ProsaRemoteRecognizer, you can use it like the following example. Please replace <PROSA_API_URL> and <PROSA_API_KEY> with the valid values.

from gllm_privacy.pii_detector.recognizer.prosa_remote_recognizer import ProsaRemoteRecognizer
from gllm_privacy.pii_detector import TextAnalyzer, TextAnonymizer
from gllm_privacy.pii_detector.constants import Entities

text = "John Doe adalah seorang karyawan PT ABCD yang berlokasi di Jakarta."
prosa_recognizer = ProsaRemoteRecognizer('<PROSA_API_URL>', '<PROSA_API_KEY>')
text_analyzer = TextAnalyzer(additional_recognizers=[prosa_recognizer])
entities = [Entities.PERSON, Entities.LOCATION]

text_anonymizer = TextAnonymizer(text_analyzer)
anonymized_text = text_anonymizer.anonymize(text=text, entities=entities)
print(anonymized_text)

deanonymized_text = text_anonymizer.deanonymize(text=text)
print(deanonymized_text)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gllm_privacy_binary-0.4.25.post1-cp313-cp313-win_amd64.whl (543.1 kB view details)

Uploaded CPython 3.13Windows x86-64

gllm_privacy_binary-0.4.25.post1-cp313-cp313-macosx_13_0_arm64.whl (600.0 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

gllm_privacy_binary-0.4.25.post1-cp312-cp312-win_amd64.whl (546.9 kB view details)

Uploaded CPython 3.12Windows x86-64

gllm_privacy_binary-0.4.25.post1-cp312-cp312-manylinux_2_31_x86_64.whl (858.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

gllm_privacy_binary-0.4.25.post1-cp312-cp312-macosx_13_0_arm64.whl (599.8 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

gllm_privacy_binary-0.4.25.post1-cp311-cp311-win_amd64.whl (563.8 kB view details)

Uploaded CPython 3.11Windows x86-64

gllm_privacy_binary-0.4.25.post1-cp311-cp311-manylinux_2_31_x86_64.whl (783.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

gllm_privacy_binary-0.4.25.post1-cp311-cp311-macosx_13_0_arm64.whl (584.9 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 72798eae54c9b52d8df6be2e9cd03586aae26a60df2f96efb23e6229e62f9836
MD5 82ede34f7db07edb9b44673e5225dd6a
BLAKE2b-256 aac1e0d12c67bb07d6f29c0ce4e8ba4cd29dd88641fc5c07f5006b8822e0ea06

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_privacy_binary-0.4.25.post1-cp313-cp313-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 ff8479009cbb5c2970291b4ca9bfa9b5e9b4b2bd0cc7390548a6f771c3ee69d0
MD5 8c5366f0310b948dd782c695ed8d8131
BLAKE2b-256 f1f7a0ac30e48e7aae2bc321273ce0e381093e6e1d70798e153c1ece8e7a281f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_privacy_binary-0.4.25.post1-cp313-cp313-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8e1fad82816be2434b852c291c0f57e73e91e615d9e4ffd2ecbdf71a76ac4402
MD5 a009b6ef49271a4d1186cac5585f3779
BLAKE2b-256 a3147d2f54faf73477a599be2f9e934b65497d993c94c6486f22081ddb1e6849

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_privacy_binary-0.4.25.post1-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 cb46410a77462ca3ac77082d89bb314d78e09ed0b64eab320156655e2e9a60b8
MD5 663a1d5454e04c9d5ab2c0c7fd050758
BLAKE2b-256 a8941bceec04b0a27e2ede32d26c24be18b1cc67f9a30bff43f4afa719ce1807

See more details on using hashes here.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 0ad71d4f66473ba560a5056df3cc06087452b0605f081901087017a12bf79740
MD5 dc0a28f94bef5ea9a66e7d2ad4d6d093
BLAKE2b-256 62ee3caad078de2226b5d4859752cd29294f381020f798f1ce29069152807119

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_privacy_binary-0.4.25.post1-cp312-cp312-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 90346ef5de8f7f8f7a405d7cf5937158d4d6e625f821f755874e8c01d8e29d92
MD5 5577a2de138c89e5edd53570aada3761
BLAKE2b-256 c0abac9813204746e7bf1958c020d54f7013c3a68a741cf35954d7e1599c20a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_privacy_binary-0.4.25.post1-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 54bd2f7d2e76645c49e9c0b1a8f8eaff572760b849e955dd230eab64dd17a332
MD5 253381fa0455b4e5025a383ae6c2844d
BLAKE2b-256 6a83d19226296c2b04dc3fbe335ffbde1150e6da307676df43e7923d6bf145f3

See more details on using hashes here.

File details

Details for the file gllm_privacy_binary-0.4.25.post1-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for gllm_privacy_binary-0.4.25.post1-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 9b208062ac782f035acd681facb3eef27eccb88977fa94480a0c6ff052587a2c
MD5 741561439742616071dadd32f6c93083
BLAKE2b-256 4afe62e8535aa9a2388c10ef003773469a1b0ed44591fcd0d0ce2147b8c0c154

See more details on using hashes here.

Provenance

The following attestation bundles were made for gllm_privacy_binary-0.4.25.post1-cp311-cp311-macosx_13_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/gl-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page