Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sess.run(tf.assign(model.is_train, tf.constant(False, dtype=tf.bool)))
losses = []
answer_dict = {}
remapped_dict = {}
for step in tqdm(range(total // config.batch_size + 1)):
qa_id, loss, yp1, yp2 = sess.run(
[model.qa_id, model.loss, model.yp1, model.yp2])
answer_dict_, remapped_dict_ = convert_tokens(
eval_file, qa_id.tolist(), yp1.tolist(), yp2.tolist())
answer_dict.update(answer_dict_)
remapped_dict.update(remapped_dict_)
losses.append(loss)
loss = np.mean(losses)
metrics = evaluate(eval_file, answer_dict)
with open(config.answer_file, "w") as fh:
json.dump(remapped_dict, fh)
print("Exact Match: {}, F1: {}".format(
metrics['exact_match'], metrics['f1']))
remapped_dict = {}
for step in tqdm(range(total // config.batch_size + 1)):
qa_id, loss, yp1, yp2 = sess.run(
[model.qa_id, model.loss, model.yp1, model.yp2])
answer_dict_, remapped_dict_, outlier = convert_tokens(
eval_file, qa_id.tolist(), yp1.tolist(), yp2.tolist())
answer_dict.update(answer_dict_)
remapped_dict.update(remapped_dict_)
losses.append(loss)
loss = np.mean(losses)
# evaluate with answer_dict, but in evaluate-v1.1.py, evaluate with remapped_dict
# since only that is saved. Both dict are a little bit different, check evaluate-v1.1.py
metrics = evaluate(eval_file, answer_dict)
with open(config.answer_file, "w") as fh:
json.dump(remapped_dict, fh)
print("Exact Match: {}, F1: {} Rouge-L-F1: {} Rouge-L-p: {} Rouge-l-r: {}".format(\
metrics['exact_match'], metrics['f1'], metrics['rouge-l-f'], metrics['rouge-l-p'],\
metrics['rouge-l-r']))
def get_five_acccount_ids(self, test_server):
accounts = []
for i in range(1, 6):
payload = {"emailAddress": f"test{i}@example.com", "password": "1234567"}
res = test_server.post("/signup", data=ujson.dumps(payload))
resData = res.json()
accounts.append(resData["id"])
return accounts
def get_hash(obj):
return hashlib.shake_128(json.dumps(obj).encode("utf-8")).hexdigest(16)
def test_on_message_when_type_message(self):
redis, app, bus = self.get_bus()
handler_mock = Mock()
bus.throttling = {}
bus.handlers['events']['uuid'] = handler_mock
value = dumps({'type': 'test'})
bus.on_message(('message', 'events', value))
expect(handler_mock.called).to_be_true()
def fetch_schema(conn):
"""
Fetch the Solr schema in JSON format via the provided pysolr
connection object (`conn`).
"""
jsn = conn._send_request('get', 'schema/fields?wt=json')
return ujson.loads(jsn)
def test_encodeTrueConversion(self):
input = True
output = ujson.encode(input)
self.assertEquals(input, json.loads(output))
self.assertEquals(output, json.dumps(input))
self.assertEquals(input, ujson.decode(output))
pass
def test_decodeDictWithNoKey(self):
input = "{{{{31337}}}}"
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"
def test_encodeDoubleNegConversion(self):
input = -math.pi
output = ujson.encode(input)
self.assertEquals(round(input, 5), round(json.loads(output), 5))
self.assertEquals(round(input, 5), round(ujson.decode(output), 5))
pass
def test_decodeBrokenObjectStart(self):
input = "{"
try:
ujson.decode(input)
assert False, "Expected exception!"
except(ValueError):
return
assert False, "Wrong exception"