Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if field in new_data:
new_data[field] = string_beautify(new_data[field])
new_data.update(constant_data)
new_data["pairID"] = str(pairID)
pairID += 1
if pairID % 100 == 0:
print("%d sentences generated" % pairID)
output_writer.write(new_data)
except Exception as e:
self.log_exception(e)
print(self.get_stack_trace(e))
error_counter += 1
if error_counter > number_to_generate // 5:
pass
# raise Exception("Over 20\% of samples result in errors. You should fix this.")
jsonlines.Writer(output).write_all(generated_data)
past_sentences.append(track_sentence)
for C in new_data:
for field in self.data_fields:
if field in C:
C[field] = string_beautify(C[field])
C.update(constant_data)
generated_data.append(C)
except Exception as e:
self.log_exception(e)
print(self.get_stack_trace(e))
# error_counter += 1
# if error_counter >= number_to_generate // 10:
# raise Exception("Over 10\% of samples result in errors. You should fix this.")
jsonlines.Writer(output).write_all(generated_data)
def test_custom_dumps():
fp = io.BytesIO()
writer = jsonlines.Writer(fp, dumps=lambda obj: 'oh hai')
with writer:
writer.write({})
assert fp.getvalue() == b'oh hai\n'
def print_json(value):
with jsonlines.Writer(sys.stdout) as out:
out.write(value)
while wav_path.exists():
# Find unique name
count += 1
wav_path = get_wav_path(text, count)
wav_bytes = core.buffer_to_wav(audio_data)
wav_path.write_bytes(wav_bytes)
# Save transcription
transcript_path = examples_dir / f"{wav_path.stem}.txt"
transcript_path.write_text(text)
# Save intent
intent_path = examples_dir / f"{wav_path.stem}.json"
with open(intent_path, "w") as intent_file:
with jsonlines.Writer(intent_file) as out:
# pylint: disable=E1101
out.write(random_intent)
# Response
print("Wrote", wav_path)
print("")
finally:
record_task.cancel()
try:
await audio_source.close()
except Exception:
pass
def print_json(value):
if json_file is not None:
with jsonlines.Writer(json_file) as out:
out.write(value)
json_file.flush()
def fix_ngram():
with jsonlines.open(file) as reader:
for obj in reader:
with jsonlines.Writer(open(os.path.join(results_dir, "blimp_ngram_simplelm_peephole.jsonl"), "w")) as writer:
writer.write_all(obj)