{"id":20484532,"url":"https://github.com/sap-samples/security-research-dp-hierarchical-text","last_synced_at":"2026-04-20T07:31:48.671Z","repository":{"id":37963875,"uuid":"398403574","full_name":"SAP-samples/security-research-dp-hierarchical-text","owner":"SAP-samples","description":"SAP Security Research sample code to reproduce the research done in our paper “On the privacy-utility trade-off in differentially private hierarchical text classification\".","archived":false,"fork":false,"pushed_at":"2024-08-02T11:24:37.000Z","size":345,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-05T16:19:35.427Z","etag":null,"topics":["research","sample","sample-code","security"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2103.02895","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SAP-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-20T21:25:04.000Z","updated_at":"2024-12-08T07:01:32.000Z","dependencies_parsed_at":"2022-09-02T11:41:05.004Z","dependency_job_id":null,"html_url":"https://github.com/SAP-samples/security-research-dp-hierarchical-text","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SAP-samples/security-research-dp-hierarchical-text","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fsecurity-research-dp-hierarchical-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fsecurity-research-dp-hierarchical-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fsecurity-research-dp-hierarchical-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fsecurity-research-dp-hierarchical-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAP-samples","download_url":"https://codeload.github.com/SAP-samples/security-research-dp-hierarchical-text/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP-samples%2Fsecurity-research-dp-hierarchical-text/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32037860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["research","sample","sample-code","security"],"created_at":"2024-11-15T16:23:39.225Z","updated_at":"2026-04-20T07:31:48.648Z","avatar_url":"https://github.com/SAP-samples.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Differentially Private Hierarchical Text Classification\n\n[![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/security-research-dp-hierarchical-text)](https://api.reuse.software/info/github.com/SAP-samples/security-research-dp-hierarchical-text)\n\n## Description\n\nSAP Security Research sample code to reproduce the research done in our paper \"On the privacy-utility trade-off in\ndifferentially private hierarchical text classification\"[1].\n\n## Requirements\n\n- [Python](https://www.python.org/) 3.7\n- [Tensorflow Privacy](https://github.com/tensorflow/privacy)\n- [Tensorflow](https://github.com/tensorflow)\n- [transformers](https://github.com/huggingface/transformers/)\n- [numpy](https://numpy.org/)\n- [scipy](https://scipy.org/)\n- [pandas](https://pandas.pydata.org/)\n- [anytree](https://anytree.readthedocs.io/)\n- [scikit-learn](https://scikit-learn.org/)\n- [matplotlib](https://matplotlib.org/)\n- [tqdm](https://tqdm.github.io/)\n\n## Download and Installation\n\n### Differentially Private Hierarchical Text Classification Framework\n\nImplementation of several hierarchical text classification (HTC) neural networks\nand the corresponding differential privacy (DP) adversary to quantify information leakage in the trained HTC models.\n\n### Install\n\nRunning `make install` in the root folder should be enough for most use cases.\n\nThe command will create the basic project directory structure and installs dph as well as other requirements.\nYou can use pip as your package manager and install the `dph` package via `python -m pip install -e ./`\nFor other package managers you need to install dpa using `setup.py`.\n\n### Directory Structure\n\nAfter having run `make install`, the following directory structure should be created in your local \nfile system. Note: Everything that must not be tracked by git is already in `.gitignore`.\n\n```\nDPAttack/\n     |-- Makefile\n     |-- setup.py\n     |-- requirements.txt\n     |-- data/              # dataset files\n     |-- logs/\t\t        # experiment logs \n     |-- notebooks/         # evaluation notebooks\n     |-- dph/\t\t\t    # source root\n          |--core/\t            # hierarchical text classification framework\n          |--mia/\t            # membership inference attack framework\n          |--projects/\t        # project implementations using dph\n          |--utils/             # utility modules\n\n```\n\n### Using the Framework\n\nFor every dph project (dataset), a subdirectory in `./dph/projects` is recommended.\nInside the folder, a subclass of an [`HTC Experiment`](dph/core/experiment.py) should be created as it is done for the existing datasets.\nTo train an HTC model, call the `start` method of an experiment.\nTo train a DP-HTC model, pass an instance of [`DPParameters`](dph/core/parameters/parameters.py) to the `Experiment` constructor.\n\nTo train an attack model for an (DP-)HTC model, a [`AttackExperiment`](dph/mia/mia_experiment.py) has to be created.\nTo start an attack, call the `start` method of the attack experiment.\n\n### Reproducing the tables and diagrams of the paper\n\nIn the following, we explain how the different tables and diagrams of the paper can be reproduced. \nRunning the python scripts for [BestBuy], [Reuters] and [DBPedia] will execute the different project's experiments.\nThe scripts' parameters can be adapted to execute all possible scenarios that we examined in the paper. \nThe resulting experiment dictionary in the `logs` folder will contain several json files with the target/attack model metrics (train and test).\nThe results can then be retrieved and plotted in a notebook, as we have done in [`notebooks/plots-dp.ipynb`](notebooks/plots-dp.ipynb).\n\n[BestBuy]: dph/projects/bestbuy/mia/experiment.py\n[Reuters]: dph/projects/reuters/mia/experiment.py\n[DBPedia]: dph/projects/dbpedia/mia/experiment.py\n\n### Contributors\n\n- Dominik Wunderlich\n- Daniel Bernau\n\n### Contributing\n\nIf you wish to contribute code, offer fixes or improvements, please send a pull request. Due to legal reasons, contributors will be asked to accept a DCO when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).\n\nIf you want to report issues or have questions about the project, please open an issue in the GitHub repository or contact the maintainers directly via email. We will respond as soon as possible.\n\n## Citations\nIf you use this code in your research, please cite:\n\n```\n@article{WBA+21,\n      author    =   {Dominik Wunderlich and \n                    Daniel Bernau and \n                    Francesco Aldà and \n                    Javier Parra-Arnau and \n                    Thorsten Strufe},\n      title     =   {On the privacy-utility trade-off in differentially private hierarchical text classification}, \n      eprint    =   {2103.02895},\n      archivePrefix={arXiv},\n      url       =   {http://arxiv.org/abs/2103.02913},\n}\n```\n\n## References\n[1] Dominik Wunderlich, Daniel Bernau, Francesco Aldà, Javier Parra-Arnau, Thorsten Strufe:\nOn the privacy-utility trade-off in differentially private hierarchical text classification.\narXiv:2103.02895\nhttp://arxiv.org/abs/2103.02913\n\n## Code of conduct\n\nSee the [Code of conduct tab](https://github.com/SAP-samples/security-research-dp-hierarchical-text?tab=coc-ov-file).\n\n## License\n\nCopyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache\nSoftware License, version 2.0 except as noted otherwise in the [LICENSE](LICENSES/Apache-2.0.txt) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fsecurity-research-dp-hierarchical-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsap-samples%2Fsecurity-research-dp-hierarchical-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap-samples%2Fsecurity-research-dp-hierarchical-text/lists"}