Class: Aws::Lex::Conversation::Type::IntentConfidence

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/aws/lex/conversation/type/intent_confidence.rb

Instance Method Summary collapse

Methods included from Base

included

Instance Method Details

#ambiguous?(threshold: standard_deviation) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/aws/lex/conversation/type/intent_confidence.rb', line 12

def ambiguous?(threshold: standard_deviation)
  candidates(threshold: threshold).size > 1
end

#candidates(threshold: standard_deviation) ⇒ Object

NOTE: by default this method looks for candidates with a confidence score within one standard deviation of the current intent. Confidence scores may not be normally distributed, so it’s very possible that this method will return abnormal results for skewed sample sets.

If you want a consistent threshold for the condition, pass a static ‘threshold` parameter.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aws/lex/conversation/type/intent_confidence.rb', line 28

def candidates(threshold: standard_deviation)
  intents = event.intents.select do |intent|
    diff = event.current_intent
      .nlu_confidence
      .to_f
      .-(intent.nlu_confidence.to_f)
      .abs

    diff <= threshold
  end

  # sort descending
  intents.sort do |a, b|
    b.nlu_confidence.to_f <=> a.nlu_confidence.to_f
  end
end

#meanObject



45
46
47
# File 'lib/aws/lex/conversation/type/intent_confidence.rb', line 45

def mean
  @mean ||= calculate_mean
end

#similar_alternates(threshold: standard_deviation) ⇒ Object



49
50
51
52
# File 'lib/aws/lex/conversation/type/intent_confidence.rb', line 49

def similar_alternates(threshold: standard_deviation)
  # remove the first element (current intent) from consideration
  candidates(threshold: threshold)[1..-1]
end

#standard_deviationObject



54
55
56
# File 'lib/aws/lex/conversation/type/intent_confidence.rb', line 54

def standard_deviation
  @standard_deviation ||= calculate_standard_deviation
end

#unambiguous?(threshold: standard_deviation) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/aws/lex/conversation/type/intent_confidence.rb', line 16

def unambiguous?(threshold: standard_deviation)
  !ambiguous?(threshold: threshold)
end