【问题标题】:Is it possible to load a trained Rasa NLU model and run inference to get embeddings是否可以加载经过训练的 Rasa NLU 模型并运行推理以获取嵌入
【发布时间】:2026-01-03 05:05:02
【问题描述】:

我已经使用rasa train nlu 训练了一个supervised_embeddings Rasa NLU 模型。对于我的特定用例,我现在需要获取输入用户消息的嵌入,并将嵌入与我的 NLU 训练数据中的消息进行比较。

是否可以使用 Python API 加载训练好的模型,并使用它来获取文本字符串的嵌入?

【问题讨论】:

    标签: python tensorflow rasa-nlu rasa


    【解决方案1】:

    这是在rasa forum 上回答的。为了便于参考 - 将 only_output_properties=False 传递给 interpreter.parse 方法:

    您可以在 python 脚本中执行此操作:

    from rasa.nlu.model import Interpreter
    
    interpreter = Interpreter.load('models/nlu-xyz/nlu')) ## this should be an extracted model
    result = interpreter.parse('hello world',only_output_properties=False)
    embeds = result.get("text_sparse_features")
    

    【讨论】:

      【解决方案2】:

      @KOB 不幸的是,我们没有它的 API。您可以查看https://github.com/RasaHQ/rasa/blob/master/rasa/nlu/classifiers/embedding_intent_classifier.py#L572 的代码并使用message_embed 作为嵌入。 如有任何其他问题,请随时提出。

      【讨论】:

        最近更新 更多