@@ -22,7 +22,6 @@ const RESULT_COLS: &[&str] = &[
2222 "State_of_the_code" ,
2323 "Time_to_train" ,
2424 "Self_Test_Score_L2" ,
25- "Self_Test_Score_L3" ,
2625 "QA_Test_Score" ,
2726 "JSON_Test_Score" ,
2827 "Date" ,
@@ -44,7 +43,6 @@ const EPOCH_COLS: &[&str] = &[
4443 "State_of_the_code" ,
4544 "Time_to_train" ,
4645 "Self_Test_Score_L2" ,
47- "Self_Test_Score_L3" ,
4846 "QA_Test_Score" ,
4947 "JSON_Test_Score" ,
5048 "Date" ,
@@ -97,8 +95,8 @@ pub fn print_results() -> Result<(), Box<dyn std::error::Error>> {
9795}
9896
9997pub fn self_test ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
100- let ( l2 , l3 ) = self_test_scores ( ) ?;
101- println ! ( "Self test scores : L2={}, L3={} " , l2, l3 ) ;
98+ let l2 = self_test_scores ( ) ?;
99+ println ! ( "Self test score : L2={}" , l2) ;
102100 Ok ( ( ) )
103101}
104102
@@ -115,7 +113,7 @@ pub fn json_test() -> Result<(), Box<dyn std::error::Error>> {
115113}
116114
117115pub fn test_all ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
118- let ( score_l2, score_l3 ) = self_test_scores ( ) ?;
116+ let score_l2 = self_test_scores ( ) ?;
119117 let score_qa = qa_test_score ( ) ?;
120118 let score_json = json_test_score ( ) ?;
121119
@@ -132,7 +130,6 @@ pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
132130 let entry = serde_json:: json!( {
133131 "Model_ID" : model_id,
134132 "Self_Test_Score_L2" : score_l2,
135- "Self_Test_Score_L3" : score_l3,
136133 "QA_Test_Score" : score_qa,
137134 "JSON_Test_Score" : score_json,
138135 "Date" : date,
@@ -146,11 +143,8 @@ pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
146143 writeln ! ( file, "{}" , serde_json:: to_string( & entry) . unwrap( ) ) ?;
147144 }
148145
149- println ! ( "Self_Test_Score_L2\t Self_Test_Score_L3\t QA_Test_Score\t JSON_Test_Score\t Date" ) ;
150- println ! (
151- "{}\t {}\t {}\t {}\t {}" ,
152- score_l2, score_l3, score_qa, score_json, date
153- ) ;
146+ println ! ( "Self_Test_Score_L2\t QA_Test_Score\t JSON_Test_Score\t Date" ) ;
147+ println ! ( "{}\t {}\t {}\t {}" , score_l2, score_qa, score_json, date) ;
154148
155149 Ok ( ( ) )
156150}
@@ -159,11 +153,11 @@ pub fn test_all() -> Result<(), Box<dyn std::error::Error>> {
159153pub fn per_epoch_scores < M : PredictGreedy > (
160154 model : & M ,
161155 device : & candle_core:: Device ,
162- ) -> Result < ( f32 , f32 , f32 , f32 ) , Box < dyn std:: error:: Error > > {
163- let ( l2 , l3 ) = compute_self_test_scores ( model, device) ?;
156+ ) -> Result < ( f32 , f32 , f32 ) , Box < dyn std:: error:: Error > > {
157+ let l2 = compute_self_test_scores ( model, device) ?;
164158 let qa = compute_qa_test_score ( model, device) ?;
165159 let json = compute_json_test_score ( model, device) ?;
166- Ok ( ( l2, l3 , qa, json) )
160+ Ok ( ( l2, qa, json) )
167161}
168162
169163/// Print the header for per_epoch_stats.log (call once before training).
@@ -194,73 +188,54 @@ fn first_n_words_contain(output: &str, expected: &str, n: usize) -> bool {
194188fn compute_self_test_scores < M : PredictGreedy > (
195189 model : & M ,
196190 device : & candle_core:: Device ,
197- ) -> Result < ( f32 , f32 ) , Box < dyn std:: error:: Error > > {
198- let level_file_paths = vec ! [
199- "smoll-generated-corpus/level_2/corpus.txt" ,
200- "smoll-generated-corpus/level_3/corpus.txt" ,
201- ] ;
202-
203- let mut scores: Vec < f32 > = Vec :: new ( ) ;
204-
205- for level_file_path in level_file_paths. iter ( ) {
206- let mut file = fs:: File :: open ( level_file_path) ?;
207- let mut content: String = String :: new ( ) ;
208- file. read_to_string ( & mut content) ?;
209-
210- let mut match_count = 0 ;
211- let mut total = 0 ;
212-
213- for line in content. split ( "\n " ) . filter ( |l| !l. trim ( ) . is_empty ( ) ) . take ( 20 ) {
214- let words: Vec < & str > = line. split ( " " ) . take ( 6 ) . collect ( ) ;
215- let expected_completion = line. split ( " " ) . skip ( 6 ) ;
216- let original_input = words. join ( " " ) ;
217- let mut input = original_input. clone ( ) + " " ;
218-
219- let mut buf = String :: new ( ) ;
220- loop {
221- let pred = model. predict_next_token_greedy ( input. as_str ( ) , device) ?;
222- input = input + pred. as_str ( ) ;
223-
224- if buf. len ( ) > 50 || pred == "." {
225- buf. push_str ( pred. as_str ( ) ) ;
226- break ;
227- }
228-
229- if pred == STOP_TOKEN {
230- break ;
231- }
191+ ) -> Result < f32 , Box < dyn std:: error:: Error > > {
192+ let level_file_path = "smoll-generated-corpus/level_2/corpus.txt" ;
193+ let mut file = fs:: File :: open ( level_file_path) ?;
194+ let mut content: String = String :: new ( ) ;
195+ file. read_to_string ( & mut content) ?;
196+
197+ let mut match_count = 0 ;
198+ let mut total = 0 ;
199+
200+ for line in content. split ( "\n " ) . filter ( |l| !l. trim ( ) . is_empty ( ) ) . take ( 20 ) {
201+ let words: Vec < & str > = line. split ( " " ) . take ( 6 ) . collect ( ) ;
202+ let expected_completion = line. split ( " " ) . skip ( 6 ) ;
203+ let original_input = words. join ( " " ) ;
204+ let mut input = original_input. clone ( ) + " " ;
232205
206+ let mut buf = String :: new ( ) ;
207+ loop {
208+ let pred = model. predict_next_token_greedy ( input. as_str ( ) , device) ?;
209+ input = input + pred. as_str ( ) ;
210+
211+ if buf. len ( ) > 50 || pred == "." {
233212 buf. push_str ( pred. as_str ( ) ) ;
213+ break ;
234214 }
235215
236- let expected_completion: Vec < & str > = expected_completion. collect ( ) ;
237- let expected_completion = expected_completion. join ( " " ) . replace ( "<stop>" , "" ) ;
238-
239- if first_n_words_contain ( & buf, & expected_completion, 3 ) {
240- match_count += 1 ;
241- println ! (
242- "'{}' |> '{}' ~ '{}' - match" ,
243- original_input, buf, expected_completion
244- ) ;
245- } else {
246- println ! (
247- "'{}' |> '{}' ~ '{}' - no match" ,
248- original_input, buf, expected_completion
249- ) ;
216+ if pred == STOP_TOKEN {
217+ break ;
250218 }
251219
252- total += 1 ;
220+ buf. push_str ( pred. as_str ( ) ) ;
221+ }
222+
223+ let expected_completion: Vec < & str > = expected_completion. collect ( ) ;
224+ let expected_completion = expected_completion. join ( " " ) . replace ( "<stop>" , "" ) ;
225+
226+ if first_n_words_contain ( & buf, & expected_completion, 3 ) {
227+ match_count += 1 ;
228+ println ! ( "'{}' |> '{}' ~ '{}' - match" , original_input, buf, expected_completion) ;
229+ } else {
230+ println ! ( "'{}' |> '{}' ~ '{}' - no match" , original_input, buf, expected_completion) ;
253231 }
254232
255- let success_rate = match_count as f32 / total as f32 ;
256- println ! (
257- "corpus {} - matches - {}, total - {}, success rate - {}" ,
258- level_file_path, match_count, total, success_rate
259- ) ;
260- scores. push ( success_rate) ;
233+ total += 1 ;
261234 }
262235
263- Ok ( ( scores[ 0 ] , scores[ 1 ] ) )
236+ let success_rate = match_count as f32 / total as f32 ;
237+ println ! ( "corpus {} - matches - {}, total - {}, success rate - {}" , level_file_path, match_count, total, success_rate) ;
238+ Ok ( success_rate)
264239}
265240
266241fn compute_qa_test_score < M : PredictGreedy > (
@@ -322,7 +297,7 @@ fn compute_qa_test_score<M: PredictGreedy>(
322297 Ok ( success_rate)
323298}
324299
325- fn self_test_scores ( ) -> Result < ( f32 , f32 ) , Box < dyn std:: error:: Error > > {
300+ fn self_test_scores ( ) -> Result < f32 , Box < dyn std:: error:: Error > > {
326301 let device = get_device ( ) ?;
327302 println ! ( "Loading test model" ) ;
328303 let model = Model :: load_from_path ( "data/model" , & device) ?;
0 commit comments