allennlp-demo
allennlp-demo copied to clipboard
Include packages for new models
Right now, if a user has developed a task as a library (running it with allennlp train --include-package my_library ...), it will fail when its archive is included as a new model in the demo because its classes won't have been imported. For instance, a registered DatasetReader subclass referenced in config.json will cause a ConfigurationError to be thrown when running python app.py.
I think this can be avoided by adding something like a --include-package-path argument to app.py and then appending the directory to the system path before calling utils.import_submodules. I'm happy to submit a PR if this would be useful.
hi,I also have a import problem,can you give me some details of how to solve it?Thank you!
In app.py, you can add the following lines, then load your package by specifying a path to the folder containing the package with --include-package (the path need not be absolute). It's untested, but I may submit this as a PR along with some tests later in the month.
import pathlib
...
from allennlp.common.util import JsonDict, peak_memory_mb, import_submodules
...
if __name__ == "__main__":
...
parser.add_argument(
'--include-package',
type=str,
help='Load this package by specifying a path, e.g. ../path/package-name'
)
...
if args.include_package:
package_path = pathlib.Path(args.include_package)
sys.path.append(package_path.parent.as_posix())
import_submodules(package_path.name)