You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用TextAttack生成对抗样本时遇数据集导入ValueError问题求助

问题:TextAttack导入自定义CSV数据集失败

我用TextAttack基于预训练模型和自有CSV数据集生成对抗样本,执行命令:

textattack attack --model-from-file model --dataset-from-file data/data.csv --attack-recipe bert-attack --log-to-txt data/output.txt

但触发错误:

raise ValueError(f"Failed to import file {args.dataset_from_file}")
ValueError: Failed to import file data/data.csv

已经排查过路径问题(改用绝对路径仍报错),模型文件包含模型和tokenizer无异常,CSV内容如下:

text
"my wife and i stayed at the affinia chicago last week in a studio suite which was not worth the extra payment it was an absolute nightmare to begin with the room is listed as 'oversized' when it's nothing of the sort we've previously stayed in the hotel and the regular guest room is only about 2 square feet smaller i believe the only extra space was in the closet which isn't very useful unless you plan on living there we had our two sons with us so we had to make extra sleeping space our oldest son slept on the couch and woke up multiple times in the time complaining of bugs moving around he must have been umcomfortable also as i sat on the couch during the day and it was like a rock the room service is horrible they took 47 minutes to deliver a pillow for my wife around 10pm and she had to wait up for that my family would never go back to this hotel and i highly recommend you also stay well away
"
"affinia chicago is one of the worst hotels i have ever stayed at not in my life have i been treated so poorly as a guest the front desk was very unaccommodating when i asked for a smoke free room when they had made an error in my reservation there was no bellhop available for some strange reason so i had to move all my luggage to the elevator and down a long hallway to my room by myself if it wasn't already a bad stay i ordered room service and it took over an hour and a half to be delivered if they didn't have air conditioning in the room i would say just about everything about this stay was completely miserable if you are traveling to chicago for any kind of business i hope you decide not to choose this hotel i was quite surprised i like chicago as a city but this stay definitely made my trip quite a negative experience

解决方法

  • 补全CSV必要列:TextAttack的自定义分类数据集CSV必须包含text和label两列,你的CSV只有text列,缺少标签列会导致导入失败——对抗样本生成需要明确的样本标签(比如情感分类的negative/positive或0/1)。给每一行文本添加对应标签即可,示例:
text,label
"my wife and i stayed at the affinia chicago last week...",negative
"affinia chicago is one of the worst hotels i have ever stayed at...",negative
  • 修复CSV语法错误:你提供的第二个文本末尾缺少闭合引号,这会导致CSV解析失败,要确保所有文本的引号都正确闭合。
  • 检查文件权限:确认当前用户对目标CSV文件有读取权限,避免因权限问题导致无法导入。

内容的提问来源于stack exchange,提问作者Lillian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 16:01:13