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 38c8b2f commit 50c4bfd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
7 changes: 4 additions & 3 deletions WordToVec/NeuralNetwork.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ cdef class NeuralNetwork:
self.__vocabulary = Vocabulary(corpus)
self.__parameter = parameter
self.__corpus = corpus
self.__wordVectors = Matrix(self.__vocabulary.size(), self.__parameter.getLayerSize(), -0.5, 0.5)
self.__wordVectors = Matrix(self.__vocabulary.size(), self.__parameter.getLayerSize(), -0.5, 0.5,
parameter.getSeed())
self.__wordVectorUpdate = Matrix(self.__vocabulary.size(), self.__parameter.getLayerSize())
self.__prepareExpTable()

Expand Down Expand Up @@ -119,7 +120,7 @@ cdef class NeuralNetwork:
outputs.initAllSame(self.__parameter.getLayerSize(), 0.0)
outputUpdate = Vector()
outputUpdate.initAllSame(self.__parameter.getLayerSize(), 0)
self.__corpus.shuffleSentences(1)
self.__corpus.shuffleSentences(self.__parameter.getSeed())
while iteration.getIterationCount() < self.__parameter.getNumberOfIterations():
iteration.alphaUpdate()
wordIndex = self.__vocabulary.getPosition(currentSentence.getWord(iteration.getSentencePosition()))
Expand Down Expand Up @@ -188,7 +189,7 @@ cdef class NeuralNetwork:
outputs.initAllSame(self.__parameter.getLayerSize(), 0.0)
outputUpdate = Vector()
outputUpdate.initAllSame(self.__parameter.getLayerSize(), 0)
self.__corpus.shuffleSentences(1)
self.__corpus.shuffleSentences(self.__parameter.getSeed())
while iteration.getIterationCount() < self.__parameter.getNumberOfIterations():
iteration.alphaUpdate()
wordIndex = self.__vocabulary.getPosition(currentSentence.getWord(iteration.getSentencePosition()))
Expand Down
2 changes: 2 additions & 0 deletions WordToVec/WordToVecParameter.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ cdef class WordToVecParameter:
cpdef bint isHierarchicalSoftMax(self)
cpdef int getNegativeSamplingSize(self)
cpdef int getNumberOfIterations(self)
cpdef int getSeed(self)
cpdef setLayerSize(self, int layerSize)
cpdef setCbow(self, bint cbow)
cpdef setAlpha(self, double alpha)
cpdef setWindow(self, int window)
cpdef setHierarchialSoftMax(self, bint hierarchicalSoftMax)
cpdef setNegativeSamplingSize(self, int negativeSamplingSize)
cpdef setNumberOfIterations(self, int numberOfIterations)
cpdef setSeed(self, int seed)
23 changes: 23 additions & 0 deletions WordToVec/WordToVecParameter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cdef class WordToVecParameter:
self.__negativeSamplingSize = 5
self.__numberOfIterations = 3
self.__window = 5
self.__seed = 1

cpdef int getLayerSize(self):
"""
Expand Down Expand Up @@ -89,6 +90,17 @@ cdef class WordToVecParameter:
"""
return self.__numberOfIterations

cpdef int getSeed(self):
"""
Accessor for the seed attribute.
RETURNS
-------
int
Seed to train the network.
"""
return self.__seed

cpdef setLayerSize(self, int layerSize):
"""
Mutator for the layerSize attribute.
Expand Down Expand Up @@ -165,3 +177,14 @@ cdef class WordToVecParameter:
New number of iterations.
"""
self.__numberOfIterations = numberOfIterations

cpdef setSeed(self, int seed):
"""
Mutator for the numberOfIterations attribute.
PARAMETERS
----------
seed : int
New seed.
"""
self.__seed = seed
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ext_modules=cythonize(["WordToVec/*.pyx"],
compiler_directives={'language_level': "3"}),
name='NlpToolkit-WordToVec-Cy',
version='1.0.0',
version='1.0.1',
packages=['WordToVec'],
package_data={'WordToVec': ['*.pxd', '*.pyx', '*.c']},
url='https://github.com/StarlangSoftware/WordToVec-Cy',
Expand Down

0 comments on commit 50c4bfd

Please sign in to comment.