huggingface-transformers - Huggingface transformer export tokenizer and model
问题描述
I'm currently working on a text summarizer powered by the Huggingface transformers library. The summarization process has to be done on premise, as such I have the following code (close to documentation):
from transformers import BartTokenizer, BartForConditionalGeneration, BartConfig
model = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-cnn-6-6')
tokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-cnn-6-6')
inputs = tokenizer([myTextToSummarize], max_length=1024, return_tensors='pt')
summary_ids = model.generate(inputs['input_ids'], num_beams=4, early_stopping=True)
[tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids]
My problem is that I cannot load the model in memory and have my server expose an API which can directly use model
and tokenizer
, I would like both of them to be initialized in a first process, and made available in a second one (one that will expose an HTTP API). I saw that you can export the model on the filesystem, but again, I don't have access to it (locked k8s environment), and I'd need to store it in a specific database.
Is it possible to export both the model
and the tokenizer
as string/buffer/something storable in a Database ?
Thanks a lot
解决方案
推荐阅读
- webforms - 在 Web 表单附件 URL 中添加令牌值
- javascript - 对字符串进行计数的另一种方法出现在数组中
- javascript - Javascript:在“onkeyup”事件中仅屏蔽信用卡号的前 12 位数字
- ubuntu-18.04 - 口径未在 ubuntu 18.04.03 LTS 下启动
- php - 如何在代码嗅探器中查找和更改规则集?
- c# - 无法理解 MVP Winforms C# 中的被动视图
- java - JPA Hibernate 映射视图 - 查询随机抛出错误
- javascript - 使引导警报出现并可堆叠
- java - 无效的初始堆大小
- javascript - 需要隐藏url中的变量值