简体   繁体   中英

AttributeError: 'list' object has no attribute 'split' - Chatterbot

I have been encountering this error within my chatterbot script when attempting to use the train function from a file list:

    Traceback (most recent call last):
  File "C:\Users\user\PycharmProjects\pythonProject\project\main.py", line 60, in <module>
    trainer.train(file_list)
  File "C:\Users\user\pythonProject\lib\site-packages\chatterbot\trainers.py", line 136, in train
    data_file_paths.extend(list_corpus_files(corpus_path))
  File "C:\Users\user\pythonProject\lib\site-packages\chatterbot\corpus.py", line 46, in list_corpus_files
    corpus_path = get_file_path(dotted_path, extension=CORPUS_EXTENSION)
  File "C:\Users\user\pythonProject\lib\site-packages\chatterbot\corpus.py", line 20, in get_file_path
    parts = dotted_path.split('.')
AttributeError: 'list' object has no attribute 'split'

Here is the code for reference:

import os
import re
import yaml
import transformers
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from Cognify.cleaner import clean_corpus

I am using.yml files found in the chatterbot git as a reference piece in order to ensure it functions, but I cannot seem to get it to read the files. The trainer I am using is based off of the ChatterBotCorpusTrainer, as I have read that it is meant for reading.yml files. Additionally, it calls on the cleaner script, which is an external script that cleans and preprocesses data from the user so the bot can process the data after (although, I am not sure it is necessary).

Here is where I actually call the trainer:

chatbot = ChatBot("Cognify")
trainer = ChatterBotCorpusTrainer(chatbot)

file_list = [
    "C:/Users/user/PycharmProjects/pythonProject/directory/ai.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/botprofile.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/computers.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/conversations.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/emotion.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/food.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/gossip.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/greetings.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/health.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/history.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/humor.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/literature.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/money.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/movies.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/politics.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/psychology.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/science.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/sports.yml",
    "C:/Users/user/PycharmProjects/pythonProject/directory/trivia.yml"
]

cleaned_corpus = clean_corpus(file_list)
trainer.train(file_list)

I am not certain where or why it is giving me this error. I cannot seem to pinpoint it, however I sense it is in plain sight. Additionally, I am using the hugging-face BERT transformer. Any advice is welcome.

ChatterBotCorpusTrainer.train 's signature doesn't accept a list, it takes *args . Relevant documentation example , and the source code of the signature .

Replace trainer.train(file_list) with trainer.train(*file_list) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM