Search code examples
tensorflowmachine-learningnlptensorflow.jsgpt-2

OpenAI GPT-2 model use with TensorFlow JS


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

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


Solution

  • It's possible. Maybe someone finds this useful in 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)

    • 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.

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

    • 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 (example, talk)