torchtext.data.Field

torchtext.data.Field

类接口

class torchtext.data.Field(sequential=True, use_vocab=True, init_token=None, eos_token=None, fix_length=None, dtype=torch.int64, preprocessing=None, postprocessing=None, lower=False, tokenize=None, tokenizer_language='en', include_lengths=False, batch_first=False, pad_token='<pad>', unk_token='<unk>', pad_first=False, truncate_first=False, stop_words=None, is_target=False)

功能

Defines a datatype together with instructions for converting to Tensor.
定义数据类型以及转换为张量的指令

Field class models common text processing datatypes that can be represented by tensors. It holds a Vocab object that defines the set of possible values for elements of the field and their corresponding numerical representations. The Field object also holds other parameters relating to how a datatype should be numericalized, such as a tokenization method and the kind of Tensor that should be produced.
字段类对可用张量表示的通用文本处理数据类型进行建模。它保存一个Vocab对象,该对象定义字段元素的可能值集及其相应的数值表示。Field对象还包含与数据类型应如何数值化有关的其他参数,例如标记化方法和应生成的张量类型。

If a Field is shared between two columns in a dataset (e.g., question and answer in a QA dataset), then they will have a shared vocabulary.
如果一个字段在数据集中的两列之间共享(例如,QA数据集中的问题和答案),那么它们将有一个共享词汇表

参数

  • sequential – Whether the datatype represents sequential data. If False, no tokenization is applied. Default: True.
  • use_vocab – Whether to use a Vocab object. If False, the data in this field should already be numerical. Default: True.
  • init_token – A token that will be prepended to every example using this field, or None for no initial token. Default: None.
  • eos_token – A token that will be appended to every example using this field, or None for no end-of-sentence token. Default: None.
  • fix_length – A fixed length that all examples using this field will be padded to, or None for flexible sequence lengths. Default: None.
  • dtype – The torch.dtype class that represents a batch of examples of this kind of data. Default: torch.long.
  • preprocessing – The Pipeline that will be applied to examples using this field after tokenizing but before numericalizing. Many Datasets replace this attribute with a custom preprocessor. Default: None.
  • postprocessing – A Pipeline that will be applied to examples using this field after numericalizing but before the numbers are turned into a Tensor. The pipeline function takes the batch as a list, and the field’s Vocab. Default: None.
  • lower – Whether to lowercase the text in this field. Default: False.
  • tokenize – The function used to tokenize strings using this field into sequential examples. If “spacy”, the SpaCy tokenizer is used. If a non-serializable function is passed as an argument, the field will not be able to be serialized. Default: string.split.
  • tokenizer_language – The language of the tokenizer to be constructed. Various languages currently supported only in SpaCy.
  • include_lengths – Whether to return a tuple of a padded minibatch and a list containing the lengths of each examples, or just a padded minibatch. Default: False.
  • batch_first – Whether to produce tensors with the batch dimension first. Default: False.
  • pad_token – The string token used as padding. Default: “”.
  • unk_token – The string token used to represent OOV words. Default: “”.
  • pad_first – Do the padding of the sequence at the beginning. Default: False.
  • truncate_first – Do the truncating of the sequence at the beginning. Default: False
  • stop_words – Tokens to discard during the preprocessing step. Default: None
  • is_target – Whether this field is a target variable. Affects iteration over batches. Default: False

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/507936.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

np.triu

np.triu numpy.triu(m, k0) Upper triangle of an array. Return a copy of a matrix with the elements below the k-th diagonal zeroed. 返回一个矩阵的上三角矩阵&#xff0c;第k条对角线以下的元素归零 例如&#xff1a; import numpy as np np.triu(np.ones([4,4]), …

python读取json格式的超参数

python读取json格式的超参数 json文件&#xff1a; {"full_finetuning": true,"max_len": 180,"learning_rate": 3e-5,"weight_decay": 0.01,"clip_grad": 2,"batch_size": 30,"epoch_num": 20,"…

python缺少标准库_干货分享:Python如何自动导入缺失的库

很多同学在写Python项目时会遇到导入模块失败的情况&#xff1a;ImportError: No module named xxx或者ModuleNotFoundError: No module named xxx。导入模块失败通常分为两种&#xff1a;一种是导入自己写的模块(即以 .py 为后缀的文件)&#xff0c;另一种是导入三方库。接下来…

.val()数据乱码_【目标检测数据集】PASCAL VOC制作

【VOC20072012】数据集地址&#xff1a;https://pjreddie.com/projects/pascal-voc-dataset-mirror/PASCAL VOC为图像识别和分类提供了一整套标准化的优秀的数据集&#xff0c;用于构建和评估用于图像分类&#xff08;Classification&#xff09;&#xff0c;检测&#xff08;O…

pytorch-多GPU训练(单机多卡、多机多卡)

pytorch-多GPU训练&#xff08;单机多卡、多机多卡&#xff09; pytorch 单机多卡训练 首先是数据集的分布处理 需要用到的包&#xff1a; torch.utils.data.distributed.DistributedSampler torch.utils.data.DataLoader torch.utils.data.Dataset DistributedSampler这个…

机器人 铑元素_智能机器人 三十三

福里斯特茫然不知所措地从窃窃私语的黑暗中转过身来&#xff0c;沉重的失败感犹如巨怪压得他喘不过气来。他顺从地跛着脚走向笼内角落里的小浴室&#xff0c;冲着微笑着的木偶刚才经过的地方点点头&#xff0c;漫不经意地问道&#xff1a;“你们是如何抓住他们的&#xff1f;”…

character-level OCR之Character Region Awareness for Text Detection(CRAFT) 论文阅读

Character Region Awareness for Text Detection 论文阅读 论文地址(arXiv) &#xff0c;pytorch版本代码地址 最近在看一些OCR的问题&#xff0c;CRAFT是在场景OCR中效果比较好的模型&#xff0c;记录一下论文的阅读 已有的文本检测工作大致如下&#xff1a; 基于回归的文…

c# wpf 面试_【远程面试】九强通信 | 九洲电器集团全资子公司

成都IT内推圈成立于2016年,专注成都IT互联网领域的招聘与求职;覆盖精准IT人群10W,通过内推圈推荐且已入职人数超过5000,合作公司均系成都知名或靠谱公司.此公众号每天7:30AM准时推送当天职位详情,敬请关注并置顶&#xff01;岗位投递一、登陆内推圈官网: www.itneituiquan.com,…

ViT(Vision Transformer)学习

ViT(Vison Transformer)学习 Paper:An image is worth 1616 words: transformers for image recognition at scale. In ICLR, 2021. Transformer 在 NLP领域大放异彩&#xff0c;并且随着模型和数据集的不断增长&#xff0c;仍然没有表现出饱和的迹象。这使得使用更大规模的数…

mysql php宝塔 root_[转载]在安卓中安装宝塔面板运行PHP+MySQL

手机上的操作我用的手机是小米10pro&#xff0c;其他手机应该也能用相同的方法安装成功。安装Linux Deploy&#xff0c;然后给它root权限。点击左上角的菜单按钮。点击号&#xff0c;创建一个名为debian的配置文件。如果已经有了名为debian的配置文件&#xff0c;选择它即可。返…

cpri带宽不足的解决方法_u盘容量不足怎么办 u盘容量不足解决方法【介绍】

我们在使用u盘的时候总能碰到各种各样的问题&#xff0c;其中u盘容量不足问题也是神烦&#xff0c;很多时候打开并没有发现有文件存在&#xff0c;但是在你存文件的时候又被提示u盘容量不足无法操作&#xff0c;关于这个问题u启动通过整理和大家一起分享下解决办法。1、u盘里的…

(python numpy) np.array.shape 中 (3,)、(3,1)、(1,3)的区别

(python numpy) np.array.shape 中 (3,)、(3,1)、(1,3)的区别 被人问到这个问题&#xff0c;就记录一下吧 1. (3,) (3,)是[x,y,z][x,y,z][x,y,z]的形式&#xff0c;即为一维数组&#xff0c;访问数组元素用一个index for example: >>> array1 np.array([1,2,3]) …

复合的赋值运算符例题_Java学习:运算符的使用与注意事项

运算符的使用与注意事项四则运算当中的加号“”有常见的三种用法&#xff1a;对于数值来&#xff0c;那就是加法。对于字符char类型来说&#xff0c;在计算之前&#xff0c;char会被提升成为int&#xff0c;然后再计算。char类型字符&#xff0c;和int类型数字之间的对照关系比…

腾讯会议如何使用讲演者模式进行汇报(nian gao)

腾讯会议如何使用讲演者模式进行汇报&#xff08;nian gao&#xff09; 首先列出步骤&#xff0c;再一一演示&#xff1a; altf5 开启讲演者模式&#xff0c;调整讲演者模式的窗口为小窗alttab 切换回腾讯会议界面&#xff0c;屏幕共享power point窗口&#xff08;注意不是“…

bulk这个词的用法_15、形容词与副词(二)比较的用法

初中英语语法——形容词与副词(二)比较的用法语法解释1、形容词与副词比较级和最高级的规则变化单音节词与部分双音节词&#xff1a;(1)一般情况加-er&#xff0c;-estlong-longer-longest strong-stronger-strongestclean-cleaner-cleanest(2)以不发音的e结尾的词&#xff0c;…

pytorch 使用DataParallel 单机多卡和单卡保存和加载模型时遇到的问题

首先很多网上的博客&#xff0c;讲的都不对&#xff0c;自己跟着他们踩了很多坑 1.单卡训练&#xff0c;单卡加载 这里我为了把三个模块save到同一个文件里&#xff0c;我选择对所有的模型先封装成一个checkpoint字典&#xff0c;然后保存到同一个文件里&#xff0c;这样就可…

retinex 的水下图像增强算法_图像增强论文:腾讯优图CVPR2019

Underexposed Photo Enhancement using Deep Illumination Estimation基于深度学习优化光照的暗光下的图像增强论文地址&#xff1a;Underexposed Photo Enhancement using Deep Illumination Estimation暗光拍照也清晰&#xff0c;这是手机厂商目前激烈竞争的新拍照目标。提出…

python 实现 BCH 纠错码的方法

python 实现 BCH 纠错码的方法 BCH码是一类重要的纠错码&#xff0c;它把信源待发的信息序列按固定的κ位一组划分成消息组&#xff0c;再将每一消息组独立变换成长为n(n>κ)的二进制数字组&#xff0c;称为码字。如果消息组的数目为M(显然M>2),由此所获得的M个码字的全…

结构体引用_C/C++结构体完全攻略

结构体是一个由程序员定义的数据类型&#xff0c;可以容纳许多不同的数据值。在过去&#xff0c;面向对象编程的应用尚未普及之前&#xff0c;程序员通常使用这些从逻辑上连接在一起的数据组合到一个单元中。一旦结构体类型被声明并且其数据成员被标识&#xff0c;即可创建该类…

python 实现 CRC 冗余码的方法

python 实现 CRC 冗余码的方法 我这里考虑输入是 torch.Tensor的一个 只包含0 &#xff0c;1 元素的张量对于输入是numpy或者0&#xff0c;1字符串的方法就更简单了&#xff0c;总之都先要将输入处理成为 0&#xff0c;1字符串&#xff0c;例如“1010”首先构造一个输入&#…