Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 927
jay Avatar asked Jul 01 '20 13:07

jay


People also ask

Does GPT use TensorFlow?

GPT-2 Pre-training and text generation, implemented in Tensorflow 2.0. Distributed training on multiple gpu.

What version of TensorFlow do I need for GPT-2?

If you intend to fine-tune gpt2 I recommend installing TensorFlow version 1.15.

Is TensorFlow JS used for machine learning?

js is a library for machine learning in JavaScript. Develop ML models in JavaScript, and use ML directly in the browser or in Node.

What can you do with GPT-2?

Trained on 40 GB of textual data, GPT-2 is a very large model containing a massive amount of compressed knowledge from a cross-section of the internet. GPT-2 has a lot of potential use cases. It can be used to predict the probability of a sentence. This, in turn, can be used for text autocorrection.


Video Answer


1 Answers

I don't see any reason as to why not, other than maybe some operation that is in gpt-2 that is not supported by tensorflowjs.

I don't know how to do it, but here's a nice starting point:

install.sh

python3 -m pip install -q git+https://github.com/huggingface/transformers.git
python3 -m pip install tensorflow

save.py

from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
# add the EOS token as PAD token to avoid warnings
model = TFGPT2LMHeadModel.from_pretrained("gpt2", pad_token_id=tokenizer.eos_token_id)
model.save("./test_gpt2")

that will give you a SavedModel file. Now you can try figure out the input and output nodes, and use tensorflowjs_converter to try and convert it. Pointer: https://www.tensorflow.org/js/tutorials/conversion/import_saved_model.

like image 50
Frederik Bode Avatar answered Oct 24 '22 09:10

Frederik Bode