<commit_before>require 'nmatrix/nmatrix'

module NnFunctions
  def sigmoid(x)
    N::ones_like(x) / ((-x).exp + 1.0)
  end

  def softmax(x)
    x2 = x - x.max(1)[0]
    x2.exp / x2.exp.sum(1)[0]
  end

  def argmax(x)
    y = x.shape[0] == 1 ? [x.to_a] : x.to_a
    res = y.to_a.map do |row|
      max = -Float::MAX
      idx = nil
      row.each_with_index do |n, i|
        if n > max
          idx = i
          max = n
        end
      end
      idx
    end
    N[*res]
  end
end<commit_msg>Remove redundant processing<commit_after>require 'nmatrix/nmatrix'

module NnFunctions
  def sigmoid(x)
    N::ones_like(x) / ((-x).exp + 1.0)
  end

  def softmax(x)
    x2 = x - x.max(1)[0]
    x2.exp / x2.exp.sum(1)[0]
  end

  def argmax(x)
    list = x.shape[0] == 1 ? [x.to_a] : x.to_a
    res = list.map do |row|
      max = -Float::MAX
      idx = nil
      row.each_with_index do |n, i|
        if n > max
          idx = i
          max = n
        end
      end
      idx
    end
    N[*res]
  end
end
{'fraction_non_alphanumeric': 0.14172447968285432, 'fraction_numerical': 0.02180376610505451, 'mean_word_length': 1.616580310880829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2919994', 'n_tokens_mistral': 441, 'n_tokens_neox': 426, 'n_words': 103}