How to use the jsonlines.Writer function in jsonlines

To help you get started, we’ve selected a few jsonlines examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexwarstadt / data_generation / utils / data_generator.py View on Github external
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)
github alexwarstadt / data_generation / utils / data_generator.py View on Github external
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)
github wbolster / jsonlines / tests / test_jsonlines.py View on Github external
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'
github synesthesiam / voice2json / recipes / deepspeech / deep_transcribe.py View on Github external
def print_json(value):
        with jsonlines.Writer(sys.stdout) as out:
            out.write(value)
github synesthesiam / voice2json / voice2json / record.py View on Github external
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
github synesthesiam / voice2json / voice2json / command / webrtcvad.py View on Github external
def print_json(value):
        if json_file is not None:
            with jsonlines.Writer(json_file) as out:
                out.write(value)

            json_file.flush()
github alexwarstadt / data_generation / results_processing / blimp / process_peephole_jsonl.py View on Github external
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)

jsonlines

Library with helpers for the jsonlines file format

BSD-2-Clause
Latest version published 11 months ago

Package Health Score

72 / 100
Full package analysis

Similar packages