File size: 1,187 Bytes
f7813f0
 
 
 
 
 
 
 
 
 
 
 
ecaa6c5
f7813f0
ecaa6c5
f7813f0
ecaa6c5
f7813f0
dd03977
f7813f0
23efd80
 
f7813f0
dd03977
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import csv

# Replace 'input.txt' with the path to your input text file
input_file = 'works.txt'

# Replace 'output.csv' with the desired output CSV file path
output_file = 'train.csv'

# Read the text file and split it into paragraphs
with open(input_file, 'r', encoding='utf-8') as file:
    paragraphs = file.read().split('\n\n')  # Adjust the split pattern based on your paragraph format

# Create a CSV writer and write the combined paragraphs into the CSV file with 'text' as the column header
with open(output_file, 'w', newline='', encoding='utf-8') as csvfile:
    fieldnames = ['text']
    csv_writer = csv.writer(csvfile)
    csv_writer.writerow(fieldnames)

    # Use a loop to combine prompt and continuation in the same column with appropriate tags
    for i in range(len(paragraphs)):
        prompt = '###Human:' + ' '.join(paragraphs[i:i + 2])  # Combine two paragraphs for the prompt
        continuation = '###Assistant:' + ' '.join(paragraphs[i + 2:i + 7])  # Combine five paragraphs for the continuation

        # Combine the prompt and continuation in the same column and write to the CSV
        csv_writer.writerow([prompt.strip() + ' ' + continuation.strip()])