@@ -8,9 +8,9 @@ import { promises as fs } from 'fs';
88const { BayesClassifier } = natural ;
99
1010async function trainAndEvaluate ( ) {
11- console . log ( 'Iniciando o pipeline de treinamento ...' ) ;
11+ console . log ( 'Starting training pipeline...' ) ;
1212
13- // Lê o dataset centralizado em data/raw/ (relativo a este arquivo )
13+ // Read dataset centralized in data/raw/ (relative to this file )
1414 const datasetPath = new URL ( '../../data/raw/dataset.csv' , import . meta. url ) . pathname ;
1515 const datasetRaw = await fs . readFile ( datasetPath , 'utf-8' ) ;
1616 const dataset = datasetRaw . split ( '\n' ) . slice ( 1 ) . map ( line => {
@@ -22,22 +22,22 @@ async function trainAndEvaluate() {
2222 const classifier = new BayesClassifier ( ) ;
2323 dataset . forEach ( item => item && classifier . addDocument ( item . text , item . label ) ) ;
2424 classifier . train ( ) ;
25- console . log ( 'Modelo treinado .' ) ;
25+ console . log ( 'Model trained .' ) ;
2626
2727 let correct = 0 ;
2828 dataset . forEach ( item => {
2929 if ( item && classifier . classify ( item . text ) === item . label ) correct ++ ;
3030 } ) ;
3131 const accuracy = correct / dataset . length ;
32- const metrics = { f1Score : accuracy , accuracy : accuracy } ; // Simplificação
33- console . log ( `Acurácia do novo modelo : ${ metrics . accuracy } ` ) ;
32+ const metrics = { f1Score : accuracy , accuracy : accuracy } ; // Simplification
33+ console . log ( `New model accuracy : ${ metrics . accuracy } ` ) ;
3434
35- // Usa o mesmo banco do serviço de inferência (inference/main.db)
35+ // Use the same DB as the inference service (inference/main.db)
3636 const dbPath = new URL ( '../../inference/main.db' , import . meta. url ) . pathname ;
3737 const sqlite = new Database ( dbPath , { create : true } ) ;
3838 const db = drizzle ( sqlite , { schema } ) ;
3939
40- // Garante que exista um experimento padrão e obtem seu ID
40+ // Ensure a default experiment exists and get its ID
4141 let experimentId = 1 ;
4242 try {
4343 const existing = await db . query . experiments . findFirst ( {
@@ -53,14 +53,14 @@ async function trainAndEvaluate() {
5353 experimentId = existing . id ;
5454 }
5555 } catch ( e ) {
56- console . warn ( 'Não foi possível verificar/criar experimento padrão :' , e ?. message || e ) ;
56+ console . warn ( 'Could not verify/create default experiment :' , e ?. message || e ) ;
5757 }
5858
5959 const currentProdRun = await db . query . runs . findFirst ( {
6060 where : eq ( schema . runs . isProduction , true ) ,
6161 } ) ;
6262
63- // Lê métricas atuais do modelo em produção (podem estar como string JSON)
63+ // Read current production model metrics (may be stored as JSON string )
6464 let currentProdAccuracy = 0 ;
6565 if ( currentProdRun ?. metrics ) {
6666 try {
@@ -70,23 +70,23 @@ async function trainAndEvaluate() {
7070 currentProdAccuracy = 0 ;
7171 }
7272 }
73- console . log ( `Acurácia do modelo em produção : ${ currentProdAccuracy } ` ) ;
73+ console . log ( `Production model accuracy : ${ currentProdAccuracy } ` ) ;
7474
7575 if ( metrics . accuracy <= currentProdAccuracy ) {
76- console . log ( 'Novo modelo não superou o modelo em produção. Abortando .' ) ;
76+ console . log ( 'New model did not outperform the production model. Aborting .' ) ;
7777 return ;
7878 }
7979
80- console . log ( 'Novo modelo é superior! Promovendo para produção .' ) ;
80+ console . log ( 'New model is better! Promoting to production .' ) ;
8181 const runId = Date . now ( ) ;
82- // Salva o artefato centralizado em artifacts/ na raiz do repo
82+ // Save artifact centralized under artifacts/ at the repo root
8383 const modelArtifactPath = `artifacts/model_${ runId } .json` ;
8484
8585 const artifactDir = new URL ( '../../artifacts/' , import . meta. url ) . pathname ;
8686 await fs . mkdir ( artifactDir , { recursive : true } ) ;
8787 const classifierJson = JSON . stringify ( classifier ) ;
8888 await fs . writeFile ( `${ artifactDir } model_${ runId } .json` , classifierJson ) ;
89- console . log ( `Modelo salvo em : ${ modelArtifactPath } ` ) ;
89+ console . log ( `Model saved at : ${ modelArtifactPath } ` ) ;
9090
9191 if ( currentProdRun ) {
9292 await db . update ( schema . runs ) . set ( { isProduction : false } ) . where ( eq ( schema . runs . id , currentProdRun . id ) ) ;
@@ -101,7 +101,7 @@ async function trainAndEvaluate() {
101101 isProduction : true ,
102102 } ) ;
103103
104- console . log ( 'Pipeline de treinamento concluído com sucesso !' ) ;
104+ console . log ( 'Training pipeline completed successfully !' ) ;
105105}
106106
107107trainAndEvaluate ( ) ;
0 commit comments