| import csv |
| import time |
| from tqdm import tqdm |
|
|
| dataset = [] |
|
|
| min_value = -10000 |
| max_value = 10000 |
|
|
| |
| total_combinations = (max_value - min_value + 1) ** 2 |
|
|
| |
| 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"]) |
|
|
| 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): |
| |
| if b < 0: |
| instruction = f"{a}-({abs(b)})" |
| else: |
| instruction = f"{a}+{b}" |
|
|
| |
| output = a + b |
|
|
| |
| 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}.") |
|
|