赞
踩
Huggingface 里面的模型封装的很好,想要直接修改代码并非容易的事,但是如果看文档,它有很多参数,能把你想到的大部分结果取出来,下面我就以一次经历来讲讲我如何在 T5 模型上面加一个 feature fusion 层。
我使用的是生成自然语言的 T5, 想在encoder 输出加一个 fusion layer。首先查看文档,并把 源代码 复制下来查看,发现可以直接用 T5.encoder 对 input_ids 进行编码,然后把 encoder_outputs 直接输入 T5ForConditionalGeneration,就可以了。
预测时 T5 模型记成了 model.generate,这个是所有继承 PreTrainedModel 的 生成式model 都有的一个 function,可以方便的进行 greedy search, beam search。查看文档,可以直接把模型的输入参数输入 generate 函数里面。
model*kwargs — Additional model specific kwargs will be forwarded to the
forward
function of the model. If the model is an encoder-decoder model, encoder specific kwargs should not be prefixed and decoder specific kwargs should be prefixed with *decoder**.
class T5MultiCode(nn.Module):
def __init__(self
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。