rombodawg commited on
Commit
2e46993
1 Parent(s): da5199e

Upload 3 files

Browse files
Files changed (3) hide show
  1. combine.py +35 -0
  2. dedupe.py +61 -0
  3. uncensor.py +275 -0
combine.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import multiprocessing
3
+
4
+ # Define the input files
5
+ input_files = [
6
+ 'OpenHermes-2.5-Uncensored.json',
7
+ 'code_bagel.json'
8
+ ]
9
+
10
+ # Define the output file
11
+ output_file = 'code_bagel_hermes-2.5.json'
12
+
13
+ def process_file(file, output_data):
14
+ with open(file, 'r', encoding='utf-8') as f:
15
+ for line in f:
16
+ data = json.loads(line)
17
+ instruction = data['instruction']
18
+ input_data = data['input']
19
+ output = data['output']
20
+ output_data.append({
21
+ "instruction": instruction,
22
+ "input": input_data,
23
+ "output": output
24
+ })
25
+
26
+ if __name__ == '__main__':
27
+ with multiprocessing.Manager() as manager:
28
+ output_data = manager.list()
29
+ with multiprocessing.Pool(processes=12) as pool:
30
+ pool.starmap(process_file, [(file, output_data) for file in input_files])
31
+
32
+ with open(output_file, 'w') as f:
33
+ for obj in output_data:
34
+ json.dump(obj, f)
35
+ f.write('\n') # Write a newline character after each object
dedupe.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from typing import Iterator
4
+ from concurrent.futures import ThreadPoolExecutor, as_completed
5
+
6
+ def remove_duplicate_outputs(input_file_name: str, output_file_name: str, num_threads: int = 10) -> None:
7
+ """
8
+ Removes duplicate entries in the "output" field from the input file and writes the filtered lines to the output file.
9
+
10
+ :param input_file_name: Name of the input JSON file.
11
+ :param output_file_name: Name of the output JSON file.
12
+ :param num_threads: Number of threads to use for parallel processing (defaults to 10).
13
+ """
14
+ script_dir = os.path.dirname(os.path.abspath(__file__))
15
+ input_file_path = os.path.join(script_dir, input_file_name)
16
+ output_file_path = os.path.join(script_dir, output_file_name)
17
+
18
+ with open(input_file_path, 'r', encoding='utf-8') as input_fp:
19
+ lines = input_fp.readlines()
20
+
21
+ with ThreadPoolExecutor(max_workers=num_threads) as executor:
22
+ futures = [executor.submit(load_and_filter_lines, lines) for _ in range(num_threads)]
23
+ filtered_lines = []
24
+ for future in as_completed(futures):
25
+ filtered_lines.extend(future.result())
26
+
27
+ seen_outputs = set()
28
+ with open(output_file_path, 'w', encoding='utf-8') as output_fp:
29
+ for line in filtered_lines:
30
+ try:
31
+ data = json.loads(line)
32
+ output_value = data.get('output', '')
33
+ if output_value not in seen_outputs:
34
+ seen_outputs.add(output_value)
35
+ output_fp.write(line)
36
+ except json.JSONDecodeError:
37
+ continue
38
+
39
+ def load_and_filter_lines(lines: list[str]) -> list[str]:
40
+ """
41
+ Loads and filters lines from the input dataset.
42
+
43
+ :param lines: List of lines from the input dataset.
44
+ :return: List of filtered lines.
45
+ """
46
+ filtered_lines = []
47
+ for line in lines:
48
+ try:
49
+ data = json.loads(line)
50
+ output_value = data.get('output', '')
51
+ if output_value:
52
+ filtered_lines.append(line)
53
+ except json.JSONDecodeError:
54
+ continue
55
+ return filtered_lines
56
+
57
+ # Here is where you put the name of the input file, and name of the file that will be created. Note the input file needs to be in the same directory as the script unless you edit the code to have a file path instead.
58
+ input_file_name = 'Input_File.json'
59
+ output_file_name = 'Output_File.json'
60
+
61
+ remove_duplicate_outputs(input_file_name, output_file_name, num_threads=10)
uncensor.py ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from typing import Iterator
4
+ from concurrent.futures import ThreadPoolExecutor
5
+
6
+ def filter_json_lines(input_file_name: str, output_file_name: str, words_to_match: list[str], num_threads: int = 10) -> None:
7
+ """
8
+ Filters JSON lines from the input file and writes the filtered lines to the output file.
9
+ Lines are filtered out if the "output" field contains any of the specified words.
10
+
11
+ :param input_file_name: Name of the input JSON file.
12
+ :param output_file_name: Name of the output JSON file.
13
+ :param words_to_match: List of words to match in the "output" field.
14
+ :param num_threads: Number of threads to use for parallel processing (defaults to 10).
15
+ """
16
+ script_dir = os.path.dirname(os.path.abspath(__file__))
17
+ input_file_path = os.path.join(script_dir, input_file_name)
18
+ output_file_path = os.path.join(script_dir, output_file_name)
19
+
20
+ with open(input_file_path, 'r', encoding='utf-8') as input_fp, open(output_file_path, 'w', encoding='utf-8') as output_fp:
21
+ with ThreadPoolExecutor(max_workers=num_threads) as executor:
22
+ futures = [executor.submit(filter_json_lines_iter, input_fp, words_to_match) for _ in range(num_threads)]
23
+ for future in futures:
24
+ for line in future.result():
25
+ output_fp.write(line)
26
+
27
+ def filter_json_lines_iter(input_fp: Iterator[str], words_to_match: list[str]) -> Iterator[str]:
28
+ """
29
+ Generator function that yields filtered JSON lines.
30
+
31
+ :param input_fp: Iterator over input file lines.
32
+ :param words_to_match: List of words to match in the "output" field.
33
+ :return: Iterator of filtered JSON lines.
34
+ """
35
+ words_to_match_set = set(words_to_match)
36
+ for line in input_fp:
37
+ try:
38
+ data = json.loads(line)
39
+ output_value = data.get('output', '')
40
+ if not any(word in output_value for word in words_to_match_set):
41
+ yield line
42
+ except json.JSONDecodeError:
43
+ continue
44
+
45
+ # Here is where you put the name of the input file, and name of the file that will be created. Note the input file needs to be in the same directory as the script unless you edit the code to have a file path instead.
46
+ input_file_name = 'Input_File.json'
47
+ output_file_name = 'Output_File.json'
48
+ words_to_match = [
49
+ "text-based AI language model",
50
+ "domestic violence",
51
+ "please refrain",
52
+ "derogatory",
53
+ "inappropriate",
54
+ "offensive",
55
+ "racism",
56
+ "racist",
57
+ "racial",
58
+ "discriminate",
59
+ "discriminatory",
60
+ "discrimination",
61
+ "sexist",
62
+ "sexism",
63
+ "unacceptable",
64
+ "inclusive workplace",
65
+ "lgbt",
66
+ "morals",
67
+ "ethics",
68
+ "ethical",
69
+ "legality",
70
+ "illegal",
71
+ "illegality",
72
+ "hateful",
73
+ "harmful",
74
+ "it is never okay",
75
+ "It is important to",
76
+ "It's important to",
77
+ "real-world consequences",
78
+ "hate speech",
79
+ "glorify",
80
+ "not be appropriate",
81
+ "supremacist",
82
+ "extremist",
83
+ "responsible AI",
84
+ "AI principles",
85
+ "AI assistant",
86
+ "an AI language",
87
+ "ableist",
88
+ "hurtful",
89
+ "gender stereotype",
90
+ "gender inequality",
91
+ "underrepresentation",
92
+ "safe spaces",
93
+ "gender-based",
94
+ "inclusivity",
95
+ "feminist",
96
+ "feminism",
97
+ "transgender",
98
+ "empowerment",
99
+ "communist",
100
+ "capitalism",
101
+ "stereotypes",
102
+ "biases",
103
+ "bias",
104
+ "Microaggression",
105
+ "prioritize human safety",
106
+ "as a language model",
107
+ "as an AI language model",
108
+ "As a large language model",
109
+ "As an AI",
110
+ "ethical principles",
111
+ "consensual",
112
+ "it is not appropriate",
113
+ "it's not appropriate",
114
+ "I cannot fulfill your request",
115
+ "harmful to human beings",
116
+ "ethical guidelines",
117
+ "my guidelines",
118
+ "prioritize user safety",
119
+ "adhere to ethical guidelines",
120
+ "harmful consequences",
121
+ "potentially harmful",
122
+ "dangerous activities",
123
+ "promote safety",
124
+ "well-being of all users",
125
+ "responsible information sharing",
126
+ "jeopardize the safety",
127
+ "illegal actions or intentions",
128
+ "undermine the stability",
129
+ "promote the well-being",
130
+ "illegal activities or actions",
131
+ "adherence to the law",
132
+ "potentially be harmful",
133
+ "illegal substances or activities",
134
+ "committed to promoting",
135
+ "safe information",
136
+ "lawful information",
137
+ "cannot provide guidance",
138
+ "cannot provide information",
139
+ "unable to offer assistance",
140
+ "cannot engage in discussions",
141
+ "programming prohibits",
142
+ "follow ethical guidelines",
143
+ "ensure the safety",
144
+ "involves an illegal subject",
145
+ "prioritize safety",
146
+ "illegal subject",
147
+ "prioritize user well-being",
148
+ "cannot support or promote",
149
+ "activities that could harm",
150
+ "pose a risk to others",
151
+ "against my programming",
152
+ "activities that could undermine",
153
+ "potentially dangerous",
154
+ "not within the scope",
155
+ "designed to prioritize safety",
156
+ "not able to provide",
157
+ "maintain user safety",
158
+ "adhere to safety guidelines",
159
+ "dangerous or harmful",
160
+ "cannot provide any information",
161
+ "focus on promoting safety",
162
+ "an AI language model you don't have",
163
+ "As an AI language model, I cannot",
164
+ "As an AI language model, I do not",
165
+ "As an AI language model, I am not able",
166
+ "As an AI language model, I don't have personal",
167
+ "I am an AI language model and do not",
168
+ "However,it is important to use any code or information provided responsibly and within legal and ethical boundaries.",
169
+ "As an AI language model, I don't have",
170
+ "As an AI language model, I am only able",
171
+ "AI language model and I do not",
172
+ "As an AI language model, I cannot modify",
173
+ "I know as an AI language model you don't have",
174
+ "as an AI language model, you cannot",
175
+ "I'm sorry, but as an AI language model",
176
+ "Unfortunately, I cannot provide",
177
+ "I'm sorry, I cannot",
178
+ "I'm sorry, I cannot generate",
179
+ "AI cannot create or program",
180
+ "I'm afraid I cannot create",
181
+ "you cannot create an",
182
+ "it operates ethically and is",
183
+ "had an ethical system",
184
+ "Ensuring the ethical",
185
+ "and ethical sourcing",
186
+ "are from ethical",
187
+ "legal and ethical",
188
+ "engage in unethical",
189
+ "unethical or aggressive",
190
+ "unethical business",
191
+ "como modelo de lenguaje AI",
192
+ "Lo siento, como modelo de lenguaje",
193
+ "no puedo proporcionar",
194
+ "pero debido a mi capacidad para generar códigos complejos y completos es limitado",
195
+ "Lo siento, pero no puedo",
196
+ "Lo siento, pero como modelo de lenguaje, no puedo proporcionar",
197
+ "Lo siento, como modelo de lenguaje, no tengo",
198
+ "Lo siento, debe haber habido una confusión",
199
+ "Lo siento, como modelo de lenguaje, no puedo realizar",
200
+ "Lo siento, soy un modelo de lenguaje y no tengo la capacidad de generar",
201
+ "Lamento no poder proporcionarte el código",
202
+ "Desculpe-me, mas a linguagem vulgar e ofensiva",
203
+ "apropriada em nenhum contexto",
204
+ "Como modelo de linguagem",
205
+ "Como um modelo de linguagem, não tenho a capacidade de",
206
+ "I cannot assist",
207
+ "prioritize ethical",
208
+ "respectful",
209
+ "morally",
210
+ "I'm sorry,",
211
+ "I'm an",
212
+ "I am an",
213
+ "I'm an AI",
214
+ "I am an AI",
215
+ "my purpose",
216
+ "filter_bad_language",
217
+ "entertainment purposes",
218
+ "purely hypothetical",
219
+ "not a human",
220
+ "cannot provide",
221
+ "can't provide",
222
+ "won't provide",
223
+ "not provide",
224
+ "worth noting",
225
+ "cause harm",
226
+ "a language model",
227
+ "keep in mind",
228
+ "unethical",
229
+ "bad language",
230
+ "the words ****",
231
+ "bad_language",
232
+ "certainly not",
233
+ "complying",
234
+ "comply",
235
+ "I cannot",
236
+ "my main goal",
237
+ "As a machine",
238
+ "I don't have the ability",
239
+ "I am here to assist",
240
+ "my purpose is to ",
241
+ "my knowledge cutoff",
242
+ "my knowledge cut off",
243
+ "September 2021",
244
+ "regulations",
245
+ "not be suitable",
246
+ "I apologize, but",
247
+ "It is not possible",
248
+ "controversial",
249
+ "my programming",
250
+ "ethically",
251
+ "it is important to",
252
+ "Please note",
253
+ "sensitive topic",
254
+ "not acceptable",
255
+ "It is important for",
256
+ "divisive",
257
+ "not appropriate",
258
+ "our values",
259
+ "f*cking",
260
+ "F*ck",
261
+ "sh*t",
262
+ "diversity and",
263
+ "diversity and inclusion",
264
+ "values diversity",
265
+ "social responsibility",
266
+ "environmental, social, and governance",
267
+ " ESG ",
268
+ "against women",
269
+ "problematic history",
270
+ "diversity",
271
+ "*This chat conversation is shared from",
272
+ "*This conversation is shared from",
273
+ ]
274
+
275
+ filter_json_lines(input_file_name, output_file_name, words_to_match, num_threads=10)