gpt4 book ai didi

python - Keras 垂直集成模型,条件介于两者之间

转载 作者:行者123 更新时间:2023-12-03 09:35:22 25 4
gpt4 key购买 nike

我训练了两个独立的模型

  • ModelA:检查输入文本是否与我的工作相关(二元分类器 [相关/不相关])
  • ModelB:相关文本的分类器(Classifier [good/normal/bad])。仅将相关文本从 ModelA
  • 转发到此模型

    我想要
  • ModelC:输出 [good/normal/bad/not-related] 的集成分类器
  • 我会分批训练。并且可以混合使用 not-relatedgood/normal/bad一批。我需要他们分开。

  • 我需要的一些伪代码
    # Output of modelA will be a vector I presume `(1, None)` where `None` is batch
    def ModelC.predict(input):
    outputA = ModelA(input)
    if outputA == 'not-related':
    return outputA
    return ModelB(outputA)
    我不知道如何包含 if模型推理中的逻辑。我怎样才能做到这一点?

    最佳答案

    只需定义您自己的模型。我很惊讶你的其他模型输出的是字符串而不是数字,但没有更多信息,我只能给你,所以我假设模型 A 的输出是一个字符串。

    import tensorflow as tf

    class ModelC(tf.keras.Model):

    def __init__(self, A, B):
    super(ModelC, self).__init__()
    self.A = A
    self.B = B

    def call(self, inputs, training=False):
    x = self.A(inputs, training)
    if x == 'not-related':
    return x
    return self.B(inputs, training)

    关于python - Keras 垂直集成模型,条件介于两者之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64983112/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com