Update README.md
Browse files
README.md
CHANGED
@@ -3,34 +3,124 @@ license: mit
|
|
3 |
---
|
4 |
|
5 |
# GSM8K training set
|
6 |
-
The original answer is "\n#### Value" and now is "\n#### Value\nThe answer is: Value", which is consistent with the answer format with "meta-math/MetaMathQA"
|
7 |
|
8 |
# Dataset modification codes
|
9 |
```python
|
10 |
# coding=utf-8
|
11 |
|
|
|
|
|
12 |
import jsonlines
|
13 |
from datasets import load_dataset, Features, Value
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# Retrieve the path of training and testing databases
|
16 |
context_feat = Features({"question": Value(dtype='string', id=None), "answer": Value(dtype='string', id=None)})
|
17 |
train_set = load_dataset('json', data_files='train.jsonl', split='train', features=context_feat)
|
18 |
|
19 |
data = []
|
20 |
for example in train_set:
|
21 |
-
# Get the label answer
|
22 |
number = example['answer'].split('#### ')[1]
|
23 |
number = int(number.replace(',', ''))
|
24 |
-
|
25 |
-
# Append the "\nThe answer is: " and numerical answer
|
26 |
append = "\nThe answer is: " + str(number)
|
27 |
answer = example['answer'] + append
|
|
|
28 |
|
29 |
-
# Get the question and make the new question-answer pair
|
30 |
question = example['question']
|
31 |
data.append({"question": question, "answer": answer})
|
32 |
|
33 |
-
# Save the modified data to a
|
34 |
output_file = 'gsm8k_train.jsonl'
|
35 |
with jsonlines.open(output_file, 'w') as writer:
|
36 |
writer.write_all(data)
|
|
|
3 |
---
|
4 |
|
5 |
# GSM8K training set
|
6 |
+
The original answer is "\n#### Value" and now is "\n#### Value\nThe answer is: Value", and the answer is cleaned, which is **consistent with the answer format with "meta-math/MetaMathQA"**.
|
7 |
|
8 |
# Dataset modification codes
|
9 |
```python
|
10 |
# coding=utf-8
|
11 |
|
12 |
+
import re
|
13 |
+
|
14 |
import jsonlines
|
15 |
from datasets import load_dataset, Features, Value
|
16 |
|
17 |
+
|
18 |
+
def clean_up(sentence):
|
19 |
+
# Find the left 10 characters of each "<<"
|
20 |
+
matches = [match.start() for match in re.finditer(r'<<', sentence)]
|
21 |
+
|
22 |
+
for match in matches:
|
23 |
+
# Get the left 10 characters of each "<<"
|
24 |
+
left_chars = sentence[match-20:match]
|
25 |
+
modified_chars = sentence[match-20:match].replace('x', '*').replace('X', '*')
|
26 |
+
|
27 |
+
# Check if "x" or "X" is in the left 10 characters
|
28 |
+
if 'x' in left_chars or 'X' in left_chars:
|
29 |
+
# Replace "x" or "X" with "*"
|
30 |
+
sentence = sentence.replace(left_chars, modified_chars)
|
31 |
+
|
32 |
+
##############################################################################################################
|
33 |
+
|
34 |
+
# Define a pattern to match text between "<< and >>"
|
35 |
+
pattern = r"<<(.*?)>>"
|
36 |
+
|
37 |
+
# Use re.sub to replace matched patterns with an empty string
|
38 |
+
sentence = re.sub(pattern, "", sentence)
|
39 |
+
|
40 |
+
##############################################################################################################
|
41 |
+
# Find all occurrences of "*"
|
42 |
+
asterisks = [i for i, char in enumerate(sentence) if char == '*']
|
43 |
+
|
44 |
+
# Check and add spaces around "*"
|
45 |
+
for index in reversed(asterisks):
|
46 |
+
if index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] != ' ':
|
47 |
+
sentence = sentence[:index] + ' ' + sentence[index] + ' ' + sentence[index + 1:]
|
48 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] == ' ':
|
49 |
+
sentence = sentence[:index] + ' ' + sentence[index] + sentence[index + 1:]
|
50 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] == ' ' and sentence[index + 1] != ' ':
|
51 |
+
sentence = sentence[:index] + sentence[index] + ' ' + sentence[index + 1:]
|
52 |
+
|
53 |
+
#
|
54 |
+
# Find all occurrences of "/"
|
55 |
+
asterisks = [i for i, char in enumerate(sentence) if char == '/']
|
56 |
+
|
57 |
+
# Check and add spaces around "*"
|
58 |
+
for index in reversed(asterisks):
|
59 |
+
if index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] != ' ':
|
60 |
+
sentence = sentence[:index] + ' ' + sentence[index] + ' ' + sentence[index + 1:]
|
61 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] == ' ':
|
62 |
+
sentence = sentence[:index] + ' ' + sentence[index] + sentence[index + 1:]
|
63 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] == ' ' and sentence[index + 1] != ' ':
|
64 |
+
sentence = sentence[:index] + sentence[index] + ' ' + sentence[index + 1:]
|
65 |
+
|
66 |
+
#
|
67 |
+
# Find all occurrences of "+"
|
68 |
+
asterisks = [i for i, char in enumerate(sentence) if char == '+']
|
69 |
+
|
70 |
+
# Check and add spaces around "*"
|
71 |
+
for index in reversed(asterisks):
|
72 |
+
if index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] != ' ':
|
73 |
+
sentence = sentence[:index] + ' ' + sentence[index] + ' ' + sentence[index + 1:]
|
74 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] == ' ':
|
75 |
+
sentence = sentence[:index] + ' ' + sentence[index] + sentence[index + 1:]
|
76 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] == ' ' and sentence[index + 1] != ' ':
|
77 |
+
sentence = sentence[:index] + sentence[index] + ' ' + sentence[index + 1:]
|
78 |
+
|
79 |
+
#
|
80 |
+
# Find all occurrences of "-"
|
81 |
+
asterisks = [i for i, char in enumerate(sentence) if char == '-']
|
82 |
+
|
83 |
+
# Check and add spaces around "-"
|
84 |
+
for index in reversed(asterisks):
|
85 |
+
if index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] != ' ':
|
86 |
+
sentence = sentence[:index] + ' ' + sentence[index] + ' ' + sentence[index + 1:]
|
87 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] == ' ':
|
88 |
+
sentence = sentence[:index] + ' ' + sentence[index] + sentence[index + 1:]
|
89 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] == ' ' and sentence[index + 1] != ' ':
|
90 |
+
sentence = sentence[:index] + sentence[index] + ' ' + sentence[index + 1:]
|
91 |
+
|
92 |
+
# Find all occurrences of "="
|
93 |
+
asterisks = [i for i, char in enumerate(sentence) if char == '=']
|
94 |
+
|
95 |
+
# Check and add spaces around "="
|
96 |
+
for index in reversed(asterisks):
|
97 |
+
if index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] != ' ':
|
98 |
+
sentence = sentence[:index] + ' ' + sentence[index] + ' ' + sentence[index + 1:]
|
99 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] != ' ' and sentence[index + 1] == ' ':
|
100 |
+
sentence = sentence[:index] + ' ' + sentence[index] + sentence[index + 1:]
|
101 |
+
elif index > 0 and index < len(sentence) - 1 and sentence[index - 1] == ' ' and sentence[index + 1] != ' ':
|
102 |
+
sentence = sentence[:index] + sentence[index] + ' ' + sentence[index + 1:]
|
103 |
+
|
104 |
+
return sentence
|
105 |
+
|
106 |
+
|
107 |
# Retrieve the path of training and testing databases
|
108 |
context_feat = Features({"question": Value(dtype='string', id=None), "answer": Value(dtype='string', id=None)})
|
109 |
train_set = load_dataset('json', data_files='train.jsonl', split='train', features=context_feat)
|
110 |
|
111 |
data = []
|
112 |
for example in train_set:
|
113 |
+
# Get the label answer --> gsm8k_answers
|
114 |
number = example['answer'].split('#### ')[1]
|
115 |
number = int(number.replace(',', ''))
|
|
|
|
|
116 |
append = "\nThe answer is: " + str(number)
|
117 |
answer = example['answer'] + append
|
118 |
+
answer = clean_up(sentence=answer)
|
119 |
|
|
|
120 |
question = example['question']
|
121 |
data.append({"question": question, "answer": answer})
|
122 |
|
123 |
+
# Save the modified data to a jsonl file
|
124 |
output_file = 'gsm8k_train.jsonl'
|
125 |
with jsonlines.open(output_file, 'w') as writer:
|
126 |
writer.write_all(data)
|