Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教训练过程中的一些结果 #9

Open
aagq opened this issue Apr 9, 2020 · 3 comments
Open

请教训练过程中的一些结果 #9

aagq opened this issue Apr 9, 2020 · 3 comments

Comments

@aagq
Copy link

aagq commented Apr 9, 2020

您好,如图所示,训练前几个Batch有metric-f1值,之后变nan,产生这样的结果正常吗?
WeChatd771b6c880a207e21cb5b7f4c49d8f52

@yumi-di
Copy link

yumi-di commented Apr 11, 2020

同问

@YanqiangWang
Copy link

from keras import backend as K
def metrics_f1(y_true, y_pred):
    def recall(y_true, y_pred):
        """Recall metric.
        Only computes a batch-wise average of recall.
        Computes the recall, a metric for multi-label classification of
        how many relevant items are selected.
        """
        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
        possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
        recall = true_positives / (possible_positives + K.epsilon())
        return recall
 
    def precision(y_true, y_pred):
        """Precision metric.
        Only computes a batch-wise average of precision.
        Computes the precision, a metric for multi-label classification of
        how many selected items are relevant.
        """
        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
        predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
        precision = true_positives / (predicted_positives + K.epsilon())
        return precision
    precision = precision(y_true, y_pred)
    recall = recall(y_true, y_pred)
    return 2*((precision*recall)/(precision+recall+K.epsilon()))

使用这个代码计算f1值,把原代码中的metrics_f1方法替换掉,就不会出现nan的问题了

@Kevin9780
Copy link

请问一下您是如何获取data/entity_id.pkl、data/id_entity.pkl等文件的呢,我跑代码跑不了显示缺文件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants