Skip to content

Commit

Permalink
Merge pull request #28 from machine-intelligence-laboratory/release/v…
Browse files Browse the repository at this point in the history
…0.6.0

Release/v0.6.0
  • Loading branch information
Alvant authored Feb 22, 2020
2 parents 0c6bf4f + fa2c410 commit 988b70d
Show file tree
Hide file tree
Showing 41 changed files with 8,857 additions and 603 deletions.
20 changes: 9 additions & 11 deletions docs/cooking_machine/config_parser.html
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.config_parser</code></h1

Returns
-------
instance of artm.Score or topicnet.BaseScore
instance of artm.scores.BaseScore or topicnet.cooking_machine.models.base_score
&#34;&#34;&#34;
module = artm.scores if is_artm_score else tnscores
class_of_object = getattr(module, elemtype)
Expand Down Expand Up @@ -516,10 +516,10 @@ <h1 class="title">Module <code>topicnet.cooking_machine.config_parser</code></h1
})
parsed[&#34;model&#34;][&#34;modalities_weights&#34;].revalidate(local_schema)
modalities_weights = parsed[&#34;model&#34;][&#34;modalities_weights&#34;].data
return modalities_weights
else:
modalities_weights = None
modalities_to_use = parsed.data[&#34;model&#34;][&#34;modalities_to_use&#34;]
return modalities_to_use, modalities_weights
return modalities_to_use


def parse(yaml_string, force_single_thread=False):
Expand Down Expand Up @@ -552,7 +552,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.config_parser</code></h1

dataset = Dataset(parsed.data[&#34;model&#34;][&#34;dataset_path&#34;])

modalities_to_use, modalities_weights = parse_modalities_data(parsed)
modalities_to_use = parse_modalities_data(parsed)

data_stats = count_vocab_size(dataset.get_dictionary(), modalities_to_use)
model = init_simple_default_model(
Expand All @@ -561,7 +561,6 @@ <h1 class="title">Module <code>topicnet.cooking_machine.config_parser</code></h1
main_modality=parsed.data[&#34;model&#34;][&#34;main_modality&#34;],
specific_topics=parsed.data[&#34;topics&#34;][&#34;specific_topics&#34;],
background_topics=parsed.data[&#34;topics&#34;][&#34;background_topics&#34;],
modalities_weights=modalities_weights
)

regularizers = _add_parsed_regularizers(
Expand Down Expand Up @@ -925,7 +924,7 @@ <h2 id="returns">Returns</h2>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>instance</code> of <code>artm.Score</code> or <code>topicnet.BaseScore</code></dt>
<dt><code>instance</code> of <code>artm.scores.BaseScore</code> or <a title="topicnet.cooking_machine.models.base_score" href="models/base_score.html"><code>topicnet.cooking_machine.models.base_score</code></a></dt>
<dd>&nbsp;</dd>
</dl></section>
<details class="source">
Expand All @@ -943,7 +942,7 @@ <h2 id="returns">Returns</h2>

Returns
-------
instance of artm.Score or topicnet.BaseScore
instance of artm.scores.BaseScore or topicnet.cooking_machine.models.base_score
&#34;&#34;&#34;
module = artm.scores if is_artm_score else tnscores
class_of_object = getattr(module, elemtype)
Expand Down Expand Up @@ -1146,7 +1145,7 @@ <h2 id="returns">Returns</h2>

dataset = Dataset(parsed.data[&#34;model&#34;][&#34;dataset_path&#34;])

modalities_to_use, modalities_weights = parse_modalities_data(parsed)
modalities_to_use = parse_modalities_data(parsed)

data_stats = count_vocab_size(dataset.get_dictionary(), modalities_to_use)
model = init_simple_default_model(
Expand All @@ -1155,7 +1154,6 @@ <h2 id="returns">Returns</h2>
main_modality=parsed.data[&#34;model&#34;][&#34;main_modality&#34;],
specific_topics=parsed.data[&#34;topics&#34;][&#34;specific_topics&#34;],
background_topics=parsed.data[&#34;topics&#34;][&#34;background_topics&#34;],
modalities_weights=modalities_weights
)

regularizers = _add_parsed_regularizers(
Expand Down Expand Up @@ -1201,10 +1199,10 @@ <h2 id="returns">Returns</h2>
})
parsed[&#34;model&#34;][&#34;modalities_weights&#34;].revalidate(local_schema)
modalities_weights = parsed[&#34;model&#34;][&#34;modalities_weights&#34;].data
return modalities_weights
else:
modalities_weights = None
modalities_to_use = parsed.data[&#34;model&#34;][&#34;modalities_to_use&#34;]
return modalities_to_use, modalities_weights</code></pre>
return modalities_to_use</code></pre>
</details>
</dd>
<dt id="topicnet.cooking_machine.config_parser.preprocess_parameters_for_cube_creator"><code class="name flex">
Expand Down
65 changes: 32 additions & 33 deletions docs/cooking_machine/cubes/base_cube.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.base_cube</code></
from tqdm import tqdm
import warnings
from multiprocessing import Queue, Process
# from queue import Empty
from artm.wrapper.exceptions import ArtmException

from .strategy import BaseStrategy
Expand All @@ -39,6 +38,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.base_cube</code></
MODEL_RETRIEVE_ERROR = &#34;Retrieved only {0} models out of {1}&#34;
STRATEGY_RETRIEVE_ERROR = &#39;Failed to retrieve strategy parameters&#39;
WARNINGS_RETRIEVE_ERROR = &#39;Failed to return warnings&#39;
SCORE_ERROR_MESSAGE = &#34;Can&#39;t find a score &#39;&#39;{0}&#39;&#39;. Please add a score with that name to the model.&#34;


def check_experiment_existence(topic_model):
Expand All @@ -61,15 +61,16 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.base_cube</code></
return is_experiment


class retrieve_score_for_strategy:
def __init__(self, score_name):
self.score_name = score_name
def retrieve_score_for_strategy(score_name=None):
if not score_name:
score_name = &#39;PerplexityScore@all&#39;

def __call__(self, model):
if isinstance(model, str):
self.score_name = model
else:
return model.scores[self.score_name][-1]
def last_score(model):
try:
return model.scores[score_name][-1]
except KeyError:
raise KeyError(SCORE_ERROR_MESSAGE.format(score_name))
return last_score


# exists for multiprocessing debug
Expand Down Expand Up @@ -448,6 +449,27 @@ <h2 id="returns">Returns</h2>
queue.put(puttable)</code></pre>
</details>
</dd>
<dt id="topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy"><code class="name flex">
<span>def <span class="ident">retrieve_score_for_strategy</span></span>(<span>score_name=None)</span>
</code></dt>
<dd>
<section class="desc"></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def retrieve_score_for_strategy(score_name=None):
if not score_name:
score_name = &#39;PerplexityScore@all&#39;

def last_score(model):
try:
return model.scores[score_name][-1]
except KeyError:
raise KeyError(SCORE_ERROR_MESSAGE.format(score_name))
return last_score</code></pre>
</details>
</dd>
</dl>
</section>
<section>
Expand Down Expand Up @@ -861,27 +883,6 @@ <h2 id="returns">Returns</h2>
</dd>
</dl>
</dd>
<dt id="topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy"><code class="flex name class">
<span>class <span class="ident">retrieve_score_for_strategy</span></span>
<span>(</span><span>score_name)</span>
</code></dt>
<dd>
<section class="desc"></section>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class retrieve_score_for_strategy:
def __init__(self, score_name):
self.score_name = score_name

def __call__(self, model):
if isinstance(model, str):
self.score_name = model
else:
return model.scores[self.score_name][-1]</code></pre>
</details>
</dd>
</dl>
</section>
</article>
Expand All @@ -901,6 +902,7 @@ <h1>Index</h1>
<li><code><a title="topicnet.cooking_machine.cubes.base_cube.check_experiment_existence" href="#topicnet.cooking_machine.cubes.base_cube.check_experiment_existence">check_experiment_existence</a></code></li>
<li><code><a title="topicnet.cooking_machine.cubes.base_cube.get_from_queue_till_fail" href="#topicnet.cooking_machine.cubes.base_cube.get_from_queue_till_fail">get_from_queue_till_fail</a></code></li>
<li><code><a title="topicnet.cooking_machine.cubes.base_cube.put_to_queue" href="#topicnet.cooking_machine.cubes.base_cube.put_to_queue">put_to_queue</a></code></li>
<li><code><a title="topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy" href="#topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy">retrieve_score_for_strategy</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
Expand All @@ -912,9 +914,6 @@ <h4><code><a title="topicnet.cooking_machine.cubes.base_cube.BaseCube" href="#to
<li><code><a title="topicnet.cooking_machine.cubes.base_cube.BaseCube.get_jsonable_from_parameters" href="#topicnet.cooking_machine.cubes.base_cube.BaseCube.get_jsonable_from_parameters">get_jsonable_from_parameters</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy" href="#topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy">retrieve_score_for_strategy</a></code></h4>
</li>
</ul>
</li>
</ul>
Expand Down
38 changes: 28 additions & 10 deletions docs/cooking_machine/cubes/controller_cube.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ <h2 id="fields">Fields</h2>
Parameters
----------
reg_name : str
score_to_track : str or None
score_to_track : str, list of str or None
tau_converter : callable or str
local_dict : dict
max_iters : int or float
Expand All @@ -322,7 +322,13 @@ <h2 id="fields">Fields</h2>
&#34;&#34;&#34;
self.reg_name = reg_name
self.tau_converter = tau_converter
self.score_to_track = score_to_track
if isinstance(score_to_track, list):
self.score_to_track = score_to_track
elif isinstance(score_to_track, str):
self.score_to_track = [score_to_track]
else:
self.score_to_track = []

self.is_working = True
self.local_dict = local_dict
self.tau_history = []
Expand Down Expand Up @@ -371,7 +377,9 @@ <h2 id="fields">Fields</h2>
self.is_working = False

if self.is_working:
should_stop = is_score_out_of_control(model, self.score_to_track)
should_stop = any(
is_score_out_of_control(model, score) for score in self.score_to_track
)
if should_stop:
warnings.warn(W_HALT_CONTROL.format(len(self.tau_history)))
self.is_working = False
Expand Down Expand Up @@ -470,7 +478,7 @@ <h2 id="fields">Fields</h2>
&#34;max_iters&#34;: params_dict.get(&#34;max_iters&#34;, self.num_iter)
},
&#34;field&#34;: &#34;callback&#34;,
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [])
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [0])
}
for params_dict in all_parameters
]
Expand Down Expand Up @@ -649,7 +657,7 @@ <h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>reg_name</code></strong> :&ensp;<code>str</code></dt>
<dd>&nbsp;</dd>
<dt><strong><code>score_to_track</code></strong> :&ensp;<code>str</code> or <code>None</code></dt>
<dt><strong><code>score_to_track</code></strong> :&ensp;<code>str</code>, <code>list</code> of <code>str</code> or <code>None</code></dt>
<dd>&nbsp;</dd>
<dt><strong><code>tau_converter</code></strong> :&ensp;<code>callable</code> or <code>str</code></dt>
<dd>&nbsp;</dd>
Expand Down Expand Up @@ -690,7 +698,7 @@ <h2 id="parameters">Parameters</h2>
Parameters
----------
reg_name : str
score_to_track : str or None
score_to_track : str, list of str or None
tau_converter : callable or str
local_dict : dict
max_iters : int or float
Expand All @@ -700,7 +708,13 @@ <h2 id="parameters">Parameters</h2>
&#34;&#34;&#34;
self.reg_name = reg_name
self.tau_converter = tau_converter
self.score_to_track = score_to_track
if isinstance(score_to_track, list):
self.score_to_track = score_to_track
elif isinstance(score_to_track, str):
self.score_to_track = [score_to_track]
else:
self.score_to_track = []

self.is_working = True
self.local_dict = local_dict
self.tau_history = []
Expand Down Expand Up @@ -749,7 +763,9 @@ <h2 id="parameters">Parameters</h2>
self.is_working = False

if self.is_working:
should_stop = is_score_out_of_control(model, self.score_to_track)
should_stop = any(
is_score_out_of_control(model, score) for score in self.score_to_track
)
if should_stop:
warnings.warn(W_HALT_CONTROL.format(len(self.tau_history)))
self.is_working = False
Expand Down Expand Up @@ -799,7 +815,9 @@ <h2 id="parameters">Parameters</h2>
self.is_working = False

if self.is_working:
should_stop = is_score_out_of_control(model, self.score_to_track)
should_stop = any(
is_score_out_of_control(model, score) for score in self.score_to_track
)
if should_stop:
warnings.warn(W_HALT_CONTROL.format(len(self.tau_history)))
self.is_working = False
Expand Down Expand Up @@ -957,7 +975,7 @@ <h2 id="parameters">Parameters</h2>
&#34;max_iters&#34;: params_dict.get(&#34;max_iters&#34;, self.num_iter)
},
&#34;field&#34;: &#34;callback&#34;,
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [])
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [0])
}
for params_dict in all_parameters
]
Expand Down
16 changes: 5 additions & 11 deletions docs/cooking_machine/cubes/cube_creator.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.cube_creator</code
raise AttributeError(&#39;This model is not implemented&#39;)

self._model_class = model.__class__
self._library_version = model._model.library_version
self._library_version = getattr(model, &#39;library_version&#39;, &#39;not defined&#39;)

param_set = [dictionary[&#39;name&#39;] for dictionary in parameters]
topic_related = set([&#39;topic_names&#39;, &#39;num_topics&#39;]) &amp; set(param_set)
Expand Down Expand Up @@ -198,10 +198,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.cube_creator</code
if self._second_level:
jsonable_parameters[&#39;additional_info&#39;] = &#39;hierarchical: Second level.&#39;

try:
jsonable_parameters[&#39;version&#39;] = self._library_version
except AttributeError:
jsonable_parameters[&#39;version&#39;] = &#34;undefined&#34;
jsonable_parameters[&#39;version&#39;] = self._library_version
return [jsonable_parameters]

def apply(self, topic_model, one_cube_parameter, dictionary=None, model_id=None):
Expand Down Expand Up @@ -357,7 +354,7 @@ <h2 id="parameters">Parameters</h2>
raise AttributeError(&#39;This model is not implemented&#39;)

self._model_class = model.__class__
self._library_version = model._model.library_version
self._library_version = getattr(model, &#39;library_version&#39;, &#39;not defined&#39;)

param_set = [dictionary[&#39;name&#39;] for dictionary in parameters]
topic_related = set([&#39;topic_names&#39;, &#39;num_topics&#39;]) &amp; set(param_set)
Expand Down Expand Up @@ -467,10 +464,7 @@ <h2 id="parameters">Parameters</h2>
if self._second_level:
jsonable_parameters[&#39;additional_info&#39;] = &#39;hierarchical: Second level.&#39;

try:
jsonable_parameters[&#39;version&#39;] = self._library_version
except AttributeError:
jsonable_parameters[&#39;version&#39;] = &#34;undefined&#34;
jsonable_parameters[&#39;version&#39;] = self._library_version
return [jsonable_parameters]

def apply(self, topic_model, one_cube_parameter, dictionary=None, model_id=None):
Expand Down Expand Up @@ -535,7 +529,7 @@ <h3>Class variables</h3>
<dl>
<dt id="topicnet.cooking_machine.cubes.cube_creator.CubeCreator.DEFAULT_SEED_VALUE"><code class="name">var <span class="ident">DEFAULT_SEED_VALUE</span></code></dt>
<dd>
<section class="desc"><p>int([x]) -&gt; integer
<section class="desc"><p>int(x=0) -&gt; integer
int(x, base=10) -&gt; integer</p>
<p>Convert a number or string to an integer, or return 0 if no arguments
are given.
Expand Down
4 changes: 2 additions & 2 deletions docs/cooking_machine/cubes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<header>
<h1 class="title">Module <code>topicnet.cooking_machine.cubes</code></h1>
</header>
<p>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD # Cubes and their Strategies</p>
<p>Cubes and their Strategies</p>
<p>Cube types:</p>
<ul>
<li><code>BaseCube</code> — a parent class for all the Cubes</li>
Expand Down Expand Up @@ -140,4 +140,4 @@ <h1><code>TopicNet</code> library documentation </h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad()</script>
</body>
</html>
</html>
Loading

0 comments on commit 988b70d

Please sign in to comment.