Skip to content

Commit

Permalink
Added seed parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Olcay Taner YILDIZ committed Aug 26, 2021
1 parent 5448e24 commit fda680a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/WordToVec/NeuralNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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()))
Expand Down
20 changes: 20 additions & 0 deletions Sources/WordToVec/WordToVecParameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
}

}

0 comments on commit fda680a

Please sign in to comment.