大佬教程收集整理的这篇文章主要介绍了如何使用其他指标(presicion、recall、F1)评估我的 NER 模型?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Keras 开发我的 NER 模型。我训练我的模型,但有必要根据其他指标来评估它,而不仅仅是训练错误。有一些我的代码 - TOKENS 和 Tags 填充。
#TraiN TOKENS NAD Tags
Train_tokens = Train_group['Word_IDx'].to_numpy()
maxlen = 1024#max([len(s) for s in Train_tokens])
Train_pad_tokens = pad_sequences(Train_tokens,maxlen=maxlen,padding='pre',value=0)
Train_Tags = Train_group['Tag_IDx'].to_numpy()
Train_pad_Tags = pad_sequences(Train_Tags,value=0)
Train_n_Tags = len(tag2IDX)
Train_pad_Tags = np.array([to_categorical(i,num_classes=Train_n_Tags) for i in Train_pad_Tags])
#TEST TOKENS NAD Tags
test_tokens = test_group['Word_IDx'].to_numpy()
test_pad_tokens = np.array(pad_sequences(test_tokens,value=0))
test_Tags = test_group['Tag_IDx'].to_numpy()
test_pad_Tags = pad_sequences(test_Tags,value=0)
test_n_Tags = len(tag2IDX)
test_pad_Tags = np.array([to_categorical(i,num_classes=test_n_Tags) for i in test_pad_Tags])
#VAL TOKENS NAD Tags
val_tokens = val_group['Word_IDx'].to_numpy()
val_pad_tokens = np.array(pad_sequences(val_tokens,value=0))
val_Tags = val_group['Tag_IDx'].to_numpy()
val_pad_Tags = pad_sequences(val_Tags,value=0)
val_n_Tags = len(tag2IDX)
val_pad_Tags = np.array([to_categorical(i,num_classes=val_n_Tags) for i in val_pad_Tags])
现在我需要使用其他指标评估我的模型:
@H_816_5@model = Sequential() # Add Embedding layer model.add(Embedding(input_dim=vstup_dim,output_dim=vystup_dim,input_length=vstup_dlzka )) # Add bIDirectional LSTM model.add(BIDirectional(LSTM(units=32,return_sequences=True,dropout=0.2,recurrent_dropout=0.2) `merge_mode = 'concat'))` # Add LSTM model.add(LSTM(units=32,dropout=0.5,recurrent_dropout=0.5)) # Add Dense layer model.add(layers.Dense(10,activation='relu')) # Add timediStributed Layer model.add(TimediStributed(Dense(Train_n_Tags,activation="softmax"))) #Optimiser adam = k.optimizers.Adam(lr=0.0005,beta_1=0.9,beta_2=0.999) # Compile model model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy']) model.sumMary() plot_model(model)
我看到了一些简单的东西 - 接近我的问题,但我需要将其调整到我的代码中:
def preDict(model):
y_probs = model.preDict(X_val)
y_pred = np.argmax(y_probs,axis=-1)
return [
[(token,tag,scheR_137_11845@a[index]) for (token,tag),index in zip(sentence,tag_pred)]
for sentence,tag_pred in zip(val_samples,y_pred)
]
preDictions = preDict(model)
import pandas as pd
from sklearn.metrics import classification_report
def evaluate(preDictions):
y_t = [pos[1] for sentence in preDictions for pos in sentence]
y_p = [pos[2] for sentence in preDictions for pos in sentence]
report = classification_report(y_t,y_p,output_Dict=TruE)
return pd.DataFrame.from_Dict(report).transpose().reset_index()
evaluate(preDictions)
https://blog.codecentric.de/en/2020/11/take-control-of-named-entity-recognition-with-you-own-keras-model/
感谢您的帮助。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的如何使用其他指标(presicion、recall、F1)评估我的 NER 模型?全部内容,希望文章能够帮你解决如何使用其他指标(presicion、recall、F1)评估我的 NER 模型?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。