m0_61104322 2022-01-07 20:46 采纳率: 90.3%
浏览 198
已结题

深度学习XLnet模型出现问题,如何解决

在运行XLnet进行文本分类的时候,出现了下面的问题,该如何解决,请大家赐教:

def tokenize(text):
    tokenized = tokenizer(text,
              padding=True,
              truncation=True,
              return_tensors='tf',
              return_token_type_ids=False,
              return_attention_mask=False,
              verbose=True)
    return tokenized

x_train_enc = tokenize(x_train)
x_test_enc = tokenize(x_test)

y_train_enc_one_hot = to_categorical(y_train_enc, num_classes=num_classes)
y_test_enc_one_hot = to_categorical(y_test_enc, num_classes=num_classes)


ValueError Traceback (most recent call last)
/tmp/ipykernel_10776/2763515379.py in
11 return tokenized
12
---> 13 x_train_enc = tokenize(x_train)
14 x_test_enc = tokenize(x_test)
15

/tmp/ipykernel_10776/2763515379.py in tokenize(text)
8 return_token_type_ids=False,
9 return_attention_mask=False,
---> 10 verbose=True)
11 return tokenized
12

/environment/miniconda3/lib/python3.7/site-packages/transformers/tokenization_utils_base.py in call(self, text, text_pair, add_special_tokens, padding, truncation, max_length, stride, is_split_into_words, pad_to_multiple_of, return_tensors, return_token_type_ids, return_attention_mask, return_overflowing_tokens, return_special_tokens_mask, return_offsets_mapping, return_length, verbose, **kwargs)
2391 if not _is_valid_text_input(text):
2392 raise ValueError(
-> 2393 "text input must of type str (single example), List[str] (batch or single pretokenized example) "
2394 "or List[List[str]] (batch of pretokenized examples)."
2395 )

ValueError: text input must of type str (single example), List[str] (batch or single pretokenized example) or List[List[str]] (batch of pretokenized examples).

  • 写回答

1条回答 默认 最新

  • CSDN专家-HGJ 2022-01-08 13:49
    关注

    参数text应该是一个字符串类型或字符串列表形式。检查一下传入的参数text。
    试试改一下:
    for i, text in enumerate(df['abstract2'].tolist())

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 1月16日
  • 已采纳回答 1月8日
  • 创建了问题 1月7日

悬赏问题

  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥15 有一台三相异步电动机 M1控制一个小车,有四个控制按钮,一个复位、一个启动、一个停止,还有一个急停,两个行程开关分别为上限位和下限位。 上限位。 下限位。
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?