当前位置: 首页 > news >正文

高端网站制作哪家好广州17做网站

高端网站制作哪家好,广州17做网站,wordpress设置html代码高亮,百度认证怎么认证承接上文#xff1a;Transformer Encoder-Decoer 结构回顾 笔者以huggingface T5 transformer 对encoder-decoder 模型进行了简单的回顾。 由于笔者最近使用decoder-only模型时发现#xff0c;其使用细节和encoder-decoder有着非常大的区别#xff1b;而huggingface的接口为…承接上文Transformer Encoder-Decoer 结构回顾 笔者以huggingface T5 transformer 对encoder-decoder 模型进行了简单的回顾。 由于笔者最近使用decoder-only模型时发现其使用细节和encoder-decoder有着非常大的区别而huggingface的接口为了实现统一化很多接口的使用操作都是以encoder-decoder的用例为主如T5导致在使用hugging face运行decoder-only模型时如GPTLLaMA会遇到很多反直觉的问题。 本篇进一步涉及decoder-only的模型从技术细节上简单列举一些和encoder-decoder模型使用上的区别。 以下讨论均以huggingface transformer接口为例。 1. 训练时input与output合并 对于encoder-decoder模型我们需要把input和output 分别 喂给模型的encoder和decoder。也就是说像T5这种模型会有一个单独的encoder编码input的上下文信息由decoder解码output和计算loss。简而言之如果是encoder-decoder模型我们 只把 output喂给decoder用于计算lossteacher forcing这对于我们大多是人来说是符合直觉的。 但decoder-onyl模型需要你手动地将input和output合并在一起作为decoder的输入。因为从逻辑上讲对于decoder-only模型而言它们并没有额外的encoder去编码input的上下文所以需要把input作为“前文”让decoder基于这一段“前文”把“后文”的output预测出来auto regressive。因此在训练时input和output是合并在一起喂给decoder-only 模型的input这段前文必须要有。这对于大多数习惯了使用encoder-decoder的人来说是很违反直觉的。 于此相对应的decoder-only 模型计算loss时的“答案”ground truth reference也得是input和output的合并因为计算loss的时候输入token representation得和输出ground truth reference要对应。而这样一来decoder 的loss就既包含output又会涉及input上的预测error。由于我们大多数情况下不希望去惩罚decoder模型在input上的error一般的做法是训练时我们只计算output上的loss 即把input token对应的ground truth全部设置为-100cross entropy ignore idx。 2. 测试时手动提取output encoder-decoder模型的输出就是很“纯粹”的output模型的预测结果 但decoder-only模型在做inference的时候模型的输出就会既包含output也包含input因为input也喂给了decoder 所以这种情况下decoder-only 模型我们需要手动地把output给分离出来。 如下所示 笔者也很无语huggingface的 model.generate() 接口为什么不考虑一下对于decoder-only模型设置一个额外参数能够自动提取output用input token的数量就可以自动定位output不难实现的 3. batched inference的速度和准确度 如果想要批量地进行预测简单的做法就是把一个batch的样本进行tokenization之后在序列末尾右边pad token补足长度差异。这对于encoder-decoder 模型来说是适用的。 但是对于decoder-only模型你需要在训练时额外地将tokenizer的pad 位置设置为左边 因为你一旦设置为默认的右边模型在做inference时一个batch的样本所有pad token就都在序列末尾。而decoder only模型是auto regressive地生成新token的最右边的pad token就很容易影响到模型生成的内容。 有人就会问这个时候和encoder-decoder模型一样用attention mask把那些pad tokens都遮掉不就不会影响模型生成的内容了吗 但是很遗憾对于decoder-only模型huggingface model.generate 接口并不支持输入attention mask如下面官方api所描述 所以你如果想batched inference不得不在训练和测试的时候把tokenizer的pad设置在左手边以降低pad token对生成内容的影响或者干脆设置batch size为1 。 经过笔者自己的实验推理时batch size1能够显著提升推理准确度 以下为笔者测试的性能表现排序 batch size 为1 完全没有pad token的影响性能最好batch size不为1pad token在左侧pad token影响降低但还是会损伤推理性能在部分任务上性能降低较为明显batch size不为1pad token在右侧pad token对大量的样本的预测产生极大干扰模型最后的输出基本都是乱码性能接近于0 总之当前huggingface的生成接口对于decoder-only模型的支持度并不是非常高decoder-only模型推理的速度和精度以及接口使用的便捷程度都会逊于encoder-decoder模型。 下面是GPT-4对于为何decoder-only模型做推理时不需要attention mask最后一句话是亮点。。。 The instruction from the Hugging Face Transformers documentation regarding the use of input_ids for decoder-only models during generation (like GPT-2, GPT-3) stems from the typical use case and architecture of these models. Why input_ids? Decoder-only models like GPT-2 or GPT-3 are designed to generate text sequentially. When generating text, the model uses its previously generated tokens as context to generate the next token. Since these models are autoregressive, they generate one token at a time, and the sequence of generated tokens grows until it reaches a stopping condition (like the max_length or eos_token_id). During this process, the only necessity is to know which tokens have been generated (encoded as input_ids), so the model knows the context based on which it should generate the subsequent token(s). About attention_mask While it’s true that attention masks are used to prevent the model from attending to certain positions within the input sequence (for example, padding tokens in a batched input scenario), during the generation phase, the need to specify an attention_mask explicitly is not as critical as during training or evaluation. This is because, during generation, the model is focusing on the tokens it has already generated and the positions it needs to fill next – all of which are relevant and none should be masked out. That said, for certain generation scenarios or model configurations, you might want to control the attention mechanism explicitly. The Hugging Face Transformers library does allow for passing additional arguments like attention_mask in some contexts, but for the default use case of generating text with decoder-only models, including the attention_mask is not necessary. Batched Inference For batched inference, input_ids are necessary to understand the sequence (or sequences) from which to start generating text. If the sequences within a batch have different lengths, padding might be necessary to shape the input tensor appropriately. In such cases, an attention_mask becomes relevant because it allows the model to distinguish between the actual content and the padding. Therefore, while the generation call as you’ve shown doesn’t explicitly mention attention_mask, depending on the specifics of your use case and the model’s implementation, you might still need or want to provide it to ensure proper handling of batched inputs. 其他待补充 。。。 总结 总而言之个人认为 huggingface目前的模型接口对于decoder-only模型的使用并不是很友好。在使用过程中需要注意很多细节不然会遇到许多问题而这些问题encoder-decoder模型是完全不会有的。 参考 官方接口alpaca-lora
http://www.hkea.cn/news/14451127/

