默认的 SimpleTransformers 安装失败并显示 ValueError str
Default SimpleTransformers setup fails with ValueError str
我正在尝试使用 SimpleTransformers 默认设置来进行多任务学习。
我正在使用他们网站上的示例 here
代码如下所示:
import logging
import pandas as pd
from simpletransformers.t5 import T5Model, T5Args
logging.basicConfig(level=logging.INFO)
transformers_logger = logging.getLogger("transformers")
transformers_logger.setLevel(logging.WARNING)
train_data = [
["binary classification", "Anakin was Luke's father" , 1],
["binary classification", "Luke was a Sith Lord" , 0],
["generate question", "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon", "Who created the Star Wars franchise?"],
["generate question", "Anakin was Luke's father" , "Who was Luke's father?"],
]
train_df = pd.DataFrame(train_data)
train_df.columns = ["prefix", "input_text", "target_text"]
eval_data = [
["binary classification", "Leia was Luke's sister" , 1],
["binary classification", "Han was a Sith Lord" , 0],
["generate question", "In 2020, the Star Wars franchise's total value was estimated at US billion, and it is currently the fifth-highest-grossing media franchise of all time.", "What is the total value of the Star Wars franchise?"],
["generate question", "Leia was Luke's sister" , "Who was Luke's sister?"],
]
eval_df = pd.DataFrame(eval_data)
eval_df.columns = ["prefix", "input_text", "target_text"]
model_args = T5Args()
model_args.num_train_epochs = 200
model_args.no_save = True
model_args.evaluate_generated_text = False
model_args.evaluate_during_training = False
model_args.evaluate_during_training_verbose = False
model_args.use_multiprocessing = False
model_args.use_multiprocessing_for_evaluation = False
model = T5Model("t5", "t5-base", args=model_args)
def count_matches(labels, preds):
print(labels)
print(preds)
return sum([1 if label == pred else 0 for label, pred in zip(labels, preds)])
model.train_model(train_df, show_running_loss=True)
目前我什至没有使用 eval_df
(尽管我计划在我的真实代码中使用它),因为它在他们的代码中没有正确设置。在这个超级简单的设置中,我认为该库可以正常工作。然而,在尝试了两个系统(一个 Windows、一个 Linux、两个最新版本的 SimpleTransformers 之后,我收到以下错误:
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\simpletransformers\t5\t5_utils.py", line 175, in <listcomp>
preprocess_data(d) for d in tqdm(data, disable=args.silent)
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\simpletransformers\t5\t5_utils.py", line 81, in preprocess_data
batch = tokenizer.prepare_seq2seq_batch(
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\transformers\tokenization_utils_base.py", line 3282, in prepare_seq2seq_batch
labels = self(
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\transformers\tokenization_utils_base.py", line 2262, in __call__
raise ValueError(
ValueError: text input must of type `str` (single example), `List[str]` (batch or single pretokenized example) or `List[List[str]]` (batch of pretokenized examples).
我正在使用完全相同的设置,所有输入 DataFrames
中都有字符串。
谁能帮忙弄清楚这个基本设置失败的原因?谢谢。
在示例代码中,如果您更改
train_data = [
["binary classification", "Anakin was Luke's father" , 1],
["binary classification", "Luke was a Sith Lord" , 0],
["generate question", "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon", "Who created the Star Wars franchise?"],
["generate question", "Anakin was Luke's father" , "Who was Luke's father?"],
]
至
train_data = [
["binary classification", "Anakin was Luke's father" , '1'],
["binary classification", "Luke was a Sith Lord" , '0'],
["generate question", "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon", "Who created the Star Wars franchise?"],
["generate question", "Anakin was Luke's father" , "Who was Luke's father?"],
]
错误不再发生 - 所以这是由于标签类型不是 str
。
我正在尝试使用 SimpleTransformers 默认设置来进行多任务学习。
我正在使用他们网站上的示例 here
代码如下所示:
import logging
import pandas as pd
from simpletransformers.t5 import T5Model, T5Args
logging.basicConfig(level=logging.INFO)
transformers_logger = logging.getLogger("transformers")
transformers_logger.setLevel(logging.WARNING)
train_data = [
["binary classification", "Anakin was Luke's father" , 1],
["binary classification", "Luke was a Sith Lord" , 0],
["generate question", "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon", "Who created the Star Wars franchise?"],
["generate question", "Anakin was Luke's father" , "Who was Luke's father?"],
]
train_df = pd.DataFrame(train_data)
train_df.columns = ["prefix", "input_text", "target_text"]
eval_data = [
["binary classification", "Leia was Luke's sister" , 1],
["binary classification", "Han was a Sith Lord" , 0],
["generate question", "In 2020, the Star Wars franchise's total value was estimated at US billion, and it is currently the fifth-highest-grossing media franchise of all time.", "What is the total value of the Star Wars franchise?"],
["generate question", "Leia was Luke's sister" , "Who was Luke's sister?"],
]
eval_df = pd.DataFrame(eval_data)
eval_df.columns = ["prefix", "input_text", "target_text"]
model_args = T5Args()
model_args.num_train_epochs = 200
model_args.no_save = True
model_args.evaluate_generated_text = False
model_args.evaluate_during_training = False
model_args.evaluate_during_training_verbose = False
model_args.use_multiprocessing = False
model_args.use_multiprocessing_for_evaluation = False
model = T5Model("t5", "t5-base", args=model_args)
def count_matches(labels, preds):
print(labels)
print(preds)
return sum([1 if label == pred else 0 for label, pred in zip(labels, preds)])
model.train_model(train_df, show_running_loss=True)
目前我什至没有使用 eval_df
(尽管我计划在我的真实代码中使用它),因为它在他们的代码中没有正确设置。在这个超级简单的设置中,我认为该库可以正常工作。然而,在尝试了两个系统(一个 Windows、一个 Linux、两个最新版本的 SimpleTransformers 之后,我收到以下错误:
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\simpletransformers\t5\t5_utils.py", line 175, in <listcomp>
preprocess_data(d) for d in tqdm(data, disable=args.silent)
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\simpletransformers\t5\t5_utils.py", line 81, in preprocess_data
batch = tokenizer.prepare_seq2seq_batch(
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\transformers\tokenization_utils_base.py", line 3282, in prepare_seq2seq_batch
labels = self(
File "C:\Users\name\AppData\Local\Programs\Python\Python38\lib\site-packages\transformers\tokenization_utils_base.py", line 2262, in __call__
raise ValueError(
ValueError: text input must of type `str` (single example), `List[str]` (batch or single pretokenized example) or `List[List[str]]` (batch of pretokenized examples).
我正在使用完全相同的设置,所有输入 DataFrames
中都有字符串。
谁能帮忙弄清楚这个基本设置失败的原因?谢谢。
在示例代码中,如果您更改
train_data = [
["binary classification", "Anakin was Luke's father" , 1],
["binary classification", "Luke was a Sith Lord" , 0],
["generate question", "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon", "Who created the Star Wars franchise?"],
["generate question", "Anakin was Luke's father" , "Who was Luke's father?"],
]
至
train_data = [
["binary classification", "Anakin was Luke's father" , '1'],
["binary classification", "Luke was a Sith Lord" , '0'],
["generate question", "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon", "Who created the Star Wars franchise?"],
["generate question", "Anakin was Luke's father" , "Who was Luke's father?"],
]
错误不再发生 - 所以这是由于标签类型不是 str
。