MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / strip_string

Method strip_string

test/general/lm_eval/tasks/hendrycks_math.py:219–281  ·  view source on GitHub ↗
(self, string)

Source from the content-addressed store, hash-verified

217 return False
218
219 def strip_string(self, string):
220 # linebreaks
221 string = string.replace("\n", "")
222
223 # remove inverse spaces
224 string = string.replace("\\!", "")
225
226 # replace \\ with \
227 string = string.replace("\\\\", "\\")
228
229 # replace tfrac and dfrac with frac
230 string = string.replace("tfrac", "frac")
231 string = string.replace("dfrac", "frac")
232
233 # remove \left and \right
234 string = string.replace("\\left", "")
235 string = string.replace("\\right", "")
236
237 # Remove circ (degrees)
238 string = string.replace("^{\\circ}", "")
239 string = string.replace("^\\circ", "")
240
241 # remove dollar signs
242 string = string.replace("\\$", "")
243
244 # remove units (on the right)
245 string = self.remove_right_units(string)
246
247 # remove percentage
248 string = string.replace("\\%", "")
249 string = string.replace("\%", "") # noqa: W605
250
251 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
252 string = string.replace(" .", " 0.")
253 string = string.replace("{.", "{0.")
254 # if empty, return empty string
255 if len(string) == 0:
256 return string
257 if string[0] == ".":
258 string = "0" + string
259
260 # to consider: get rid of e.g. "k = " or "q = " at beginning
261 if len(string.split("=")) == 2:
262 if len(string.split("=")[0]) <= 2:
263 string = string.split("=")[1]
264
265 # fix sqrt3 --> sqrt{3}
266 string = self.fix_sqrt(string)
267
268 # remove spaces
269 string = string.replace(" ", "")
270
271 # \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc. Even works with \frac1{72} (but not \frac{72}1). Also does a/b --> \\frac{a}{b}
272 string = self.fix_fracs(string)
273
274 # manually change 0.5 --> \frac{1}{2}
275 if string == "0.5":
276 string = "\\frac{1}{2}"

Callers 1

is_equivMethod · 0.95

Calls 4

remove_right_unitsMethod · 0.95
fix_sqrtMethod · 0.95
fix_fracsMethod · 0.95
fix_a_slash_bMethod · 0.95

Tested by

no test coverage detected