Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda