Skip to content

Add confidence threshold #122

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

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ public string[] GetFiles()

public string[] GetLabels()
{
return GetFiles().Select(x => Path.GetFileNameWithoutExtension(x)).ToArray();
var agentService = _services.CreateScope().ServiceProvider.GetRequiredService<IAgentService>();
string rootDirectory = Path.Combine(agentService.GetDataDir(), _settings.RAW_DATA_DIR, _settings.LABEL_FILE_NAME);
var labelText = File.ReadAllLines(rootDirectory);
return labelText.OrderBy(x => x).ToArray();
}

public string TextClean(string text)
Expand All @@ -210,19 +213,23 @@ public string TextClean(string text)
return processedText;
}

public string Predict(NDArray vector)
public string Predict(NDArray vector, float confidenceScore = 0.9f)
{
if (!_isModelReady)
{
InitClassifer();
}

var prob = _model.predict(vector);
var prob = _model.predict(vector).numpy();

if (prob[0] < confidenceScore)
{
return string.Empty;
}

var probLabel = tf.arg_max(prob, -1).numpy();
// var prediction = _settings.LabelMappingDict.First(x => x.Value == probLabel[0]).Key;

var prediction = GetLabels()[probLabel[0]];
// var prediction = GetLabels().Where((x, i) => i == probLabel[0]).First();

return prediction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class ClassifierSetting

public string RAW_DATA_DIR { get; set; } = "raw_data";
public string MODEL_DIR { get; set; } = "models";
public string LABEL_FILE_NAME { get; set; } = "label.txt";
}
Binary file added src/WebStarter/data/models/intent-classifier.h5
Binary file not shown.
3 changes: 3 additions & 0 deletions src/WebStarter/data/raw_data/label.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
goodbye
greeting
other