【问题标题】:Huggingface load_dataset() method how to assign the "features" argument?Huggingface load_dataset() 方法如何分配“特征”参数?
【发布时间】:2021-12-30 22:59:54
【问题描述】:

我正在尝试加载自定义数据集以用于微调 Huggingface 模型。我的数据是一个包含 2 列的 csv 文件:一个是“序列”,它是一个字符串,另一个是“标签”,它也是一个字符串,有 8 个类。我想加载我的数据集并将“序列”列的类型分配给“字符串”,将“标签”列的类型分配给“ClassLabel”

我的代码是这样的:

from datasets import Features
from datasets import load_dataset


ft = Features({'sequence':'str','label':'ClassLabel'})

mydataset = load_dataset("csv", data_files="mydata.csv",features= ft)

运行此代码,我收到以下错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-59-45fedff522e8> in <module>()
      7 
      8 mydataset = load_dataset("csv", data_files="mydata.csv",
----> 9                             features= ft)
     10 

8 frames
/usr/local/lib/python3.7/dist-packages/datasets/features/features.py in get_nested_type(schema)
    794 
    795     # Other objects are callable which returns their data type (ClassLabel, Array2D, Translation, Arrow datatype creation methods)
--> 796     return schema()

TypeError: 'str' object is not callable

有人可以帮忙吗?

【问题讨论】:

    标签: huggingface-transformers


    【解决方案1】:

    您应该以类似于here 中的方式定义您的功能:

    from datasets import Features, Value, ClassLabel
    from datasets import load_dataset
    
    class_names = ['class_label_1', 'class_label_2']
    
    ft = Features({'sequence': Value('string'), 'label': ClassLabel(names=class_names)})
    
    mydataset = load_dataset("csv", data_files="mydata.csv",features=ft)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-07
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2023-01-28
      • 1970-01-01
      • 2022-12-11
      相关资源
      最近更新 更多