OpenAI GPT-2 model use with TensorFlow JS

发布于:2024-08-15 ⋅ 阅读:(182) ⋅ 点赞:(0)

题意:使用 TensorFlow JS 应用 OpenAI GPT-2 模型

问题背景:

Is that possible to generate texts from OpenAI GPT-2 using TensorFlowJS?

是否可以使用 TensorFlowJS 生成 OpenAI GPT-2 的文本?

If not what is the limitation, like model format or ...?

如果不能,那么限制是什么,比如模型格式或者其他因素?

问题解决:

It's possible. Maybe someone finds this useful in 2023:

这是可能的。也许有人在 2023 年会觉得这个信息有用:

  • One way to achieve this is to convert a TF model with tensorflowjs-converter as Frederik described (possible problem with this approach is missing custom layers)

一种实现方式是将 TF 模型转换为 TensorFlow.js 格式,使用 tensorflowjs-converter,正如 Frederik 描述的那样(这种方法可能存在的问题是缺少自定义层)。

  • Use gpt-tfjs - implementation of GPT model in TensorFlow.js. It's possible to load weights directly from HF (example). I developed it to experiment with model training in the browser.

使用 gpt-tfjs —— 在 TensorFlow.js 中实现 GPT 模型。可以直接从 HF 加载权重(示例)。我开发了它以在浏览器中实验模型训练。

If you just want to generate text without training, you have more options:

如果你只是想生成文本而不进行训练,你还有更多的选择:

使用 transformers.js 或 ONNX。这个库很棒,并且遵循了 Python 的 transformers 库 API。不幸的是——仅支持推理。

使用 ggml + WASM。这是一个 C/C++ 模型实现,编译为 WebAssembly(示例,讨论)。

    • Use transformers.js or ONNX in general. The lib is great and follows Python's transformers library API. Unfortunately - inference only.
    • Use ggml + WASM. It's a C/C++ model implementation compiled to WebAssembly (exampletalk)

网站公告

今日签到

点亮在社区的每一天
去签到