value error:if' bert'选择模型,然后是Preprocess_mode =' bert'应该使用,反之亦然
我有问题。我收到以下错误valueerror:如果选择了'bert'模型,则应使用Preprocess_mode ='Bert',反之亦然
。但是我看不到任何问题。我的代码怎么了?
%%time
#Importing
import ktrain
from ktrain import text
(x_train_bert, y_train_bert), (x_val_bert, y_val_bert), preproc = text.texts_from_array(
x_train=train_X.tolist(), y_train=train_y.tolist(),
x_test=test_X.tolist(), y_test=test_y.tolist(),
class_names=df_complete['forwarder_name'].unique(),
preprocess_mode='bert',
lang='en',
maxlen=65,
max_features=35000)
model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
learner = ktrain.get_learner(model,train_data=(train_X, train_y), val_data=(test_X, test_y), batch_size=6)
完全错误
model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
#learner = ktrain.get_learner(model,train_data=(train_X, train_y), val_data=(test_X, test_y), batch_size=6)
model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
#learner = ktrain.get_learner(model,train_data=(train_X, train_y), val_data=(test_X, test_y), batch_size=6)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [111], in <cell line: 1>()
----> 1 model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
File ~\AppData\Roaming\Python\Python39\site-packages\ktrain\text\models.py:589, in text_classifier(name, train_data, preproc, multilabel, metrics, verbose)
585 if preproc is not None and not preproc.get_classes():
586 raise ValueError(
587 "preproc.get_classes() is empty, but required for text classification"
588 )
--> 589 return _text_model(
590 name,
591 train_data,
592 preproc=preproc,
593 multilabel=multilabel,
594 classification=True,
595 metrics=metrics,
596 verbose=verbose,
597 )
File ~\AppData\Roaming\Python\Python39\site-packages\ktrain\text\models.py:109, in _text_model(name, train_data, preproc, multilabel, classification, metrics, verbose)
107 is_bert = U.bert_data_tuple(train_data)
108 if (is_bert and name != BERT) or (not is_bert and name == BERT):
--> 109 raise ValueError(
110 "if '%s' is selected model, then preprocess_mode='%s' should be used and vice versa"
111 % (BERT, BERT)
112 )
113 is_huggingface = U.is_huggingface(data=train_data)
114 if (is_huggingface and name not in HUGGINGFACE_MODELS) or (
115 not is_huggingface and name in HUGGINGFACE_MODELS
116 ):
ValueError: if 'bert' is selected model, then preprocess_mode='bert' should be used and vice versa
I have a problem. I got the following error ValueError: if 'bert' is selected model, then preprocess_mode='bert' should be used and vice versa
. But I do not see any problem. What is wrong with my code?
%%time
#Importing
import ktrain
from ktrain import text
(x_train_bert, y_train_bert), (x_val_bert, y_val_bert), preproc = text.texts_from_array(
x_train=train_X.tolist(), y_train=train_y.tolist(),
x_test=test_X.tolist(), y_test=test_y.tolist(),
class_names=df_complete['forwarder_name'].unique(),
preprocess_mode='bert',
lang='en',
maxlen=65,
max_features=35000)
model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
learner = ktrain.get_learner(model,train_data=(train_X, train_y), val_data=(test_X, test_y), batch_size=6)
Complete error
model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
#learner = ktrain.get_learner(model,train_data=(train_X, train_y), val_data=(test_X, test_y), batch_size=6)
model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
#learner = ktrain.get_learner(model,train_data=(train_X, train_y), val_data=(test_X, test_y), batch_size=6)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [111], in <cell line: 1>()
----> 1 model = text.text_classifier(name='bert', train_data=(train_X, train_y), preproc=preproc)
File ~\AppData\Roaming\Python\Python39\site-packages\ktrain\text\models.py:589, in text_classifier(name, train_data, preproc, multilabel, metrics, verbose)
585 if preproc is not None and not preproc.get_classes():
586 raise ValueError(
587 "preproc.get_classes() is empty, but required for text classification"
588 )
--> 589 return _text_model(
590 name,
591 train_data,
592 preproc=preproc,
593 multilabel=multilabel,
594 classification=True,
595 metrics=metrics,
596 verbose=verbose,
597 )
File ~\AppData\Roaming\Python\Python39\site-packages\ktrain\text\models.py:109, in _text_model(name, train_data, preproc, multilabel, classification, metrics, verbose)
107 is_bert = U.bert_data_tuple(train_data)
108 if (is_bert and name != BERT) or (not is_bert and name == BERT):
--> 109 raise ValueError(
110 "if '%s' is selected model, then preprocess_mode='%s' should be used and vice versa"
111 % (BERT, BERT)
112 )
113 is_huggingface = U.is_huggingface(data=train_data)
114 if (is_huggingface and name not in HUGGINGFACE_MODELS) or (
115 not is_huggingface and name in HUGGINGFACE_MODELS
116 ):
ValueError: if 'bert' is selected model, then preprocess_mode='bert' should be used and vice versa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中有一个错字。问题是您使用
train_x
和train_y
(未为bert进行预处理),而不是x_train_bert
和y_train_bert
(用于伯特的处理)。而是使用此:
There's a typo in your code. The problem is that you're using
train_X
andtrain_y
(not preprocessed for BERT) instead ofx_train_bert
andy_train_bert
(which were processed for BERT).Use this instead: