Created
August 11, 2020 01:03
-
-
Save lfoppiano/3aca6180bcd338a7c624737b3813e200 to your computer and use it in GitHub Desktop.
Migrate delft preprocessors to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import pathlib | |
import sys | |
from delft.sequenceLabelling.preprocess import WordPreprocessor | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print("Invalid parameters. Usage: python json_migration.py model directory. " | |
"The new preprocessor will be saved in the same directory as the old preprocessor ") | |
sys.exit(-1) | |
input_directory = sys.argv[1] | |
if os.path.isdir(input_directory): | |
for file in os.listdir(input_directory): | |
if file.endswith("preprocessor.pkl"): | |
input_file= pathlib.Path(input_directory, file) | |
p = WordPreprocessor().load(input_file) | |
output_dict = vars(p) | |
output_path = pathlib.Path(input_file.with_suffix('').as_posix() + '.json') | |
with open(output_path, 'w') as fp: | |
json.dump(output_dict, fp, sort_keys=False, indent=4) | |
elif os.path.isfile(input_directory): | |
print("Please specify a directory where the model is located. ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps:
2dad199dbc6e011ae3b270b260e4784b7ffe2d17
<activate the delft virtual environment>
data/models/sequenceLabelling/my_model_I_want_to_migrate/
You should have a new file preprocessor.json in the
data/models/sequenceLabelling/my_model_I_want_to_migrate/
directory