Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(path):
reddit = Reddit(path)
for comment in reddit:
print(srsly.json_dumps(comment))
serializers["meta.json"] = lambda p: p.open("w").write(
srsly.json_dumps(self.meta)
)
title="Package directory already exists",
text="Please delete the directory and try again, or use the "
"`--force` flag to overwrite existing directories.",
exits=1,
)
Path.mkdir(package_path, parents=True, exist_ok=True)
for f in REQUIRED_MODEL_FILES:
file_name: Path = input_path / f
if not file_name.exists():
msg.fail(
f"Input path '{input_path}' is missing a required file: '{f}'",
"This file is required to build your package.",
exits=1,
)
shutil.copyfile(file_name, main_path / f)
create_file(output_path / "model.config.json", srsly.json_dumps(meta, indent=2))
create_file(output_path / "setup.py", TEMPLATE_SETUP)
create_file(package_path / "__init__.py", TEMPLATE_INIT)
msg.good("Successfully created package '{}'".format(package_path), main_path)
msg.text("To build the package, run `python setup.py sdist` in this directory.")
return str(package_path)
def _save_model(epoch, is_temp=False):
is_temp_str = ".temp" if is_temp else ""
with model.use_params(optimizer.averages):
with (output_dir / ("model%d%s.bin" % (epoch, is_temp_str))).open(
"wb"
) as file_:
file_.write(model.tok2vec.to_bytes())
log = {
"nr_word": tracker.nr_word,
"loss": tracker.loss,
"epoch_loss": tracker.epoch_loss,
"epoch": epoch,
}
with (output_dir / "log.jsonl").open("a") as file_:
file_.write(srsly.json_dumps(log) + "\n")
title="Package directory already exists",
text="Please delete the directory and try again, or use the "
"`--force` flag to overwrite existing directories.",
exits=1,
)
Path.mkdir(package_path, parents=True, exist_ok=True)
for f in REQUIRED_MODEL_FILES:
file_name: Path = input_path / f
if not file_name.exists():
msg.fail(
f"Input path '{input_path}' is missing a required file: '{f}'",
"This file is required to build your package.",
exits=1,
)
shutil.copyfile(file_name, main_path / f)
create_file(output_path / "model.config.json", srsly.json_dumps(meta, indent=2))
create_file(output_path / "setup.py", TEMPLATE_SETUP)
create_file(package_path / "__init__.py", TEMPLATE_INIT)
msg.good("Successfully created package '{}'".format(package_path), main_path)
msg.text("To build the package, run `python setup.py sdist` in this directory.")
return str(package_path)
serializers["meta.json"] = lambda: srsly.json_dumps(self.meta)
for name, proc in self.pipeline:
package_path = main_path / model_name
if package_path.exists():
if force:
shutil.rmtree(path2str(package_path))
else:
msg.fail(
"Package directory already exists",
"Please delete the directory and try again, or use the "
"`--force` flag to overwrite existing "
"directories.".format(path=path2str(package_path)),
exits=1,
)
Path.mkdir(package_path, parents=True)
shutil.copytree(path2str(input_path), path2str(package_path / model_name_v))
create_file(main_path / "meta.json", srsly.json_dumps(meta, indent=2))
create_file(main_path / "setup.py", TEMPLATE_SETUP)
create_file(main_path / "MANIFEST.in", TEMPLATE_MANIFEST)
create_file(package_path / "__init__.py", TEMPLATE_INIT)
msg.good("Successfully created package '{}'".format(model_name_v), main_path)
msg.text("To build the package, run `python setup.py sdist` in this directory.")
terms = DB.get_dataset(dataset)
log(
"RECIPE: Reading {} input terms from dataset {}".format(len(terms), dataset)
)
if output_file:
patterns = [
get_pattern(term, label) for term in terms if term["answer"] == "accept"
]
log("RECIPE: Generated {} patterns".format(len(patterns)))
srsly.write_jsonl(output_file, patterns)
prints("Exported {} patterns".format(len(patterns)), output_file)
else:
log("RECIPE: Outputting patterns")
for term in terms:
if term["answer"] == "accept":
print(srsly.json_dumps(get_pattern(term, label)))