class NeuralNetwork {
  constructor(inputSize, outputSize) {
    // Initialize weights and biases with random values
    this.weights = Array.from({ length: inputSize }, () => Math.random());
    this.bias = Math.random();
    this.outputSize = outputSize;
  }

  // Sigmoid activation function
  sigmoid(x) {
    return 1 / (1 + Math.exp(-x));
  }

  // Feedforward calculation
  feedforward(inputs) {
    // Calculate weighted sum of inputs and weights, add bias, and apply sigmoid activation function
    const output = [];
    for (let i = 0; i < this.outputSize; i++) {
      let sum = 0;
      for (let j = 0; j < inputs.length; j++) {
        sum += inputs[j] * this.weights[j];
      }
      sum += this.bias;
      output.push(this.sigmoid(sum));
    }
    return output;
  }

  // Train the network on a set of input/output pairs using gradient descent
  train(inputs, expectedOutputs, learningRate, epochs) {
    for (let epoch = 0; epoch < epochs; epoch++) {
      for (let i = 0; i < inputs.length; i++) {
        const output = this.feedforward(inputs[i]);

        // Calculate error for each output node
        const errors = [];
        for (let j = 0; j < this.outputSize; j++) {
          errors.push(expectedOutputs[i][j] - output[j]);
        }

        // Update weights and bias for each input node
        for (let j = 0; j < inputs[i].length; j++) {
          for (let k = 0; k < this.outputSize; k++) {
            this.weights[j] += learningRate * errors[k] * output[k] * (1 - output[k]) * inputs[i][j];
          }
        }
        for (let j = 0; j < this.outputSize; j++) {
          this.bias += learningRate * errors[j] * output[j] * (1 - output[j]);
        }
      }
    }
  }
}
spam lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor creativity violence