Skip to content

Commit 988b70d

Browse files
authored
Merge pull request #28 from machine-intelligence-laboratory/release/v0.6.0
Release/v0.6.0
2 parents 0c6bf4f + fa2c410 commit 988b70d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8857
-603
lines changed

docs/cooking_machine/config_parser.html

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.config_parser</code></h1
405405

406406
Returns
407407
-------
408-
instance of artm.Score or topicnet.BaseScore
408+
instance of artm.scores.BaseScore or topicnet.cooking_machine.models.base_score
409409
&#34;&#34;&#34;
410410
module = artm.scores if is_artm_score else tnscores
411411
class_of_object = getattr(module, elemtype)
@@ -516,10 +516,10 @@ <h1 class="title">Module <code>topicnet.cooking_machine.config_parser</code></h1
516516
})
517517
parsed[&#34;model&#34;][&#34;modalities_weights&#34;].revalidate(local_schema)
518518
modalities_weights = parsed[&#34;model&#34;][&#34;modalities_weights&#34;].data
519+
return modalities_weights
519520
else:
520-
modalities_weights = None
521521
modalities_to_use = parsed.data[&#34;model&#34;][&#34;modalities_to_use&#34;]
522-
return modalities_to_use, modalities_weights
522+
return modalities_to_use
523523

524524

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

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

555-
modalities_to_use, modalities_weights = parse_modalities_data(parsed)
555+
modalities_to_use = parse_modalities_data(parsed)
556556

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

567566
regularizers = _add_parsed_regularizers(
@@ -925,7 +924,7 @@ <h2 id="returns">Returns</h2>
925924
</dl>
926925
<h2 id="returns">Returns</h2>
927926
<dl>
928-
<dt><code>instance</code> of <code>artm.Score</code> or <code>topicnet.BaseScore</code></dt>
927+
<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>
929928
<dd>&nbsp;</dd>
930929
</dl></section>
931930
<details class="source">
@@ -943,7 +942,7 @@ <h2 id="returns">Returns</h2>
943942

944943
Returns
945944
-------
946-
instance of artm.Score or topicnet.BaseScore
945+
instance of artm.scores.BaseScore or topicnet.cooking_machine.models.base_score
947946
&#34;&#34;&#34;
948947
module = artm.scores if is_artm_score else tnscores
949948
class_of_object = getattr(module, elemtype)
@@ -1146,7 +1145,7 @@ <h2 id="returns">Returns</h2>
11461145

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

1149-
modalities_to_use, modalities_weights = parse_modalities_data(parsed)
1148+
modalities_to_use = parse_modalities_data(parsed)
11501149

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

11611159
regularizers = _add_parsed_regularizers(
@@ -1201,10 +1199,10 @@ <h2 id="returns">Returns</h2>
12011199
})
12021200
parsed[&#34;model&#34;][&#34;modalities_weights&#34;].revalidate(local_schema)
12031201
modalities_weights = parsed[&#34;model&#34;][&#34;modalities_weights&#34;].data
1202+
return modalities_weights
12041203
else:
1205-
modalities_weights = None
12061204
modalities_to_use = parsed.data[&#34;model&#34;][&#34;modalities_to_use&#34;]
1207-
return modalities_to_use, modalities_weights</code></pre>
1205+
return modalities_to_use</code></pre>
12081206
</details>
12091207
</dd>
12101208
<dt id="topicnet.cooking_machine.config_parser.preprocess_parameters_for_cube_creator"><code class="name flex">

docs/cooking_machine/cubes/base_cube.html

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.base_cube</code></
2828
from tqdm import tqdm
2929
import warnings
3030
from multiprocessing import Queue, Process
31-
# from queue import Empty
3231
from artm.wrapper.exceptions import ArtmException
3332

3433
from .strategy import BaseStrategy
@@ -39,6 +38,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.base_cube</code></
3938
MODEL_RETRIEVE_ERROR = &#34;Retrieved only {0} models out of {1}&#34;
4039
STRATEGY_RETRIEVE_ERROR = &#39;Failed to retrieve strategy parameters&#39;
4140
WARNINGS_RETRIEVE_ERROR = &#39;Failed to return warnings&#39;
41+
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;
4242

4343

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

6363

64-
class retrieve_score_for_strategy:
65-
def __init__(self, score_name):
66-
self.score_name = score_name
64+
def retrieve_score_for_strategy(score_name=None):
65+
if not score_name:
66+
score_name = &#39;PerplexityScore@all&#39;
6767

68-
def __call__(self, model):
69-
if isinstance(model, str):
70-
self.score_name = model
71-
else:
72-
return model.scores[self.score_name][-1]
68+
def last_score(model):
69+
try:
70+
return model.scores[score_name][-1]
71+
except KeyError:
72+
raise KeyError(SCORE_ERROR_MESSAGE.format(score_name))
73+
return last_score
7374

7475

7576
# exists for multiprocessing debug
@@ -448,6 +449,27 @@ <h2 id="returns">Returns</h2>
448449
queue.put(puttable)</code></pre>
449450
</details>
450451
</dd>
452+
<dt id="topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy"><code class="name flex">
453+
<span>def <span class="ident">retrieve_score_for_strategy</span></span>(<span>score_name=None)</span>
454+
</code></dt>
455+
<dd>
456+
<section class="desc"></section>
457+
<details class="source">
458+
<summary>
459+
<span>Expand source code</span>
460+
</summary>
461+
<pre><code class="python">def retrieve_score_for_strategy(score_name=None):
462+
if not score_name:
463+
score_name = &#39;PerplexityScore@all&#39;
464+
465+
def last_score(model):
466+
try:
467+
return model.scores[score_name][-1]
468+
except KeyError:
469+
raise KeyError(SCORE_ERROR_MESSAGE.format(score_name))
470+
return last_score</code></pre>
471+
</details>
472+
</dd>
451473
</dl>
452474
</section>
453475
<section>
@@ -861,27 +883,6 @@ <h2 id="returns">Returns</h2>
861883
</dd>
862884
</dl>
863885
</dd>
864-
<dt id="topicnet.cooking_machine.cubes.base_cube.retrieve_score_for_strategy"><code class="flex name class">
865-
<span>class <span class="ident">retrieve_score_for_strategy</span></span>
866-
<span>(</span><span>score_name)</span>
867-
</code></dt>
868-
<dd>
869-
<section class="desc"></section>
870-
<details class="source">
871-
<summary>
872-
<span>Expand source code</span>
873-
</summary>
874-
<pre><code class="python">class retrieve_score_for_strategy:
875-
def __init__(self, score_name):
876-
self.score_name = score_name
877-
878-
def __call__(self, model):
879-
if isinstance(model, str):
880-
self.score_name = model
881-
else:
882-
return model.scores[self.score_name][-1]</code></pre>
883-
</details>
884-
</dd>
885886
</dl>
886887
</section>
887888
</article>
@@ -901,6 +902,7 @@ <h1>Index</h1>
901902
<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>
902903
<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>
903904
<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>
905+
<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>
904906
</ul>
905907
</li>
906908
<li><h3><a href="#header-classes">Classes</a></h3>
@@ -912,9 +914,6 @@ <h4><code><a title="topicnet.cooking_machine.cubes.base_cube.BaseCube" href="#to
912914
<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>
913915
</ul>
914916
</li>
915-
<li>
916-
<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>
917-
</li>
918917
</ul>
919918
</li>
920919
</ul>

docs/cooking_machine/cubes/controller_cube.html

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ <h2 id="fields">Fields</h2>
312312
Parameters
313313
----------
314314
reg_name : str
315-
score_to_track : str or None
315+
score_to_track : str, list of str or None
316316
tau_converter : callable or str
317317
local_dict : dict
318318
max_iters : int or float
@@ -322,7 +322,13 @@ <h2 id="fields">Fields</h2>
322322
&#34;&#34;&#34;
323323
self.reg_name = reg_name
324324
self.tau_converter = tau_converter
325-
self.score_to_track = score_to_track
325+
if isinstance(score_to_track, list):
326+
self.score_to_track = score_to_track
327+
elif isinstance(score_to_track, str):
328+
self.score_to_track = [score_to_track]
329+
else:
330+
self.score_to_track = []
331+
326332
self.is_working = True
327333
self.local_dict = local_dict
328334
self.tau_history = []
@@ -371,7 +377,9 @@ <h2 id="fields">Fields</h2>
371377
self.is_working = False
372378

373379
if self.is_working:
374-
should_stop = is_score_out_of_control(model, self.score_to_track)
380+
should_stop = any(
381+
is_score_out_of_control(model, score) for score in self.score_to_track
382+
)
375383
if should_stop:
376384
warnings.warn(W_HALT_CONTROL.format(len(self.tau_history)))
377385
self.is_working = False
@@ -470,7 +478,7 @@ <h2 id="fields">Fields</h2>
470478
&#34;max_iters&#34;: params_dict.get(&#34;max_iters&#34;, self.num_iter)
471479
},
472480
&#34;field&#34;: &#34;callback&#34;,
473-
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [])
481+
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [0])
474482
}
475483
for params_dict in all_parameters
476484
]
@@ -649,7 +657,7 @@ <h2 id="parameters">Parameters</h2>
649657
<dl>
650658
<dt><strong><code>reg_name</code></strong> :&ensp;<code>str</code></dt>
651659
<dd>&nbsp;</dd>
652-
<dt><strong><code>score_to_track</code></strong> :&ensp;<code>str</code> or <code>None</code></dt>
660+
<dt><strong><code>score_to_track</code></strong> :&ensp;<code>str</code>, <code>list</code> of <code>str</code> or <code>None</code></dt>
653661
<dd>&nbsp;</dd>
654662
<dt><strong><code>tau_converter</code></strong> :&ensp;<code>callable</code> or <code>str</code></dt>
655663
<dd>&nbsp;</dd>
@@ -690,7 +698,7 @@ <h2 id="parameters">Parameters</h2>
690698
Parameters
691699
----------
692700
reg_name : str
693-
score_to_track : str or None
701+
score_to_track : str, list of str or None
694702
tau_converter : callable or str
695703
local_dict : dict
696704
max_iters : int or float
@@ -700,7 +708,13 @@ <h2 id="parameters">Parameters</h2>
700708
&#34;&#34;&#34;
701709
self.reg_name = reg_name
702710
self.tau_converter = tau_converter
703-
self.score_to_track = score_to_track
711+
if isinstance(score_to_track, list):
712+
self.score_to_track = score_to_track
713+
elif isinstance(score_to_track, str):
714+
self.score_to_track = [score_to_track]
715+
else:
716+
self.score_to_track = []
717+
704718
self.is_working = True
705719
self.local_dict = local_dict
706720
self.tau_history = []
@@ -749,7 +763,9 @@ <h2 id="parameters">Parameters</h2>
749763
self.is_working = False
750764

751765
if self.is_working:
752-
should_stop = is_score_out_of_control(model, self.score_to_track)
766+
should_stop = any(
767+
is_score_out_of_control(model, score) for score in self.score_to_track
768+
)
753769
if should_stop:
754770
warnings.warn(W_HALT_CONTROL.format(len(self.tau_history)))
755771
self.is_working = False
@@ -799,7 +815,9 @@ <h2 id="parameters">Parameters</h2>
799815
self.is_working = False
800816

801817
if self.is_working:
802-
should_stop = is_score_out_of_control(model, self.score_to_track)
818+
should_stop = any(
819+
is_score_out_of_control(model, score) for score in self.score_to_track
820+
)
803821
if should_stop:
804822
warnings.warn(W_HALT_CONTROL.format(len(self.tau_history)))
805823
self.is_working = False
@@ -957,7 +975,7 @@ <h2 id="parameters">Parameters</h2>
957975
&#34;max_iters&#34;: params_dict.get(&#34;max_iters&#34;, self.num_iter)
958976
},
959977
&#34;field&#34;: &#34;callback&#34;,
960-
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [])
978+
&#34;values&#34;: params_dict.get(&#39;user_value_grid&#39;, [0])
961979
}
962980
for params_dict in all_parameters
963981
]