相关文章:

  • 万能网站网址下载qq是哪个公司创办的
  • 哪个网站可以改字体wordpress仿站上传到
  • 制作公司内部网站佛山seo优化排名
  • 广州网站建设360网站优化阳山县网站住房和建设局
  • 优秀企业网站模板爱网聊的男人是什么心理
  • wordpress站点标题wordpress 更换服务器
  • 能够做代理的网站有哪些问题vue做的手机网站
  • 建站程序的作用爱站网长尾关键词挖掘查询工具
  • dede网站如何换logo北京it公司排名
  • 温州网站域名注册服务公司怎样做网站的快捷方式
  • 淮安集团网站建设开发小程序软件的公司
  • 做网站一般不选用的图片格式wordpress adminimize
  • 58同城网招聘找工作下载安装关键词首页排名优化公司推荐
  • 建设旅游电子商务网站的目的做电影网站的成本
  • 做电脑网站手机能显示不出来上海做网站高端
  • 数字网站建设电子宣传册如何制作
  • 上海住房城乡建设厅网站首页地产设计网站
  • 安徽平台网站建设企业线上运营公司
  • 网络营销就是seo伊宁网站建设优化
  • 米枫网站怎么做分页网站你懂我意思正能量晚上
  • 陕西公司网站建设东丽区网站建设公司
  • iis7.5 网站配置做外贸无法登录国外网站怎么办
  • 企业营销型网站推广网站的文章参考文献怎么做
  • 毕业设计团购网站建设小型私人会所装修设计
  • 网站标题加后缀村网站建设计划书
  • 做网站要学的技术做网站公司的年终总结
  • 网站搭建平台都有哪些深圳关键词排名seo
  • 烟台建设集团 招聘信息网站canvas网站源码
  • 可信网站身份验证wordpress内容打不开
  • 百度网盘0基础网站开发教程工业互联网平台首先要提高数据的挖掘能力