Upload 2 files
Browse files- .gitattributes +1 -0
- all_prompts_deduped.txt +3 -0
- duplicate_lines.py +34 -0
.gitattributes
CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
56 |
+
all_prompts_deduped.txt filter=lfs diff=lfs merge=lfs -text
|
all_prompts_deduped.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3ea3a5bc5ca8f5f6513dcff9b9fe86686895479cd231e327d1f9c3f4e159f1f8
|
3 |
+
size 322422703
|
duplicate_lines.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
def clean_line(line):
|
4 |
+
"""Clean a line by stripping formatting differences."""
|
5 |
+
line = line.strip().lower() # Remove leading/trailing spaces and convert to lowercase
|
6 |
+
line = re.sub(r'[^\w\s]', '', line) # Remove punctuation marks
|
7 |
+
line = ' '.join(line.split()) # Remove extra spaces
|
8 |
+
return line
|
9 |
+
|
10 |
+
|
11 |
+
def remove_duplicates(input_file, output_file):
|
12 |
+
"""Remove duplicate lines from a text file while ignoring formatting differences."""
|
13 |
+
unique_lines = set()
|
14 |
+
cleaned_lines = []
|
15 |
+
duplicate_count = 0
|
16 |
+
|
17 |
+
with open(input_file, 'r', encoding='utf-8') as file:
|
18 |
+
for line in file:
|
19 |
+
cleaned_line = clean_line(line)
|
20 |
+
if cleaned_line not in unique_lines:
|
21 |
+
unique_lines.add(cleaned_line)
|
22 |
+
cleaned_lines.append(line)
|
23 |
+
else:
|
24 |
+
duplicate_count += 1
|
25 |
+
|
26 |
+
with open(output_file, 'w', encoding='utf-8') as file:
|
27 |
+
file.writelines(cleaned_lines)
|
28 |
+
|
29 |
+
print(f"{duplicate_count} duplicates removed. Cleaned lines saved to '{output_file}'.")
|
30 |
+
|
31 |
+
# Usage example:
|
32 |
+
input_file = 'all_prompts.txt'
|
33 |
+
output_file = 'all_prompts_deduped.txt'
|
34 |
+
remove_duplicates(input_file, output_file)
|