hankcs/HanLP · error · FileNotFoundError
The identifier {save_dir} resolves to a nonexistent meta fil
Error message
The identifier {save_dir} resolves to a nonexistent meta file {metapath}. {tips} What it means
HanLP resolves a model identifier to a save directory containing config.json. If the path exists but no meta file (config.json) is found there — and the identifier is not a fasttext-style model — load_from_meta_file raises FileNotFoundError with the resolved path and a hint.
Source
Thrown at hanlp/utils/component_util.py:76
'embed': {'classpath': 'hanlp.layers.embeddings.word2vec.Word2VecEmbedding',
'embed': identifier, 'field': 'token', 'normalize': 'l2'},
'hanlp_version': version.__version__}, metapath)
elif identifier in pretrained.fasttext.ALL.values():
save_dir = os.path.dirname(save_dir)
metapath = os.path.join(save_dir, 'config.json')
save_json({'classpath': 'hanlp.layers.embeddings.fast_text.FastTextEmbeddingComponent',
'embed': {'classpath': 'hanlp.layers.embeddings.fast_text.FastTextEmbedding',
'filepath': identifier, 'src': 'token'},
'hanlp_version': version.__version__}, metapath)
elif identifier in {pretrained.classifiers.LID_176_FASTTEXT_SMALL,
pretrained.classifiers.LID_176_FASTTEXT_BASE}:
save_dir = os.path.dirname(save_dir)
metapath = os.path.join(save_dir, 'config.json')
save_json({'classpath': 'hanlp.components.classifiers.fasttext_classifier.FastTextClassifier',
'model_path': identifier,
'hanlp_version': version.__version__}, metapath)
else:
raise FileNotFoundError(f'The identifier {save_dir} resolves to a nonexistent meta file {metapath}. {tips}')
meta: dict = load_json(metapath)
cls = meta.get('classpath', cls)
if not cls:
cls = meta.get('class_path', None) # For older version
if tf_model:
# tf models are trained with version < 2.1. To migrate them to 2.1, map their classpath to new locations
upgrade = {
'hanlp.components.tok_tf.TransformerTokenizerTF': 'hanlp.components.tokenizers.tok_tf.TransformerTokenizerTF',
'hanlp.components.pos.RNNPartOfSpeechTagger': 'hanlp.components.taggers.pos_tf.RNNPartOfSpeechTaggerTF',
'hanlp.components.pos_tf.RNNPartOfSpeechTaggerTF': 'hanlp.components.taggers.pos_tf.RNNPartOfSpeechTaggerTF',
'hanlp.components.pos_tf.CNNPartOfSpeechTaggerTF': 'hanlp.components.taggers.pos_tf.CNNPartOfSpeechTaggerTF',
'hanlp.components.ner_tf.TransformerNamedEntityRecognizerTF': 'hanlp.components.ner.ner_tf.TransformerNamedEntityRecognizerTF',
'hanlp.components.parsers.biaffine_parser.BiaffineDependencyParser': 'hanlp.components.parsers.biaffine_parser_tf.BiaffineDependencyParserTF',
'hanlp.components.parsers.biaffine_parser.BiaffineSemanticDependencyParser': 'hanlp.components.parsers.biaffine_parser_tf.BiaffineSemanticDependencyParserTF',
'hanlp.components.tok_tf.NgramConvTokenizerTF': 'hanlp.components.tokenizers.tok_tf.NgramConvTokenizerTF',
'hanlp.components.classifiers.transformer_classifier.TransformerClassifier': 'hanlp.components.classifiers.transformer_classifier_tf.TransformerClassifierTF',
'hanlp.components.taggers.transformers.transformer_tagger.TransformerTagger': 'hanlp.components.taggers.transformers.transformer_tagger_tf.TransformerTaggerTF',
'hanlp.components.tok.NgramConvTokenizer': 'hanlp.components.tokenizers.tok_tf.NgramConvTokenizerTF',View on GitHub (pinned to ddb1299bdd)
Solutions
- Check the spelled-out metapath in the message — usually the identifier is off by one path segment; correct it against the model list in HanLP docs.
- If the model was partially downloaded, delete the incomplete folder under the HanLP cache and retry the load to re-download.
- If you relocated the model, ensure config.json sits next to the model file inside save_dir (or create one with classpath and model_path keys).
Defensive patterns
Strategy: validation
Validate before calling
import os
meta = os.path.join(save_dir, 'config.json')
assert os.path.isfile(meta), f'{meta} missing; check model id' Try / catch
try:
comp = hanlp.load(identifier)
except FileNotFoundError as e:
# clean cache and retry once with corrected id
raise Prevention
- Keep model ids as constants copied from the official model table.
- After downloads, verify config.json exists in the model dir.
When it happens
Trigger: Calling hanlp.load(...) / load_from_meta_file with a close-to-correct identifier whose directory exists but lacks config.json: e.g. omitting a trailing path segment, pointing at a cache dir, or a partially downloaded model.
Common situations: Typos in the model id (e.g. missing the task subfolder); interrupted first download leaving an incomplete directory; moving/renaming model folders so config.json is no longer beside the weights; older models whose meta uses different layout.
Related errors
- error
- output ({}) must be of type bool or str
- Call fit or load before evaluate.
- Unrecognized devices {devices}
- Unsupported argument length: {item}
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/3cb81549a6338501.
Report an issue: GitHub.