Skip to content

Commit

Permalink
Merge pull request #97 from sashafrey/master
Browse files Browse the repository at this point in the history
Minor enhancements in python interface
  • Loading branch information
bigartm committed Jan 3, 2015
2 parents d5b4d32 + 485d7a7 commit 8bae77f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/ref/python_interface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ MasterComponent

The behavior of this method also depends on :attr:`MasterComponentConfig.online_batch_processing` flag.

.. py:method:: InvokeIteration(iterations_count)
.. py:method:: InvokeIteration(iterations_count = 1)

Invokes several iterations over the collection. The recommended value for *iterations_count* is 1.
For more iterations use for loop around :py:meth:`InvokeIteration` method.
Expand Down Expand Up @@ -293,10 +293,10 @@ Model

Returns current :ref:`ModelConfig` of the topic model.

.. py:method:: Synchronize(decay_weight = 0.0, invoke_regularizers = True)
.. py:method:: Synchronize(decay_weight = 0.0, apply_weight = 1.0, invoke_regularizers = True)

This operation updates the Phi matrix of the topic model with all model increments, collected since the last call to :py:meth:`Synchronize` method.
The weights in the Phi matrix are decreased according to *decay_weight* (refer to :attr:`SynchronizeModelArgs.decay_weight` for more details).
The Phi matrix is calculated according to *decay_weight* and *apply_weight* (refer to :attr:`SynchronizeModelArgs.decay_weight` for more details).
Depending on *invoke_regularizers* parameter this operation may also invoke all regularizers.

Remember to call :py:meth:`Synchronize` operation every time after call :py:meth:`MasterComponent.WaitIdle`.
Expand Down
10 changes: 7 additions & 3 deletions src/python/artm/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def AddBatch(self, batch):
batch_blob_p = ctypes.create_string_buffer(batch_blob)
HandleErrorCode(self.lib_, self.lib_.ArtmAddBatch(self.id_, len(batch_blob), batch_blob_p))

def InvokeIteration(self, iterations_count):
def InvokeIteration(self, iterations_count = 1):
HandleErrorCode(self.lib_, self.lib_.ArtmInvokeIteration(self.id_, iterations_count))

def WaitIdle(self, timeout = -1):
Expand Down Expand Up @@ -452,10 +452,11 @@ def Reconfigure(self, config = None):
len(model_config_blob), model_config_blob_p))
self.config_.CopyFrom(config)

def Synchronize(self, decay_weight = 0.0, invoke_regularizers = True):
def Synchronize(self, decay_weight = 0.0, apply_weight = 1.0, invoke_regularizers = True):
args = messages_pb2.SynchronizeModelArgs();
args.model_name = self.name()
args.decay_weight = decay_weight
args.apply_weight = apply_weight
args.invoke_regularizers = invoke_regularizers
args_blob = args.SerializeToString()
args_blob_p = ctypes.create_string_buffer(args_blob)
Expand All @@ -473,7 +474,10 @@ def Initialize(self, dictionary):
self.lib_.ArtmInitializeModel(self.master_id_, len(blob), blob_p))

def Overwrite(self, topic_model):
blob = topic_model.SerializeToString()
copy_ = messages_pb2.TopicModel()
copy_.CopyFrom(topic_model)
copy_.name = self.name()
blob = copy_.SerializeToString()
blob_p = ctypes.create_string_buffer(blob)
HandleErrorCode(self.lib_,
self.lib_.ArtmOverwriteTopicModel(self.master_id_, len(blob), blob_p))
Expand Down

0 comments on commit 8bae77f

Please sign in to comment.