Your file contents looks like this:
step,train_loss,train_accuracy,valid_loss,valid_mean_token_accuracy,train_mean_reward,full_validation_mean_reward
1,2.14741,0.51509,,,,
2,4.26246,0.45161,,,,
3,1.43551,0.73897,,,,
4,1.93826,0.54214,,,,
5,2.72089,0.57407,,,,
6,2.09483,0.47776,,,,
7,2.17876,0.49525,,,,
8,4.64553,0.51852,,,,
9,1.91511,0.56122,,,,
10,2.55966,0.52174,1.95078,0.58667,,
11,2.07725,0.49909,,,,
12,2.45817,0.48101,,,,
13,2.08099,0.52747,,,,
14,2.48972,0.5122,,,,
15,2.14299,0.52273,,,,
16,1.78777,0.52632,,,,
17,1.6117,0.59209,,,,
18,1.97509,0.53793,,,,
19,2.07984,0.57143,,,,
20,1.72684,0.57862,1.7641,0.52571,,
21,1.97612,0.52431,,,,
22,1.61661,0.60889,,,,
23,1.66485,0.55,,,,
24,1.96617,0.51613,,,,
25,1.66614,0.55085,,,,
26,1.94256,0.5463,,,,
27,1.75422,0.58444,,,,
28,1.9327,0.53533,,,,
29,2.09875,0.44643,,,,
30,1.79345,0.51923,2.11141,0.47312,,
31,2.62426,0.42857,,,,
32,1.4265,0.575,,,,
33,1.49776,0.61379,,,,
34,1.97241,0.46667,,,,
35,1.34752,0.72917,,,,
36,1.79573,0.52451,,,,
37,1.5365,0.57203,,,,
38,1.36473,0.60924,,,,
39,1.8153,0.51261,,,,
40,1.58154,0.58929,2.52484,0.38462,,
41,1.9404,0.50893,,,,
42,2.05275,0.51714,,,,
43,1.31695,0.6601,,,,
44,1.73391,0.55556,,,,
45,1.69977,0.57416,,,,
46,1.75264,0.55128,,,,
47,1.44323,0.60648,,,,
48,1.79441,0.55932,,,,
49,1.6793,0.71429,,,,
50,2.00226,0.58974,1.76231,0.55455,,
51,1.80852,0.5574,,,,
52,1.70634,0.57228,,,,
53,1.84206,0.55882,,,,
54,1.41931,0.65574,,,,
55,1.81368,0.48252,,,,
56,1.87061,0.54245,,,,
57,1.63109,0.55696,,,,
58,1.5902,0.59477,,,,
59,1.63601,0.5472,,,,
60,2.09863,0.49177,2.43319,0.44828,,
61,1.63872,0.50971,,,,
62,2.36439,0.55319,,,,
63,1.69916,0.57917,,,,
64,1.93645,0.5288,,,,
65,2.06131,0.51453,,,,
66,1.63434,0.58508,,,,
67,1.38534,0.6284,,,,
68,1.73171,0.55224,,,,
69,1.56311,0.625,,,,
70,1.73149,0.55769,1.23804,0.66082,,
71,1.32662,0.63529,,,,
72,1.57823,0.5617,,,,
73,1.93344,0.52985,,,,
74,1.51163,0.58282,,,,
75,2.41537,0.4697,,,,
76,1.98731,0.47902,,,,
77,1.52036,0.59612,,,,
78,1.80314,0.57317,,,,
79,1.21278,0.67797,,,
The longer lines are where validation steps were performed.
That was obtained simply by pasting it into https://www.base64decode.org/
You can also use Python on your local system or in a notebook to work on a downloaded file. Hereâs a script to decode a hard-coded file name:
import base64
def decode_base64_file(input_filename, output_filename):
"""Decodes a base64-encoded file and saves the output to a new file.
Args:
input_filename: The path to the input file containing base64 data.
output_filename: The path to the output file where decoded text will be saved.
"""
try:
with open(input_filename, 'r') as f_in:
encoded_data = f_in.read()
except FileNotFoundError:
print(f"Error: Input file '{input_filename}' not found.")
return
except Exception as e:
print(f"Error reading input file: {e}")
return
try:
decoded_data = base64.b64decode(encoded_data).decode('utf-8')
except base64.binascii.Error:
print("Error: Invalid base64 data in the input file.")
return
except Exception as e:
print(f"Error decoding base64 data: {e}")
return
try:
with open(output_filename, 'w') as f_out:
f_out.write(decoded_data)
print(f"Successfully decoded and saved to '{output_filename}'.")
except Exception as e:
print(f"Error writing to output file: {e}")
if __name__ == "__main__":
input_file = "results.txt"
output_file = "results-output.txt"
decode_base64_file(input_file, output_file)
Explanation:
- Import
base64: Imports the necessary library for base64 encoding/decoding.
decode_base64_file function:
- Takes
input_filename and output_filename as arguments.
- File Reading (with error handling):
- Uses a
try-except block to handle potential FileNotFoundError if the input file doesnât exist.
- Uses another
except block to catch any other errors during file reading.
- Reads the entire content of the input file into
encoded_data.
- Base64 Decoding (with error handling):
- Uses a
try-except block to handle base64.binascii.Error which is raised if the data is not valid base64.
- Uses another
except block to catch any other decoding errors.
base64.b64decode(encoded_data) decodes the base64 string.
.decode('utf-8') converts the decoded bytes to a UTF-8 string (assuming the original text was UTF-8 encoded).
- File Writing (with error handling):
- Uses a
try-except block to handle potential errors during writing to the output file.
- Writes the
decoded_data to the output file.
- Prints a success message.
if __name__ == "__main__": block:
- Ensures the code inside this block is executed only when the script is run directly (not imported as a module).
- Sets the input and output filenames.
- Calls the
decode_base64_file function to perform the decoding.