PEGASUS 从 pytorch 到 tensorflow

PEGASUS From pytorch to tensorflow

我使用 this script 微调了 PEGASUS 模型进行抽象摘要,其中使用了 huggingface。 输出模型在pytorch.

有没有办法将它转换为张量流模型,以便我可以在 javascript 后端中使用它?

您可以通过多种方式实现转换,其中一些甚至可能根本不需要 Tensorflow。

首先,做你想做的事情的方式:根据 transformer implementation notes. This is important, because there exists a script to convert PyTorch checkpoints to TF2 checkpoints,PEGASUS 似乎完全基于 BartForConditionalGeneration 模型。虽然此脚本不会明确 允许您转换 PEGASUS 模型,但它确实有适用于 BART 的选项。 运行 它与相应的参数应该会给你想要的输出。

或者,您可以通过将模型导出为 ONNX 格式来达到同样的效果,该格式也具有 JS deployment options. Specific details for how to convert a Huggingface model to ONNX can be found here