OpenAI GPT-2 model use with TensorFlow JS

不打扰是莪最后的温柔 提交于 2020-08-08 08:22:26

问题


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

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


回答1:


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 tensorflowjs

save.py

from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
import tensorflowjs
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.



来源:https://stackoverflow.com/questions/62677651/openai-gpt-2-model-use-with-tensorflow-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!