Skip to main content

🦾 Sujet AI / E2D

⚡ Entity Encoder Decoder (E2D): A Privacy-Enhanced Framework for LLMs and RAG Agents ⚡

PyPI - PyPi MIT license

Quick Install

With pip:

pip install sujet-ai
python -m spacy download en_core_web_lg # For French, replace "en_core_web_lg" with "fr_core_news_lg"

What is E2D ?

With the implementation of the AI EU Act, privacy has become a paramount concern in the development and deployment of AI technologies. In response to these heightened privacy requirements, the E2D (Entity Encoder Decoder) framework emerges as a robust solution specifically designed to address these concerns. E2D is a privacy-enhanced framework tailored for Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG) agents, offering a reliable mechanism for managing sensitive information and mitigating privacy risks. By using indexed-NER to filter entities, the E2D framework ensures that delicate information is safeguarded during both the training and inference phases of AI model operations. This approach is especially beneficial for closed-source LLMs, providing an additional layer of security to prevent unauthorized access or misuse of sensitive data.

Key Features

  • Privacy Preservation: E2D ensures that sensitive entities are encoded securely, reducing the risk of data breaches.
  • Compatibility: The framework can be integrated with various LLMs and RAG agents, making it versatile and adaptable.
  • Ease of Use: Designed with usability in mind, E2D can be easily incorporated into existing AI workflows.
  • Regulatory Compliance: By adopting E2D, organizations can align with the privacy requirements stipulated by the AI EU Act and other regulations.

Components

  1. Entity Encoder: This component encodes sensitive entities using indexed-NER, ensuring that the original data cannot be easily reconstructed without authorization.
  2. Entity Decoder: The decoder component allows for the secure retrieval of the original entities when necessary, ensuring that only authorized users can access the sensitive information.
  3. Integration Modules: E2D provides modules for seamless integration with popular LLM frameworks and RAG agents.

Examples

Below are examples of how to use the E2D framework with different applications.

Example 1: Process of E2D

from sujet_ai import EntityEncoderDecoder

e2d = EntityEncoderDecoder(model="en_core_web_lg") #For French, replace "en_core_web_lg" with "fr_core_news_lg"

text = "Apple Inc. was founded by Steve Jobs and Steve Wozniak on April 1, 1976."

# Encode the entities in the text using E2D
encoded_text = e2d.encode_entities(text)

print("The encoded text is: ", encoded_text)
# Output: "ORG_0 was founded by PERSON_0 and PERSON_1 on DATE_0."

# Decode the entities in the encoded text using E2D
decoded_text = e2d.decode_entities(encoded_text)

print("The decoded text is: ", decoded_text)
# Output: "Apple Inc. was founded by Steve Jobs and Steve Wozniak on April 1, 1976."

Example 2: Integration of E2D with LangChain

import os
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI
from sujet_ai import EntityEncoderDecoder

# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = "Insert Your API Key Here..."


# Define the question to be answered
question = ("What were the total operating expenses for Universal Holdings Ltd. in 2023 and how did they compare "
"to the previous year?")

# we assume the context is already retrieved.
# Open the example text file as a context containing "fake" sensetive information and read its contents
with open("example.txt", "r") as file:
    context = file.read()

# Create an instance of the EntityEncoderDecoder class
e2d = EntityEncoderDecoder(model="en_core_web_lg") #For French, replace "en_core_web_lg" with "fr_core_news_lg"

# Encode the entities in the context and question using the EntityEncoderDecoder instance
encoded_context = e2d.encode_entities(context)
encoded_question = e2d.encode_entities(question)

# Define the prompt template to be used by the language model
prompt = PromptTemplate(
template="Answer the question using the given context.\nQuestion: {question}\nContext: {context}\nAnswer:",
          input_variables=["question", "context"])

# Create an instance of the OpenAI language model
llm = OpenAI()

# Create an instance of the LLMChain class using the language model and prompt template
chain = LLMChain(llm=llm, prompt=prompt)

# Use the LLMChain instance to generate a response to the encoded question and context
encoded_response = chain.run({"question": encoded_question, "context": encoded_context})

# Decode the entities in the encoded response using the EntityEncoderDecoder instance
decoded_response = e2d.decode_entities(encoded_response)

# Use the LLMChain instance to generate a response to the original question and context
response = chain.run({"question": question, "context": context})

# Print the decoded response and the original response
print("The E2C response is: ", decoded_response)
print("The regular response is: ", response)

Bibliography

To cite the E2D framework, please use the following BibTeX reference:

@software{e2d2024,
  title={Entity Encoder Decoder: A Privacy-Enhanced Framework for LLMs and RAG Agents},
  author={Sujet AI, Hamed Rahimi},
  year={2024},
  url = {https://github.com/sujet-ai/E2D-Privacy-Enhanced-RAG}
}

Metadata

Release files for sujet-ai 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sujet-ai 0.1.2
File Size Uploaded Provenance Actions
sujet-ai-0.1.2.tar.gz 5.3 kB Without provenance Details for sujet-ai-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sujet-ai 0.1.2
File Interpreter ABI Platform Actions
sujet_ai-0.1.2-py3-none-any.whl Python 3 none any Details for sujet_ai-0.1.2-py3-none-any.whl

Total release size: 10.8 kB

Release files / sujet-ai-0.1.2.tar.gz

Download URL sujet-ai-0.1.2.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5398c7f6d06d2610df9b8ca3c8d4eedcce1f76e6cb3db7b0de3e64bfdcd4395a
BLAKE2b-256 checksum
How to use checksums
ed40b9be943e36aa3d4884931f5043c8e6d8e980c55841f9949bf5bc01612dfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / sujet_ai-0.1.2-py3-none-any.whl

Download URL sujet_ai-0.1.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1e7065871d0f90dcecebda0b50c61ba0d952d24a5a23b3c0c8aa82e2f338cc7
BLAKE2b-256 checksum
How to use checksums
fe1418eff4a0fe530a835bda97cf96014d05affc049275bd0f9b5507687debde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Security for sujet-ai 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page