docs/cooking_machine/cubes/cube_creator.html

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h1 class="title">Module <code>topicnet.cooking_machine.cubes.cube_creator</code
8888
raise AttributeError(&#39;This model is not implemented&#39;)
8989

9090
self._model_class = model.__class__
91-
self._library_version = model._model.library_version
91+
self._library_version = getattr(model, &#39;library_version&#39;, &#39;not defined&#39;)
9292

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

201-
try:
202-
jsonable_parameters[&#39;version&#39;] = self._library_version
203-
except AttributeError:
204-
jsonable_parameters[&#39;version&#39;] = &#34;undefined&#34;
201+
jsonable_parameters[&#39;version&#39;] = self._library_version
205202
return [jsonable_parameters]
206203

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

359356
self._model_class = model.__class__
360-
self._library_version = model._model.library_version
357+
self._library_version = getattr(model, &#39;library_version&#39;, &#39;not defined&#39;)
361358

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

470-
try:
471-
jsonable_parameters[&#39;version&#39;] = self._library_version
472-
except AttributeError:
473-
jsonable_parameters[&#39;version&#39;] = &#34;undefined&#34;
467+
jsonable_parameters[&#39;version&#39;] = self._library_version
474468
return [jsonable_parameters]
475469

476470
def apply(self, topic_model, one_cube_parameter, dictionary=None, model_id=None):
@@ -535,7 +529,7 @@ <h3>Class variables</h3>
535529
<dl>
536530
<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>
537531
<dd>
538-
<section class="desc"><p>int([x]) -&gt; integer
532+
<section class="desc"><p>int(x=0) -&gt; integer
539533
int(x, base=10) -&gt; integer</p>
540534
<p>Convert a number or string to an integer, or return 0 if no arguments
541535
are given.

docs/cooking_machine/cubes/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<header>
2020
<h1 class="title">Module <code>topicnet.cooking_machine.cubes</code></h1>
2121
</header>
22-
<p>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD # Cubes and their Strategies</p>
22+
<p>Cubes and their Strategies</p>
2323
<p>Cube types:</p>
2424
<ul>
2525
<li><code>BaseCube</code> — a parent class for all the Cubes</li>
@@ -140,4 +140,4 @@ <h1><code>TopicNet</code> library documentation </h1>
140140
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
141141
<script>hljs.initHighlightingOnLoad()</script>
142142
</body>
143-
</html>
143+
</html>

0 commit comments

Comments
 (0)