【问题标题】:Get output of the last 4 layers of BERT (Tensorflow)获取BERT最后4层的输出(Tensorflow)
【发布时间】:2020-05-18 16:31:08
【问题描述】:

我正在阅读 Andreas Poyiatzis 发表在 fardatascience.com 上的文章。以下是文章的链接。

https://towardsdatascience.com/nlp-extract-contextualized-word-embeddings-from-bert-keras-tf-67ef29f60a7b#--responses

生成的嵌入是通过使用 TPU 生成的。但我想在不支持 TPU 的本地机器上运行它。有人可以让我知道如何在 CPU 上运行相同的代码吗?您的帮助将不胜感激。谢谢!

【问题讨论】:

    标签: tensorflow tensorflow2.0 bert-language-model tpu tensorflow-hub


    【解决方案1】:

    在链接之后,代码显示如果没有可用的 TPU,Estimator 将回退到 CPU 或 GPU。只要确保在它出现的任何地方都设置了use_tpu = False

      # If TPU is not available, this will fall back to normal Estimator on CPU
      # or GPU.
      estimator = tf.contrib.tpu.TPUEstimator(
          use_tpu=False,
          model_fn=model_fn,
          config=run_config,
          predict_batch_size=BATCH_SIZE,
          train_batch_size=BATCH_SIZE)
    

    也直接在model_fn_builder 调用中。像这样:

    model_fn = model_fn_builder(
          bert_config=bert_config,
          init_checkpoint=INIT_CHECKPOINT,
          layer_indexes=layer_indexes,
          use_tpu=False,
          use_one_hot_embeddings=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      相关资源
      最近更新 更多