@@ -23,63 +23,21 @@ fn main() {
2323 // Mock input - test conversational format
2424 let string = String :: from ( "User: How do mountains form?" ) ;
2525
26- // Extract all unique words from training data to create vocabulary
27- let mut vocab_set = std:: collections:: HashSet :: new ( ) ;
28-
29- // Add end of sequence token
30- vocab_set. insert ( "</s>" . to_string ( ) ) ;
31-
3226 let dataset = Dataset :: new (
3327 String :: from ( "data/pretraining_data.json" ) ,
3428 String :: from ( "data/chat_training_data.json" ) ,
3529 DatasetType :: JSON ,
3630 ) ; // Placeholder, not used in this example
3731
32+ // Extract all unique words from training data to create vocabulary
33+ let mut vocab_set = std:: collections:: HashSet :: new ( ) ;
34+
3835 // Process all training examples for vocabulary
3936 // First process pre-training data
40- for text in & dataset. pretraining_data {
41- for word in text. split_whitespace ( ) {
42- // Handle punctuation by splitting it from words
43- let mut current = String :: new ( ) ;
44- for c in word. chars ( ) {
45- if c. is_ascii_punctuation ( ) {
46- if !current. is_empty ( ) {
47- vocab_set. insert ( current. clone ( ) ) ;
48- current. clear ( ) ;
49- }
50- vocab_set. insert ( c. to_string ( ) ) ;
51- } else {
52- current. push ( c) ;
53- }
54- }
55- if !current. is_empty ( ) {
56- vocab_set. insert ( current) ;
57- }
58- }
59- }
37+ Vocab :: process_text_for_vocab ( & dataset. pretraining_data , & mut vocab_set) ;
6038
6139 // Then process chat training data
62- for row in & dataset. chat_training_data {
63- // Add words from outputs
64- for word in row. split_whitespace ( ) {
65- // Handle punctuation by splitting it from words
66- let mut current = String :: new ( ) ;
67- for c in word. chars ( ) {
68- if c. is_ascii_punctuation ( ) {
69- if !current. is_empty ( ) {
70- vocab_set. insert ( current. clone ( ) ) ; // Clone to avoid moving
71- current. clear ( ) ; // Use clear() instead of String::new()
72- }
73- vocab_set. insert ( c. to_string ( ) ) ;
74- } else {
75- current. push ( c) ;
76- }
77- }
78- if !current. is_empty ( ) {
79- vocab_set. insert ( current) ;
80- }
81- }
82- }
40+ Vocab :: process_text_for_vocab ( & dataset. chat_training_data , & mut vocab_set) ;
8341
8442 let mut vocab_words: Vec < String > = vocab_set. into_iter ( ) . collect ( ) ;
8543 vocab_words. sort ( ) ; // Sort for deterministic ordering
0 commit comments