From fda680a3fb2bcefb1dfbe594dbb70df13dff7529 Mon Sep 17 00:00:00 2001 From: Olcay Taner YILDIZ Date: Thu, 26 Aug 2021 23:53:19 +0300 Subject: [PATCH] Added seed parameter. --- Sources/WordToVec/NeuralNetwork.swift | 4 ++-- Sources/WordToVec/WordToVecParameter.swift | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Sources/WordToVec/NeuralNetwork.swift b/Sources/WordToVec/NeuralNetwork.swift index f95ca6a..fce4b54 100644 --- a/Sources/WordToVec/NeuralNetwork.swift +++ b/Sources/WordToVec/NeuralNetwork.swift @@ -100,7 +100,7 @@ public class NeuralNetwork{ var currentSentence : Sentence = self.__corpus.getSentence(index: iteration.getSentenceIndex()) let outputs = Vector(size: self.__parameter.getLayerSize(), x: 0.0) let outputUpdate = Vector(size: self.__parameter.getLayerSize(), x: 0) - self.__corpus.shuffleSentences(seed: 1) + self.__corpus.shuffleSentences(seed: self.__parameter.getSeed()) while iteration.getIterationCount() < self.__parameter.getNumberOfIterations(){ iteration.alphaUpdate() let wordIndex = self.__vocabulary.getPosition(word: currentSentence.getWord(index: iteration.getSentencePosition())) @@ -177,7 +177,7 @@ public class NeuralNetwork{ var currentSentence : Sentence = self.__corpus.getSentence(index: iteration.getSentenceIndex()) let outputs = Vector(size: self.__parameter.getLayerSize(), x: 0.0) let outputUpdate = Vector(size: self.__parameter.getLayerSize(), x: 0) - self.__corpus.shuffleSentences(seed: 1) + self.__corpus.shuffleSentences(seed: self.__parameter.getSeed()) while iteration.getIterationCount() < self.__parameter.getNumberOfIterations(){ iteration.alphaUpdate() let wordIndex = self.__vocabulary.getPosition(word: currentSentence.getWord(index: iteration.getSentencePosition())) diff --git a/Sources/WordToVec/WordToVecParameter.swift b/Sources/WordToVec/WordToVecParameter.swift index b3e248a..1f373d8 100644 --- a/Sources/WordToVec/WordToVecParameter.swift +++ b/Sources/WordToVec/WordToVecParameter.swift @@ -16,6 +16,7 @@ public class WordToVecParameter{ private var __hierarchicalSoftMax: Bool = false private var __negativeSamplingSize: Int = 5 private var __numberOfIterations: Int = 3 + private var __seed: Int = 1 /** Empty constructor for Word2Vec parameter @@ -89,6 +90,15 @@ public class WordToVecParameter{ return self.__numberOfIterations } + /** + Accessor for the seed attribute. + + - Returns: Seed to train the network. + */ + public func getSeed() -> Int{ + return self.__seed + } + /** Mutator for the layerSize attribute. @@ -151,4 +161,14 @@ public class WordToVecParameter{ public func setNumberOfIterations(numberOfIterations: Int){ self.__numberOfIterations = numberOfIterations } + + /** + Mutator for the seed attribute. + + - Parameter seed : New seed. + */ + public func setSeed(seed: Int){ + self.__seed = seed + } + }