Есть ли лучший способ получить высшее намерение с соответствующим счетом от модели диспетчера LUIS - PullRequest
1 голос
/ 05 апреля 2020

У меня есть код для этого, и именно так я получаю свое высшее намерение от соответствующей модели luis, но мне было интересно, есть ли лучший способ сделать это, например, что-то, что существует в рамках непосредственно для диспетчера.

 public async getIntent(result) {
        logger.trace('getIntent result', result);
        if (result.luisResult.connectedServiceResult) {
            logger.trace('intent score', result.luisResult.connectedServiceResult.topScoringIntent.score)
            const topIntent = result.luisResult.connectedServiceResult.topScoringIntent.intent;
            const score = result.luisResult.connectedServiceResult.topScoringIntent.score;
            return await new TopIntent(topIntent, score);
        } else {
            return
        }
    }

1 Ответ

1 голос
/ 05 апреля 2020

это то, что я сделал, чтобы смягчить проблему. v3 очень отличается от v2 LUIS Api структура. Обручи, чтобы прыгать через кажется немного чрезмерным. Надеюсь, на следующей версии это будет адрес.

надеюсь, это поможет кому-то еще. Это для v3 LUIS API

/**
     * Returns the name of the top scoring intent from a particular luis model intent that will correspond
     * with the intent that triggered from the dispatcher
     * @param results Result set to be searched.
     * @param defaultIntent (Optional) intent name to return should a top intent be found. Defaults to a value of `None`.
     * @param minScore (Optional) minimum score needed for an intent to be considered as a top intent. If all intents in the set are below this threshold then the `defaultIntent` will be returned.  Defaults to a value of `0.0`.
     */
    public async modelTopIntent(result: RecognizerResult | undefined, defaultIntent: string = 'None',  minScore: number = 0 ): Promise<TopIntent> {
        let topIntent: string;
        let topScore: number = -1;
        if (result && result.luisResult) {
            const topIntentWithScore = await result.luisResult.prediction.intents[LuisRecognizer.topIntent(result)].childApp.topIntent;
            const topIntentsObject = await result.luisResult.prediction.intents[LuisRecognizer.topIntent(result)].childApp.intents;
            // obtain the top intents object to extract score
            const filteredIntent = topIntentWithScore;
            const filtered = Object.keys(topIntentsObject)
                .filter(key => filteredIntent.includes(key))
                .reduce((obj, key) => {
                    return {
                        ...obj,
                        [key]: topIntentsObject[key]
                    };
                }, {});
            // score from top intent
            const score: number = filtered[topIntentWithScore]['score'];

            if (typeof score === 'number' && score > topScore && score >= minScore) {
                topIntent = topIntentWithScore
                topScore = score;
            }
        } 

        return await new TopIntent(topIntent || defaultIntent, topScore)
    }

просто для сравнения это было v2

public async getIntent(result) {
        logger.trace('getIntent result', result);
        if (result.luisResult.connectedServiceResult) {
            logger.trace('intent score', result.luisResult.connectedServiceResult.topScoringIntent.score)
            const topIntent = result.luisResult.connectedServiceResult.topScoringIntent.intent;
            const score = result.luisResult.connectedServiceResult.topScoringIntent.score;
            return await new TopIntent(topIntent, score);
        } else {
            return
        }
    }
...