如何从 GPTNeo 中生成的文本中删除输入?

发布于 2025-01-10 17:06:38 字数 323 浏览 1 评论 0 原文

我正在编写一个程序来生成文本...... 我需要从生成的文本中删除输入。我该怎么做? 代码:

input_ids = tokenizer(context, return_tensors="pt").input_ids
gen_tokens = model.generate(
    input_ids,
    do_sample=True,
    temperature=0.8,
    top_p=0.9)
strs = tokenizer.batch_decode(gen_tokens)[0]

这里的 strs 包含我给出的输入...... 如何删除它?

I'm writing a program to generate text...
I need to remove the input from the generated text. How can I do this?
The code:

input_ids = tokenizer(context, return_tensors="pt").input_ids
gen_tokens = model.generate(
    input_ids,
    do_sample=True,
    temperature=0.8,
    top_p=0.9)
strs = tokenizer.batch_decode(gen_tokens)[0]

Here the strs contains the input I've given...
How to remove that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2025-01-17 17:06:38

Transformers 库没有为您提供执行此操作的方法,但您可以通过一行代码轻松实现:

strs = strs.replace(context,"")

这实际上是我在 NLP Cloud API,因为它在后台使用 Transformer。

The Transformers library does not provide you with a way to do it, but this is something you can easily achieve with 1 line of code:

strs = strs.replace(context,"")

This is actually what I'm doing behind my NLP Cloud API as it uses Transformers behind the hood.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文