langchain/libs/experimental/tests/unit_tests
maks-operlejn-ds 4cc4534d81
Data deanonymization (#10093)
### Description

The feature for pseudonymizing data with ability to retrieve original
text (deanonymization) has been implemented. In order to protect private
data, such as when querying external APIs (OpenAI), it is worth
pseudonymizing sensitive data to maintain full privacy. But then, after
the model response, it would be good to have the data in the original
form.

I implemented the `PresidioReversibleAnonymizer`, which consists of two
parts:

1. anonymization - it works the same way as `PresidioAnonymizer`, plus
the object itself stores a mapping of made-up values to original ones,
for example:
```
    {
        "PERSON": {
            "<anonymized>": "<original>",
            "John Doe": "Slim Shady"
        },
        "PHONE_NUMBER": {
            "111-111-1111": "555-555-5555"
        }
        ...
    }
```

2. deanonymization - using the mapping described above, it matches fake
data with original data and then substitutes it.

Between anonymization and deanonymization user can perform different
operations, for example, passing the output to LLM.

### Future works

- **instance anonymization** - at this point, each occurrence of PII is
treated as a separate entity and separately anonymized. Therefore, two
occurrences of the name John Doe in the text will be changed to two
different names. It is therefore worth introducing support for full
instance detection, so that repeated occurrences are treated as a single
object.
- **better matching and substitution of fake values for real ones** -
currently the strategy is based on matching full strings and then
substituting them. Due to the indeterminism of language models, it may
happen that the value in the answer is slightly changed (e.g. *John Doe*
-> *John* or *Main St, New York* -> *New York*) and such a substitution
is then no longer possible. Therefore, it is worth adjusting the
matching for your needs.
- **Q&A with anonymization** - when I'm done writing all the
functionality, I thought it would be a cool resource in documentation to
write a notebook about retrieval from documents using anonymization. An
iterative process, adding new recognizers to fit the data, lessons
learned and what to look out for

### Twitter handle
@deepsense_ai / @MaksOpp

---------

Co-authored-by: MaksOpp <maks.operlejn@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-09-06 21:33:24 -07:00
..
__init__.py Harrison/move experimental (#8084) 2023-07-21 10:36:28 -07:00
conftest.py Add conftest file to langchain experimental (#9886) 2023-08-28 17:52:16 -07:00
fake_llm.py Use a submodule for pydantic v1 compat (#9371) 2023-08-17 16:35:49 +01:00
test_data_anonymizer.py Add data anonymizer (#9863) 2023-08-30 10:39:44 -07:00
test_logical_fallacy.py adding new chain for logical fallacy removal from model output in chain (#9887) 2023-09-03 15:44:27 -07:00
test_mock.py Harrison/move experimental (#8084) 2023-07-21 10:36:28 -07:00
test_pal.py remove code (#8425) 2023-07-28 13:19:44 -07:00
test_reversible_data_anonymizer.py Data deanonymization (#10093) 2023-09-06 21:33:24 -07:00
test_smartllm.py Added SmartGPT workflow (issue #4463) (#4816) 2023-08-11 15:44:27 -07:00
test_tot.py Tree of Thought introducing a new ToTChain. (#5167) 2023-07-26 21:29:39 -07:00