Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator
- math_functions = {
- '+': operator.add,
- '-': operator.sub,
- '*': operator.mul,
- '/': operator.truediv
- }
- #with open("output_dev_20k", "r") as f:
- # output = f.read().split('\n')
- output = [
- '-190816',
- '261523620432',
- '583719',
- '0.9739',
- '719901',
- ]
- #with open("tst2012.from", "r") as f:
- # from_data = f.read().split('\n')
- from_data = [
- '219459 - 410275',
- '265572 * 984756',
- '584986 - 1267',
- '879174 / 902737',
- '520354 + 199547',
- ]
- right = 0
- total = 0
- for n, _ in enumerate(output):
- try:
- num = from_data[n].split(' ')
- real_answer = math_functions[num[1]](int(num[0]), int(num[2]))
- if num[1] == '/':
- real_answer = round(real_answer, 4)
- predicted_answer = float(output[n])
- if predicted_answer == real_answer:
- right += 1
- total += 1
- print(real_answer, predicted_answer)
- except Exception as e:
- print(str(e))
- print(right / total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement