# How to save a learned HTM model?

**URL:** <https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561>\
**Category:** NuPIC\
**Created:** [July 20, 2017, 6:33am UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561 "2017-07-20T06:33:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaustabpal](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/kaustabpal/32/1347_2.png) [@kaustabpal](https://discourse.numenta.org/u/kaustabpal)\
**Post date:** [July 20, 2017, 6:33am UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/1 "2017-07-20T06:33:52Z")

</div>

I am using **Nupic Algorithms API** to implement the HTM. I want to know how I can **_save the learned HTM model_** so that the next time I start the program, HTM **continues learning from that point** instead of starting from scratch. Please note that I am using the **Algorithms API** and not the _OPF_ or _Network API_ to implement the HTM. Thank you. 🙂

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [July 20, 2017, 5:09pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/2 "2017-07-20T17:09:06Z")

</div>

Hello, see the docs for our [new serialization](http://nupic.docs.numenta.org/1.0.3/guides/serialization.html).

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 14, 2018, 4:34pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/3 "2018-05-14T16:34:51Z")

</div>

3 posts were split to a new topic: [KjException when serializing](https://discourse.numenta.org/t/kjexception-when-serializing/3901)

---

<div class="post-metadata">

**Author:** ![1113](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/1113/32/3291_2.png) [@1113](https://discourse.numenta.org/u/1113)\
**Post date:** [April 8, 2019, 11:53am UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/4 "2019-04-08T11:53:06Z")

</div>

Hi,

I wonder if there is an example of using the new serialization, and also if there is an example of using HTM for online streaming anomaly detection.

Thanks

Arkady

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [April 8, 2019, 12:04pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/5 "2019-04-08T12:04:38Z")

</div>

It’s old but should still work: [https://github.com/numenta/nupic/blob/master/examples/opf/clients/hotgym/anomaly/one\_gym/README.md](https://github.com/numenta/nupic/blob/master/examples/opf/clients/hotgym/anomaly/one_gym/README.md)

---

<div class="post-metadata">

**Author:** ![1113](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/1113/32/3291_2.png) [@1113](https://discourse.numenta.org/u/1113)\
**Post date:** [April 8, 2019, 12:21pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/6 "2019-04-08T12:21:14Z")

</div>

thx for the quick answer. I wonder were I’m missing the right code for this.  
so what I need is one of two:

1. write a script which will run as a process, thus the model will be up always and will receive every defined amount of time new data, and run it into the model to decide if anomaly or not.
2. script which will run on a data of a whole week ( for example ), save the model, and then I will have another script which will run every 2 min to check if the new received data is anomaly, of course using the saved model.

so the hot gym tutorial answers for one of these cases?  
and if so should I look into “run.py” or “nupic\_output.py”

if the tutorial is not matching these cases, should I look into serialization?  
Im a lil bit confused here…

thx for the help:)

arkady

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [April 8, 2019, 12:25pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/7 "2019-04-08T12:25:13Z")

</div>

The hot gym example shows you how to do #1, sure. All you need to do is hold a model instance in memory and call `run()` on it. That will update the model and get a new anomaly value. There is no example in there for saving, but if you don’t mind pickling you can use `model.save()` (the old way).

FYI: The “new way” of serialization works too, but you have to get to the algorithm instances and save them differently (see above).

---

<div class="post-metadata">

**Author:** ![1113](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/1113/32/3291_2.png) [@1113](https://discourse.numenta.org/u/1113)\
**Post date:** [April 8, 2019, 12:29pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/8 "2019-04-08T12:29:49Z")

</div>

great! thank you very much

---

<div class="post-metadata">

**Author:** ![1113](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/1113/32/3291_2.png) [@1113](https://discourse.numenta.org/u/1113)\
**Post date:** [April 30, 2019, 8:29am UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/9 "2019-04-30T08:29:03Z")

</div>

Hi Again,

So i saw you mentioned that for online anomaly detection no swarming is needed, but how should I create a model without any parameters? what do I miss?

Thx in advance

Arkady

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [April 30, 2019, 4:05pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/10 "2019-04-30T16:05:28Z")

</div>

See: [Don't swarm for Anomaly models](https://discourse.numenta.org/t/dont-swarm-for-anomaly-models/915)

---

<div class="post-metadata">

**Author:** ![sheiser1](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/sheiser1/32/766_2.png) [@sheiser1](https://discourse.numenta.org/u/sheiser1)\
**Post date:** [April 30, 2019, 6:05pm UTC](https://discourse.numenta.org/t/how-to-save-a-learned-htm-model/2561/11 "2019-04-30T18:05:57Z")

</div>

> [@1113](#):
>
> how should I create a model without any parameters?

Nupic models can’t be created without corresponding parameter configs. For anomaly detection there’s a specific function that a generates this config, so all anomaly detection config files are nearly the same (except for the field names and their min/max values).

The function is getScalarMetricWithTimeOfDayAnomalyParams(), in nupic.frameworks.opf.common\_models.cluster\_params
