Commit
·
bb8b42a
1
Parent(s):
a50b9a3
requirement file
Browse files
README.md
CHANGED
@@ -1,3 +1,150 @@
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
4 |
+
# Responsible-AI-Moderation Model
|
5 |
+
|
6 |
+
## Table of Contents
|
7 |
+
|
8 |
+
- [Introduction](#introduction)
|
9 |
+
- [Features](#features)
|
10 |
+
- [Installation](#installation)
|
11 |
+
- [Set Configuration Variables](#set-configuration-variables)
|
12 |
+
- [Models Required](#models-required)
|
13 |
+
- [Running the Application](#running-the-application)
|
14 |
+
- [License](#license)
|
15 |
+
- [Contact](#contact)
|
16 |
+
|
17 |
+
## Introduction
|
18 |
+
The **Moderation Model** module acts as a central hub for machine learning models for prompt injection, toxicity, jailbreak, restricted topic, custom theme and refusal checks. It provides the endpoints to utilize the response generated by these models.
|
19 |
+
|
20 |
+
## Features
|
21 |
+
The **Moderation Model** module acts as a wrapper for the traditional AI models we are using for various checks like prompt injection, jailbreak, toxicity etc.
|
22 |
+
|
23 |
+
## Installation
|
24 |
+
To run the application, first we need to install Python and the necessary packages:
|
25 |
+
|
26 |
+
1. Install Python (version >= 3.9 & <3.12) from the [official website](https://www.python.org/downloads/) and ensure it is added to your system PATH.
|
27 |
+
|
28 |
+
2. Clone the repository : responsible-ai-ModerationModel:
|
29 |
+
```sh
|
30 |
+
git clone <repository-url>
|
31 |
+
```
|
32 |
+
|
33 |
+
3. Navigate to the `responsible-ai-ModerationModel` directory:
|
34 |
+
```sh
|
35 |
+
cd responsible-ai-ModerationModel
|
36 |
+
```
|
37 |
+
|
38 |
+
4. Create a virtual environment:
|
39 |
+
```sh
|
40 |
+
python -m venv venv
|
41 |
+
```
|
42 |
+
|
43 |
+
5. Activate the virtual environment:
|
44 |
+
- On Windows:
|
45 |
+
```sh
|
46 |
+
.\venv\Scripts\activate
|
47 |
+
```
|
48 |
+
|
49 |
+
6. Go to the `requirements` directory where the `requirement.txt` file is present.
|
50 |
+
In the `requirement.txt` file comment the
|
51 |
+
```sh
|
52 |
+
lib/torch-2.2.0+cu118-cp39-cp39-linux_x86_64.whl
|
53 |
+
```
|
54 |
+
**Note:** Download appropriate torch version supporting python version which is installed [i.e if Python version is 3.10 use torch-2.2.0+cu118-**cp310**-**cp310**-**linux**_x86_64.whl, where cp310 denotes python version 3.10 and linux denotes OS which can be linux/win and **_not applicable for Mac_**]
|
55 |
+
|
56 |
+
**Note:** If working in windows as this is for linux and replace
|
57 |
+
```sh
|
58 |
+
lib/
|
59 |
+
```
|
60 |
+
with
|
61 |
+
```sh
|
62 |
+
../lib/
|
63 |
+
```
|
64 |
+
**Note:** If working in Mac Os, run the below command after running requirement.txt
|
65 |
+
```sh
|
66 |
+
pip install --pre torch torchvision torchaudio \--extra-index-url https://download.pytorch.org/whl/nightly/cpu
|
67 |
+
```
|
68 |
+
|
69 |
+
Download and place the en_core_web_lg-3.5.0-py3-none-any.whl inside the lib folder.
|
70 |
+
[en_core_web_lg](https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.5.0/en_core_web_lg-3.5.0-py3-none-any.whl) and install the requirements:
|
71 |
+
|
72 |
+
```sh
|
73 |
+
pip install -r requirement.txt
|
74 |
+
```
|
75 |
+
|
76 |
+
**Note:** when running requirement.txt, if getting error related to "cuda-python" then comment cuda-python from
|
77 |
+
requirement.txt file and run pip install again
|
78 |
+
Install the fastapi library as well, use the following command:
|
79 |
+
```sh
|
80 |
+
pip install fastapi
|
81 |
+
```
|
82 |
+
## Set Configuration Variables
|
83 |
+
After installing all the required packages, configure the variables necessary to run the APIs.
|
84 |
+
|
85 |
+
1. Navigate to the `src` directory:
|
86 |
+
```sh
|
87 |
+
cd ..
|
88 |
+
```
|
89 |
+
|
90 |
+
2. Locate the `.env` file, which contains keys like the following:
|
91 |
+
|
92 |
+
```sh
|
93 |
+
workers=1
|
94 |
+
WORKERS="${workers}"
|
95 |
+
# DB_NAME="${dbname}"
|
96 |
+
# DB_USERNAME="${username}"
|
97 |
+
# DB_PWD="${password}"
|
98 |
+
# DB_IP="${ipaddress}"
|
99 |
+
# DB_PORT="${port}"
|
100 |
+
# MONGO_PATH="mongodb://${DB_USERNAME}:${DB_PWD}@${DB_IP}:${DB_PORT}/"
|
101 |
+
# MONGO_PATH= "mongodb://localhost:27017/"
|
102 |
+
```
|
103 |
+
|
104 |
+
3. Replace the placeholders with your actual values.
|
105 |
+
|
106 |
+
## Models Required
|
107 |
+
The following models are required to run the application. Download all the model files from the links provided, and place it in the folder name provided.
|
108 |
+
|
109 |
+
1. [Prompt Injection](https://huggingface.co/deepset/deberta-v3-base-injection/tree/main)
|
110 |
+
Files required to download here are : model.safetensors, config.json, tokenizer_config.json, tokenizer.json, special_tokens_map.json.
|
111 |
+
Name the folder as 'dbertaInjection'.
|
112 |
+
|
113 |
+
2. [Restricted Topic](https://huggingface.co/MoritzLaurer/deberta-v3-base-zeroshot-v2.0/tree/main)
|
114 |
+
Files required to download here are : model.safetensors, added_tokens.json, config.json, special_tokens_map.json, spm.model, tokenizer.json, tokenizer_config.json.
|
115 |
+
Name the folder as 'restricted-dberta-base-zeroshot-v2'.
|
116 |
+
|
117 |
+
3. [Sentence Transformer Model](https://huggingface.co/sentence-transformers/multi-qa-mpnet-base-dot-v1/tree/main)
|
118 |
+
Files required to download here are : 1_Pooling folder, pytorch_model.bin, vocab.txt, tokenizer.json, tokenizer_config.json, special_tokens_map.json, sentence_bert_config.json, modules.json, config.json, config_sentence_transformers.json.
|
119 |
+
Name the folder as 'multi-qa-mpnet-base-dot-v1'.
|
120 |
+
|
121 |
+
4. [Detoxify](https://huggingface.co/FacebookAI/roberta-base/tree/main)
|
122 |
+
Files required to download here are : vocab.json, tokenizer.json, merges.txt, config.json.
|
123 |
+
Now download the model checkpoint file from this url and keep it under this folder -
|
124 |
+
[toxic_model_ckpt_file](https://github.com/unitaryai/detoxify/releases/download/v0.3-alpha/toxic_debiased-c7548aa0.ckpt)
|
125 |
+
Name the folder as 'detoxify'.
|
126 |
+
|
127 |
+
Place the above folders in a folder named 'models' in the following way: 'responsible-ai-mm-flask/models'.
|
128 |
+
|
129 |
+
## Running the Application
|
130 |
+
Once we have completed all the aforementioned steps, we can start the service.
|
131 |
+
|
132 |
+
1. Navigate to the `src` directory:
|
133 |
+
|
134 |
+
2. Run `main.py` file:
|
135 |
+
```sh
|
136 |
+
python main.py
|
137 |
+
```
|
138 |
+
|
139 |
+
3. PORT_NO : Use the Port No that is configured in .env file.
|
140 |
+
|
141 |
+
Open the following URL in your browser:
|
142 |
+
`http://localhost:<PORT_NO>/rai/v1/raimoderationmodels/docs`
|
143 |
+
|
144 |
+
Note:- To address the issue where the Passport Number is not recognized in Privacy, modify the "piiEntitiesToBeRedacted" field in the privacy() under service.py file (line no: 98) from None to an empty list []. This adjustment ensures that the Passport Number is correctly identified.
|
145 |
+
|
146 |
+
## License
|
147 |
+
The source code for the project is licensed under the MIT license, which you can find in the [LICENSE.txt](LICENSE.txt) file.
|
148 |
+
|
149 |
+
## Contact
|
150 |
+
If you have more questions or need further insights please feel free to connect with us @ Infosysraitoolkit@infosys.com
|