File size: 1,241 Bytes
ef90e54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import csv
import time
from tqdm import tqdm

dataset = []

min_value = -10000
max_value = 10000

# Calculate the total number of combinations
total_combinations = (max_value - min_value + 1) ** 2

# Save the dataset to a CSV file
output_file = "output_dataset.csv"
with open(output_file, mode="w", newline="", encoding="utf-8") as file:
    writer = csv.writer(file)
    writer.writerow(["instruction", "output"])  # Write header

    with tqdm(total=total_combinations, desc="Generating Dataset") as pbar:
        start_time = time.time()
        for a in range(min_value, max_value + 1):
            for b in range(min_value, max_value + 1):
                # Generate the instruction
                if b < 0:
                    instruction = f"{a}-({abs(b)})"
                else:
                    instruction = f"{a}+{b}"

                # Calculate the output
                output = a + b

                # Write the row to the CSV file in real-time
                writer.writerow([instruction, str(output)])

                pbar.update(1)

        end_time = time.time()
        elapsed_time = end_time - start_time
        print(f"Total time taken: {elapsed_time:.2f} seconds")

print(f"Dataset saved to {output_file}.")