Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
How to dynamically add items to a function that takes in a list of objects

so I'm using the 'limdu' ML library (https://www.npmjs.com/package/limdu). In it, I am trying to use the .trainBatch() function. Train batch takes in a list of objects, with each object having an input (being another object) and an output, being an array of strings. An example looks like this:

intentClassifier.trainBatch([
  { input: { I: 1, want: 1, an: 1, apple: 1 }, output: ["WANT", "APPLE"] },
  { input: { I: 1, want: 1, a: 1, banana: 1 }, output: ["BANANA", "WANT"] },
  { input: { I: 1, want: 1, chips: 1 }, output: "CHIPS" },
]);

Now, I'm trying to pass in dynamic information into the trainBatch function. I have a csv file where each row has the 'input' and 'output' to be passed in. The parsing of the .csv can be seen below:

var trainingData = {}
fs.createReadStream('data.csv')
  .pipe(csv.parse({ headers: true }))
  .on('error', error => console.error(error))
  .on('data', row => {
    trainingData[row.input] = [row.output]
  })
  .on('end', rowCount => console.log(trainingData));

At this point, training data is an object where all the inputs are keys and the outputs are the values of corresponding string arrays. My question is how do I add these inputs and outputs inside of the .trainBatch() function? Any help is much appreciated, I'm really lost.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are building an object, when the function you are calling expects an array. Perhaps you should build an array instead, and push each row in the array? Then, on end, simply pass the constructed array to trainBatch

let trainingData = [];

fs.createReadStream('data.csv')
  .pipe(csv.parse({ headers: true }))
  .on('error', error => console.error(error))
  .on('data', row => {
    trainingData.push({input:row.input, output:row.output})
  })
  .on('end', rowCount => trainBatch(trainingData));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda