@@ -35,7 +35,6 @@ public class IntentClassifier
3535 private ClassifierSetting _settings ;
3636
3737 private string [ ] _labels ;
38-
3938 public string [ ] Labels => GetLabels ( ) ;
4039
4140 private int _numLabels
@@ -67,7 +66,7 @@ private void Build()
6766 }
6867
6968 var vector = _services . GetServices < ITextEmbedding > ( )
70- . FirstOrDefault ( x => x . GetType ( ) . FullName . EndsWith ( _knowledgeBaseSettings . TextEmbedding ) ) ;
69+ . FirstOrDefault ( x => x . GetType ( ) . FullName . EndsWith ( _knowledgeBaseSettings . TextEmbedding ) ) ;
7170
7271 var layers = new List < ILayer >
7372 {
@@ -89,20 +88,22 @@ private void Fit(NDArray x, NDArray y, TrainingParams trainingParams)
8988 {
9089 _model . compile ( optimizer : keras . optimizers . Adam ( trainingParams . LearningRate ) ,
9190 loss : keras . losses . SparseCategoricalCrossentropy ( ) ,
92- metrics : new [ ] { "accuracy" }
93- ) ;
91+ metrics : new [ ] { "accuracy" } ) ;
9492
95- CallbackParams callback_parameters = new CallbackParams
93+ var callback_parameters = new CallbackParams
9694 {
9795 Model = _model ,
9896 Epochs = trainingParams . Epochs ,
9997 Verbose = 1 ,
10098 Steps = 10
10199 } ;
102100
103- ICallback earlyStop = new EarlyStopping ( callback_parameters , "accuracy" ) ;
101+ var earlyStop = new EarlyStopping ( callback_parameters , "accuracy" ) ;
104102
105- var callbacks = new List < ICallback > ( ) { earlyStop } ;
103+ var callbacks = new List < ICallback > ( )
104+ {
105+ earlyStop
106+ } ;
106107
107108 var weights = LoadWeights ( trainingParams . Inference ) ;
108109
@@ -120,7 +121,9 @@ private void Fit(NDArray x, NDArray y, TrainingParams trainingParams)
120121
121122 public string LoadWeights ( bool inference = true )
122123 {
123- var agentService = _services . CreateScope ( ) . ServiceProvider . GetRequiredService < IAgentService > ( ) ;
124+ var agentService = _services . CreateScope ( )
125+ . ServiceProvider
126+ . GetRequiredService < IAgentService > ( ) ;
124127
125128 var weightsFile = Path . Combine ( agentService . GetDataDir ( ) , _settings . MODEL_DIR , $ "intent-classifier.h5") ;
126129
@@ -129,13 +132,13 @@ public string LoadWeights(bool inference = true)
129132 _model . load_weights ( weightsFile ) ;
130133 _isModelReady = true ;
131134 Console . WriteLine ( $ "Successfully load the weights!") ;
132-
133135 }
134136 else
135137 {
136138 var logInfo = inference ? "No available weights." : "Will implement model training process and write trained weights into local" ;
137139 Console . WriteLine ( logInfo ) ;
138140 }
141+
139142 return weightsFile ;
140143 }
141144
@@ -161,10 +164,9 @@ public NDArray GetTextEmbedding(string text)
161164 throw new Exception ( $ "No training data found! Please put training data in this path: { rootDirectory } ") ;
162165 }
163166
167+ // Do embedding and store results
164168 var vector = _services . GetRequiredService < ITextEmbedding > ( ) ;
165-
166169 var vectorList = new List < float [ ] > ( ) ;
167-
168170 var labelList = new List < string > ( ) ;
169171
170172 foreach ( var filePath in GetFiles ( ) )
@@ -195,7 +197,11 @@ public string[] GetFiles(string prefix = "intent")
195197 {
196198 var agentService = _services . CreateScope ( ) . ServiceProvider . GetRequiredService < IAgentService > ( ) ;
197199 string rootDirectory = Path . Combine ( agentService . GetDataDir ( ) , _settings . RAW_DATA_DIR ) ;
198- return Directory . GetFiles ( rootDirectory ) . Where ( x => Path . GetFileNameWithoutExtension ( x ) . StartsWith ( prefix ) ) . OrderBy ( x => x ) . ToArray ( ) ;
200+ return Directory . GetFiles ( rootDirectory )
201+ . Where ( x => Path . GetFileNameWithoutExtension ( x )
202+ . StartsWith ( prefix ) )
203+ . OrderBy ( x => x )
204+ . ToArray ( ) ;
199205 }
200206
201207 public string [ ] GetLabels ( )
0 commit comments