{"record":{"id":"3cd214ee1974d99a","repo":"tensorflow/models","slug":"import-tensorflow-text-failed-please-install-ten","errorCode":null,"errorMessage":"import tensorflow_text failed, please install 'tensorflow-text-nightly'.","messagePattern":"import tensorflow_text failed, please install 'tensorflow-text-nightly'\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/text_layers.py","lineNumber":38,"sourceCode":"import tensorflow as tf, tf_keras\n\ntry:\n  # pytype: disable=import-error\n  import tensorflow_text as text\n  from tensorflow_text.python.ops import bert_tokenizer\n  # pytype: enable=import-error\nexcept ImportError:\n  text = None\n  bert_tokenizer = None\nexcept tf.errors.NotFoundError as e:\n  logging.warn(\"Encountered error when importing tensorflow_text: %s\", e)\n  text = None\n  bert_tokenizer = None\n\n\ndef _check_if_tf_text_installed():\n  if text is None:\n    raise ImportError(\"import tensorflow_text failed, please install \"\n                      \"'tensorflow-text-nightly'.\")\n\n\ndef _truncate_row_lengths(ragged_tensor: tf.RaggedTensor,\n                          new_lengths: tf.Tensor) -> tf.RaggedTensor:\n  \"\"\"Truncates the rows of `ragged_tensor` to the given row lengths.\"\"\"\n  new_lengths = tf.broadcast_to(new_lengths,\n                                ragged_tensor.bounding_shape()[0:1])\n  def fn(x):\n    row, new_length = x\n    return row[0:new_length]\n  fn_dtype = tf.RaggedTensorSpec(dtype=ragged_tensor.dtype,\n                                 ragged_rank=ragged_tensor.ragged_rank - 1)\n  result = tf.map_fn(fn, (ragged_tensor, new_lengths), dtype=fn_dtype)\n  # Work around broken shape propagation: without this, result has unknown rank.\n  flat_values_shape = [None] * ragged_tensor.flat_values.shape.rank\n  result = result.with_flat_values(\n      tf.ensure_shape(result.flat_values, flat_values_shape))","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/text_layers.py#L20-L56","documentation":"Error \"import tensorflow_text failed, please install 'tensorflow-text-nightly'.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/text_layers.py:38 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"}