我正在使用 SVM 进行文本情感分析,以便与其他方法进行比较 但由于样本量大, 以下程序让我等到内核崩溃
tfhub_handle_preprocess="https://tfhub.dev/tensorflow/bert_zh_preprocess/3"
bert_preprocess_model = hub.KerasLayer(tfhub_handle_preprocess)
def encoder(strlist):
return bert_preprocess_model(strlist)["input_word_ids"]
from sklearn.preprocessing import FunctionTransformer
SVM_Model = Pipeline([
('Encoder',FunctionTransformer(encoder)),
('Svm',SVC(kernel='linear'))
])
SVM_Model.fit(text,labels)
所以我试着把程序改成这样:
from IPython.display import clear_output
for times in range(0,len(text),20):
SVM_Model.fit(text[times:times+20],labels[times:times+20])
pre = SVM_Model.predict(pre_text[:100])
accuracy = accuracy_score(pre_labels[:100], pre)
clear_output(wait=True)
print(f'times:{times}, Accuracy:{accuracy}')
但是我不知道SVM能不能再这样训练, 否则它只会忽略之前的样本。