{"record":{"id":"8fb7e70a0ba376fc","repo":"tensorflow/models","slug":"must-set-exactly-one-of-vocab-file-sp-model-file","errorCode":null,"errorMessage":"Must set exactly one of vocab_file, sp_model_file","messagePattern":"Must set exactly one of vocab_file, sp_model_file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"official/nlp/tools/export_tfhub_lib.py","lineNumber":343,"sourceCode":"  Args:\n    vocab_file: The path to the wordpiece vocab file, or None.\n    sp_model_file: The path to the sentencepiece model file, or None. Exactly\n      one of vocab_file and sp_model_file must be set. This determines the type\n      of tokenzer that is used.\n    do_lower_case: Whether to do lower case.\n    tokenize_with_offsets: Whether to include the .tokenize_with_offsets\n      subobject.\n    default_seq_length: The sequence length of preprocessing results from root\n      callable. This is also the default sequence length for the\n      bert_pack_inputs subobject.\n\n  Returns:\n    A tf_keras.Model object with several attached subobjects, suitable for\n    saving as a preprocessing SavedModel.\n  \"\"\"\n  # Select tokenizer.\n  if bool(vocab_file) == bool(sp_model_file):\n    raise ValueError(\"Must set exactly one of vocab_file, sp_model_file\")\n  if vocab_file:\n    tokenize = layers.BertTokenizer(\n        vocab_file=vocab_file,\n        lower_case=do_lower_case,\n        tokenize_with_offsets=tokenize_with_offsets)\n  else:\n    tokenize = layers.SentencepieceTokenizer(\n        model_file_path=sp_model_file,\n        lower_case=do_lower_case,\n        strip_diacritics=True,  #  Strip diacritics to follow ALBERT model.\n        tokenize_with_offsets=tokenize_with_offsets)\n\n  # The root object of the preprocessing model can be called to do\n  # one-shot preprocessing for users with single-sentence inputs.\n  sentences = tf_keras.layers.Input(shape=(), dtype=tf.string, name=\"sentences\")\n  if tokenize_with_offsets:\n    tokens, start_offsets, limit_offsets = tokenize(sentences)\n  else:","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/tools/export_tfhub_lib.py#L325-L361","documentation":"Error \"Must set exactly one of vocab_file, sp_model_file\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/tools/export_tfhub_lib.py:343 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}