<commit_before>/* Copyright 2016-present The KotlinNLP Authors. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at http://mozilla.org/MPL/2.0/.
 * ------------------------------------------------------------------*/

package com.kotlinnlp.simplednn.deeplearning.mergelayers.biaffine

import com.kotlinnlp.simplednn.core.arrays.AugmentedArray
import com.kotlinnlp.simplednn.simplemath.ndarray.dense.DenseNDArray
import com.kotlinnlp.simplednn.utils.ItemsPool

/**
 * A pool of [BiaffineLayerStructure]s with dense input, which allows to allocate and release one when needed, without
 * creating a new one.
 * It is useful to optimize the creation of new structures every time a new encoder is created.
 *
 * @property model the model of a dense biaffine layer
 * @property dropout the probability of dropout (default = 0.0 -> if applying it, the usual value is 0.25)
 */
class DenseBiaffineLayersPool(
  val model: BiaffineLayerModel,
  val dropout: Double = 0.0
) : ItemsPool<BiaffineLayerStructure<DenseNDArray>>() {

  /**
   * The factory of a new [BiaffineLayerStructure].
   *
   * @param id the unique id of the item to create
   *
   * @return a new [BiaffineLayerStructure] with the given [id]
   */
  override fun itemFactory(id: Int) = BiaffineLayerStructure<DenseNDArray>(
    inputArray1 = AugmentedArray(this.model.params.inputSize1),
    inputArray2 = AugmentedArray(this.model.params.inputSize2),
    outputArray = AugmentedArray(this.model.params.outputSize),
    params = this.model.params,
    activationFunction = this.model.activationFunction,
    dropout = this.dropout,
    id = id)
}<commit_msg>Update itemFactory using a secondary constructor<commit_after>/* Copyright 2016-present The KotlinNLP Authors. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at http://mozilla.org/MPL/2.0/.
 * ------------------------------------------------------------------*/

package com.kotlinnlp.simplednn.deeplearning.mergelayers.biaffine

import com.kotlinnlp.simplednn.simplemath.ndarray.dense.DenseNDArray
import com.kotlinnlp.simplednn.utils.ItemsPool

/**
 * A pool of [BiaffineLayerStructure]s with dense input, which allows to allocate and release one when needed, without
 * creating a new one.
 * It is useful to optimize the creation of new structures every time a new encoder is created.
 *
 * @property model the model of a dense biaffine layer
 * @property dropout the probability of dropout (default = 0.0 -> if applying it, the usual value is 0.25)
 */
class DenseBiaffineLayersPool(
  val model: BiaffineLayerModel,
  val dropout: Double = 0.0
) : ItemsPool<BiaffineLayerStructure<DenseNDArray>>() {

  /**
   * The factory of a new [BiaffineLayerStructure].
   *
   * @param id the unique id of the item to create
   *
   * @return a new [BiaffineLayerStructure] with the given [id]
   */
  override fun itemFactory(id: Int) = BiaffineLayerStructure<DenseNDArray>(
    params = this.model.params,
    activationFunction = this.model.activationFunction,
    dropout = this.dropout,
    id = id)
}
{'fraction_non_alphanumeric': 0.12375490492001208, 'fraction_numerical': 0.010262601871415635, 'mean_word_length': 3.320730117340287, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '3878448', 'n_tokens_mistral': 1027, 'n_tokens_neox': 973, 'n_words': 331}