简体   繁体   English

如何使用Github和CheckPoint文件中预先训练的Tensorflow模型进行推理

[英]How to run inference using pre-trained Tensorflow model from their Github and CheckPoint file

I would like to collect text embeddings from the model in this github 我想从这个github中的模型中收集文本嵌入

https://github.com/dmis-lab/biobert https://github.com/dmis-lab/biobert

Under installation, all it says is 在安装下,它说的都是

To use BioBERT, we need pre-trained weights of BioBERT, which you can download from Naver GitHub repository for BioBERT pre-trained weights. 要使用BioBERT,我们需要预先培训的BioBERT重量,您可以从Naver GitHub存储库下载BioBERT预训练重量。 Make sure to specify the versions of pre-trained weights used in your works. 确保指定您作品中使用的预训练重量的版本。 Also, note that this repository is based on the BERT repository by Google. 另请注意,此存储库基于Google的BERT存储库。

All the fine-tuning experiments were conducted on a single TITAN Xp GPU machine which has 12GB of RAM. 所有的微调实验都是在一台拥有12GB内存的TITAN Xp GPU机器上进行的。 The code was tested with Python2 and Python3 (We used Python2 for experiments). 代码用Python2和Python3测试(我们使用Python2进行实验)。 You might want to install java to use official evaluation script of BioASQ. 您可能希望安装java以使用BioASQ的官方评估脚本。 See requirements.txt for other details. 有关其他详细信息,请参阅requirements.txt。

I can download their checkpoint file and load it using something like 我可以下载他们的检查点文件并使用类似的东西加载它

with tf.Session(graph=graph) as session:

   saver.restore(session, 'BioBert.ckpt' )

And install their github using something like 并使用类似的东西安装他们的github

!test -d bioBert_repo|| git clone https://github.com/dmis-lab/biobert bioBert_repo

But how do I get the embedding from a text input. 但是如何从文本输入中获取嵌入。 The instructions say it's based on BERT, but for BERT all we have to do is import the tf.hub model 说明说它基于BERT,但是对于BERT,我们所要做的就是导入tf.hub模型

bert_module = hub.Module(
 "https://tfhub.dev/google/bert_uncased_L-12_H-768_A-12/1",
 trainable=False)

then put the tokenized sentence into that 然后将标记化的句子放入其中

bert_embedding= bert_module(inputs=tokenized_sentence, signature="tokens", as_dict=True)[
       "pooled_output"
   ]

I'm guessing there's a similar method where I can install the github and load the weights but I can't seem to find it. 我猜有一个类似的方法,我可以安装github并加载权重,但我似乎无法找到它。

You should see example from extract_features.py. 您应该看一下extract_features.py中的示例。 I suppose that BIOBert don't use tf.hub. 我想BIOBert不使用tf.hub。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 恢复预训练模型的Tensorflow检查点文件 - Restoring Tensorflow checkpoint files of a pre-trained model 到logits层的Tensorflow推理-适用于预训练模型上的批次 - Tensorflow inference upto logits layer - for batches on pre-trained model 如何在TensorFlow中使用预训练模型 - How to use pre-trained model in TensorFlow 如何在 tensorflow 中使用预训练的 model 进行预测? - how to predict with pre-trained model in tensorflow? 从 Tensorflow 中的 Unity ml-agents 推断预训练的 ONNX model - Inference on pre-trained ONNX model from Unity ml-agents in Tensorflow 运行 run_squad.py 以微调 Google BERT 模型(官方 tensorflow 预训练模型)时无法加载(恢复)TensorFlow 检查点 - Failed to load(restore) TensorFlow checkpoint when running run_squad.py to fine-tune the Google BERT model(official tensorflow pre-trained model) 无法加载预训练的 model 检查点与 TensorFlow Object 检测 ZDB974238714CA8DE634A7ACE1 - Unable to load pre-trained model checkpoint with TensorFlow Object Detection API Tensorflow Hub 和 JS:如何微调预训练模型并将其导出以在 Tensorflow.js 中使用? - Tensorflow Hub and JS: how to fine-tune a pre-trained model and export it for using in Tensorflow.js? 来自预训练 tensorflow model 的混淆矩阵 - Confusion matrix from pre-trained tensorflow model Tensorflow如何修改保存为检查点的预训练模型 - Tensorflow how to modify a pre-trained Model saved as checkpoints
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM