pytorch - 如何将 .txt 文件(语料库)读入 pytorch 中的 torchtext?

标签 pytorch torchtext

如何在pytorrch中读入.txt文件(语料库)到torchtext?

我只看到 data.Dataset 的示例数据集和 data.TabularData 的 csv、json 和 tsv。

https://github.com/pytorch/text#data

https://torchtext.readthedocs.io/en/latest/data.html#dataset

如果我使用像这样的表格数据集读取它,它仍然有效: test_file = data.TabularDataset(path=input_filepath, format='csv', fields=[('text', data.Field())])

但我的数据集不是表格,所以我想看看是否有更好的选择。

最佳答案

我建议编写一个快速脚本来读取您的语料库并将其转储到 JSON(有 plenty of examples out there ),然后将该 JSON 与 torchtext 一起使用。您将希望数据具有某种结构以充分利用 torchtext(想想批处理/可迭代数据集)。

如果您不知道如何遍历数据集,请查看 my other answer here .

关于pytorch - 如何将 .txt 文件(语料库)读入 pytorch 中的 torchtext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54340330/

相关文章:

python - Pytorch:当参数或大小发生变化时是否可以加载模型?

python - 在 Pytorch 中高级索引以摆脱嵌套的 for 循环

python - 测量 `UnboundLocalError`的时间时出现 `torch.where`错误

python - “Vocab”对象没有属性 'itos'

python - 如何保存 torchtext 数据集?

python - torch.empty 如何计算这些值?

python - 将 einsum 符号转换为 for 循环

python - 无法导入 torchtext.legacy.data

python - pytorch/torchtext 中的单热编码

jupyter-notebook - 使用pytorch时无法在jupyter笔记本中导入 'torchtext'模块