# Training Rasa using Rasa NLU

**URL:** <https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633>\
**Category:** Rasa Open Source\
**Created:** [October 21, 2021, 4:07am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633 "2021-10-21T04:07:33Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasauser1](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@Rasauser1](https://forum.rasa.com/u/Rasauser1)\
**Post date:** [October 21, 2021, 4:07am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/1 "2021-10-21T04:07:33Z")

</div>

I’m following the code sample here to train the model via python. [http://35.196.60.7/docs/nlu/0.15.1/python/](http://35.196.60.7/docs/nlu/0.15.1/python/)

```auto

from rasa_nlu.training_data import load_data
from rasa_nlu.model import Trainer
from rasa_nlu import config

training_data = load_data('data/examples/rasa/demo-rasa.json')
trainer = Trainer(config.load("sample_configs/config_pretrained_embeddings_spacy.yml"))
trainer.train(training_data)
model_directory = trainer.persist('./projects/default/') # Returns the directory the model is stored in

```

Now I have 2 issues.

1. my training data isn’t in json format it is in yml format like so

> version: “2.0”
> 
> nlu:
> 
> - intent: greet examples: |
> - hey
> - hello
> - hi
> - hello there
> - good morning
> - good evening
> - moin
> - hey there
> - let’s go
> - hey dude
> - goodmorning
> - goodevening
> - good afternoon

How do I use yml file to load the training data. I get this error when I try to load a yaml file. ValueError: Unknown data format for file

1. `config.load("sample_configs/config_pretrained_embeddings_spacy.yml")` throws this error

```auto
    return yaml.load(read_file(filename, "utf-8"))
TypeError: load() missing 1 required positional argument: 'Loader'

```

---

<div class="post-metadata">

**Author:** ![koaning](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/koaning/32/6626_2.png) [@koaning](https://forum.rasa.com/u/koaning)\
**Post date:** [October 27, 2021, 11:40am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/2 "2021-10-27T11:40:33Z")

</div>

I fear that you’re referring to a rather old `0.x` version of Rasa that isn’t supported anymore. In modern versions of Rasa the training is triggered from the command line via;

```auto
rasa train

```

Is there a reason why you’re using such an old version?

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 2, 2021, 8:33am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/3 "2021-11-02T08:33:49Z")

</div>

what if we want to write our own endpoints for training NLU and CORE separately?

---

<div class="post-metadata">

**Author:** ![koaning](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/koaning/32/6626_2.png) [@koaning](https://forum.rasa.com/u/koaning)\
**Post date:** [November 2, 2021, 10:14am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/4 "2021-11-02T10:14:52Z")

</div>

Technically, they are trained seperately in 2.x. You can confirm by running:

```auto
rasa train --help
usage: rasa train [-h] [-v] [-vv] [--quiet] [--data DATA [DATA ...]]
                  [-c CONFIG] [-d DOMAIN] [--out OUT] [--dry-run]
                  [--augmentation AUGMENTATION] [--debug-plots]
                  [--num-threads NUM_THREADS]
                  [--fixed-model-name FIXED_MODEL_NAME] [--persist-nlu-data]
                  [--force] [--finetune [FINETUNE]]
                  [--epoch-fraction EPOCH_FRACTION]
                  {core,nlu} ...

positional arguments:
  {core,nlu}
    core Trains a Rasa Core model using your stories.
    nlu Trains a Rasa NLU model using your NLU data.

```

That means that you can run:

```auto
rasa train nlu

```

To only run the NLU part of the pipeline. Or, if you only want the core policies:

```auto
rasa train core

```

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 2, 2021, 10:25am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/5 "2021-11-02T10:25:16Z")

</div>

Actually I want to write my own server using FastAPI, for that, I need the actual code. I do not want to start the Rasa server. So i think above commands will only work in I run the Rasa HTTPI API.

---

<div class="post-metadata">

**Author:** ![koaning](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/koaning/32/6626_2.png) [@koaning](https://forum.rasa.com/u/koaning)\
**Post date:** [November 2, 2021, 10:35am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/6 "2021-11-02T10:35:57Z")

</div>

While you could write a lot of code to wrap around our NLU objects, you can also run Rasa as a service via;

```auto
rasa run --enable-api

```

I even wrote a blog post that explains the details on how to use Rasa’s NLU pipeline as a general NLU service in Docker.

> **[Custom Rasa NLU Docker Containers](https://rasa.com/blog/custom-rasa-nlu-docker-container/)**
>
> The main use-case for Rasa NLU pipelines is to construct virtual assistants. That said, the intents and entities that Rasa can predict are based on domain knowledge that can also be reused across an organisation.

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 2, 2021, 10:46am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/7 "2021-11-02T10:46:41Z")

</div>

**rasa run** will open all the endpoints, my custom api will only have training endpoint that will train the models along with other custom endpoints. I have seen the blog post, it also train models using rasa train, which is not what i required.

What I am doing is, I have installed Rasa 2.8.8 and imported **train** from **rasa.api** and trying to train by giving paths. It did train for the first time but after that it is giving me this error `RuntimeError: This event loop is already running`

Below is the code to train the models.

```auto
from rasa.api import train

domain = 'sample_bot/domain.yml'
config = 'sample_bot/config.yml'
training_files = 'sample_bot/data'
output='sample_bot/models'
fixed_model_name= 'self_model'
dry_run = False
force_training = True

train(
        domain=domain,
        config=config,
        training_files=training_files,
        output=output,
        dry_run=False,
        force_training=True,
        fixed_model_name=fixed_model_name,
    )

```

---

<div class="post-metadata">

**Author:** ![koaning](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/koaning/32/6626_2.png) [@koaning](https://forum.rasa.com/u/koaning)\
**Post date:** [November 2, 2021, 10:52am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/8 "2021-11-02T10:52:21Z")

</div>

Just to double-check, are you running that from a python script or from Jupyter?

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 2, 2021, 10:52am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/9 "2021-11-02T10:52:49Z")

</div>

Yes 😕

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 2, 2021, 11:01am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/10 "2021-11-02T11:01:20Z")

</div>

Its Jupyter

---

<div class="post-metadata">

**Author:** ![koaning](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/koaning/32/6626_2.png) [@koaning](https://forum.rasa.com/u/koaning)\
**Post date:** [November 2, 2021, 1:58pm UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/11 "2021-11-02T13:58:00Z")

</div>

Could you try running it in a normal python script? If memory serves, Jupyter is running in an async loop via Tornado which might be confusing the async code inside of Rasa.

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 3, 2021, 7:58am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/12 "2021-11-03T07:58:00Z")

</div>

Working perfectly fine in a normal python script. Thanks.

Any workaround for Jupyter?

---

<div class="post-metadata">

**Author:** ![koaning](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/koaning/32/6626_2.png) [@koaning](https://forum.rasa.com/u/koaning)\
**Post date:** [November 3, 2021, 10:26am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/13 "2021-11-03T10:26:56Z")

</div>

Not without getting hacky as far as I know.

---

<div class="post-metadata">

**Author:** ![noman](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noman/32/10071_2.png) [@noman](https://forum.rasa.com/u/noman)\
**Post date:** [November 3, 2021, 11:42am UTC](https://forum.rasa.com/t/training-rasa-using-rasa-nlu/48633/14 "2021-11-03T11:42:55Z")

</div>

ok. Thanks. You helped me solve the issue 🙂
