# RASA and camemBERT

**URL:** <https://forum.rasa.com/t/rasa-and-camembert/31882>\
**Category:** Rasa Open Source\
**Created:** [July 27, 2020, 3:05pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882 "2020-07-27T15:05:16Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zoukero](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zoukero/32/15155_2.png) [@Zoukero](https://forum.rasa.com/u/Zoukero)\
**Post date:** [July 27, 2020, 3:05pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/1 "2020-07-27T15:05:17Z")

</div>

Hi everyone ! I wanted to know if there was a way to implement the french version of BERT (camembert). It seems how were implemented the other bert version (rasa.nlu.utils.hugging\_face) and wanted to know if anyone tried to play with these files to add a version of BERT !

Thank you very much !

---

<div class="post-metadata">

**Author:** ![MingGuangShao](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mingguangshao/32/10173_2.png) [@MingGuangShao](https://forum.rasa.com/u/MingGuangShao)\
**Post date:** [July 27, 2020, 3:51pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/2 "2020-07-27T15:51:26Z")

</div>

Why not use your own nlu service to provide http ports？

You can use rasa core alone and use your nlu service to parse text.

---

<div class="post-metadata">

**Author:** ![Zoukero](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zoukero/32/15155_2.png) [@Zoukero](https://forum.rasa.com/u/Zoukero)\
**Post date:** [July 28, 2020, 7:57am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/3 "2020-07-28T07:57:57Z")

</div>

Thanks for your answer ! I wanted to beneficiate from the train process of rasa 🙂

---

<div class="post-metadata">

**Author:** ![Zoukero](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zoukero/32/15155_2.png) [@Zoukero](https://forum.rasa.com/u/Zoukero)\
**Post date:** [July 28, 2020, 4:04pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/4 "2020-07-28T16:04:33Z")

</div>

Solved ! I heard there was some tries on camemBERT [here](https://github.com/RasaHQ/rasa/issues/5365#issuecomment-596427977) and looked for these traces

There is no need to modify the rasa[transformers] modules from the pip installations, only rasa source code

1. Monkeypatch the dictionary from the modeling\_tf\_camembert to provide the link to the camemBERT model : add the following lines at the beggining of the hf\_transformers.py file (rasa/nlu/utils/hugging\_face)

> from transformers import modeling\_tf\_camembert modeling\_tf\_camembert.TF\_CAMEMBERT\_PRETRAINED\_MODEL\_ARCHIVE\_MAP[“camembert-base”]=“[https://s3.amazonaws.com/models.huggingface.co/bert/jplu/tf-camembert-base/tf\_model.h5](https://s3.amazonaws.com/models.huggingface.co/bert/jplu/tf-camembert-base/tf_model.h5)”

1. Add camemBERT to the registry.py file (path : rasa/nlu/utils/hugging\_face/registry.py). Here is an example : [registry.py](https://forum.rasa.com/uploads/short-url/dr7nKUpnI5BWht06hP8whMpHwo4.py) (3.0 KB)

2. config.py file :

pipeline:

- name: HFTransformersNLP model\_name: “camembert” model\_weights: “camembert-base” cache\_dir: “data/cache\_membert”
- name: “LanguageModelTokenizer”
- name: “LanguageModelFeaturizer”
- name: “DIETClassifier”

---

<div class="post-metadata">

**Author:** ![kasar3](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kasar3/32/10800_2.png) [@kasar3](https://forum.rasa.com/u/kasar3)\
**Post date:** [August 10, 2020, 1:01pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/5 "2020-08-10T13:01:39Z")

</div>

Hi,

I am actually working with CamemBERT and was wondering if you had succeeded in creating a french chatbot based on this model? If you did, are the results good?

Thx.

---

<div class="post-metadata">

**Author:** ![Zoukero](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zoukero/32/15155_2.png) [@Zoukero](https://forum.rasa.com/u/Zoukero)\
**Post date:** [August 10, 2020, 3:04pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/6 "2020-08-10T15:04:30Z")

</div>

Hi !

It is still in development but the results are better than I expected. The NLU I used consists of 27 intents for an average of around 10 examples per intent

When the inputs were really close to an example given in the nlu.md file, the model always predicted the good intent with a confidence close to 1. Moreover, when a word is not specified in your NLU but semantically close to a word you specified, the model often predicted the good intent with a lower confidence (around 0.50) ; but it can make a mistake between two close intents (what\_time\_is\_it / what\_day\_is\_it)

I hope it helps !

---

<div class="post-metadata">

**Author:** ![kasar3](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kasar3/32/10800_2.png) [@kasar3](https://forum.rasa.com/u/kasar3)\
**Post date:** [August 11, 2020, 7:37am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/7 "2020-08-11T07:37:12Z")

</div>

Sounds cool I’ll try to do my own chatbot too, thank you very much! 🙂

---

<div class="post-metadata">

**Author:** ![MaxGdr](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/maxgdr/32/10748_2.png) [@MaxGdr](https://forum.rasa.com/u/MaxGdr)\
**Post date:** [August 28, 2020, 8:11am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/8 "2020-08-28T08:11:05Z")

</div>

> [@Zoukero](#):
>
> (what\_time\_is\_it / what\_day\_is\_it

Maybe you should create an intent “What is it”, and switch by entities your response for time, day, or another thing… 😉

Your two intentions are very close 🙂

---

<div class="post-metadata">

**Author:** ![kasar3](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kasar3/32/10800_2.png) [@kasar3](https://forum.rasa.com/u/kasar3)\
**Post date:** [September 1, 2020, 3:16pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/9 "2020-09-01T15:16:11Z")

</div>

I’m back on that CamemBERT thing.

So I tried to do my own bot but can’t do anything when I’m trying to use CamemBERT model. I do follow what you said but when I try to train I got errors:

> File “\_ruamel\_yaml.pyx”, line 706, in \_ruamel\_yaml.CParser.get\_single\_node  
> File “\_ruamel\_yaml.pyx”, line 724, in \_ruamel\_yaml.CParser.\_compose\_document  
> File “\_ruamel\_yaml.pyx”, line 775, in \_ruamel\_yaml.CParser.\_compose\_node  
> File “\_ruamel\_yaml.pyx”, line 891, in \_ruamel\_yaml.CParser.\_compose\_mapping\_node  
> File “\_ruamel\_yaml.pyx”, line 904, in \_ruamel\_yaml.CParser.\_parse\_next\_event  
> ruamel.yaml.parser.ParserError: while parsing a block mapping  
> in “”, line 3, column 1  
> did not find expected key  
> in “”, line 8, column 1

I don’t understand what is wrong. Are you sure the followin line is working?

> modeling\_tf\_camembert.TF\_CAMEMBERT\_PRETRAINED\_MODEL\_ARCHIVE\_MAP[“camembert-base”]=…

Cause when I try it on Colab it doesn’t.

I’d love to use the french model for a bot, could you help me? Thx

---

<div class="post-metadata">

**Author:** ![kasar3](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kasar3/32/10800_2.png) [@kasar3](https://forum.rasa.com/u/kasar3)\
**Post date:** [September 3, 2020, 9:08am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/10 "2020-09-03T09:08:59Z")

</div>

Solved !!!

Finally I managed to load the model following your instructions.

To be more precise:

1. The first step is working well

2. in the registry.py, there is a sneaky `TFCamembertModel,` that I didn’t see and needed to add it

3. Indentation of the config file must be perfect (tricky error…) :

```auto
language: fr  
pipeline: 
    - name: HFTransformersNLP  
      model_name: "camembert"  
      model_weights: "camembert-base"  
      cache_dir: "data/cache_membert"
    - name: "LanguageModelTokenizer"  
    - name: "LanguageModelFeaturizer"  
    - name: "DIETClassifier"  
      epochs: 200  

```

Hope it will help and thanks again to @Zoukero

---

<div class="post-metadata">

**Author:** ![MaxGdr](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/maxgdr/32/10748_2.png) [@MaxGdr](https://forum.rasa.com/u/MaxGdr)\
**Post date:** [September 10, 2020, 7:26am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/11 "2020-09-10T07:26:08Z")

</div>

Thanks to share that u success to use it ! 😃

---

<div class="post-metadata">

**Author:** ![AminaDerouiche](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@AminaDerouiche](https://forum.rasa.com/u/AminaDerouiche)\
**Post date:** [May 17, 2021, 3:03pm UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/12 "2021-05-17T15:03:57Z")

</div>

I want to use camemBERT but I have some issue, I did apply this solution unfortunately it is out dated I guess did anyone used camemBERT recently ?

---

<div class="post-metadata">

**Author:** ![zack](https://avatars.discourse-cdn.com/v4/letter/z/f6c823/32.png) [@zack](https://forum.rasa.com/u/zack)\
**Post date:** [May 19, 2021, 10:59am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/13 "2021-05-19T10:59:42Z")

</div>

downgrade Transformers library, I guess it should be some version around 2.5.X

---

<div class="post-metadata">

**Author:** ![AminaDerouiche](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@AminaDerouiche](https://forum.rasa.com/u/AminaDerouiche)\
**Post date:** [May 20, 2021, 7:41am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/14 "2021-05-20T07:41:20Z")

</div>

I downgraded the transformers library and it worked

I did this `pip install --upgrade transformers==2.5.0`

thanks @zack for you answer 🙂

---

<div class="post-metadata">

**Author:** ![khatba](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/khatba/32/13847_2.png) [@khatba](https://forum.rasa.com/u/khatba)\
**Post date:** [June 8, 2021, 9:47am UTC](https://forum.rasa.com/t/rasa-and-camembert/31882/16 "2021-06-08T09:47:12Z")

</div>

It worked ! but additionally to the steps described above I had to add camembert to the dict MAX\_SEQUENCE\_LENGTHS in rasa/nlu/utils/hugging\_face.py

MAX\_SEQUENCE\_LENGTHS = { “camembert”: 512, “bert”: 512, “gpt”: 512, “gpt2”: 512, “xlnet”: NO\_LENGTH\_RESTRICTION, “distilbert”: 512, “roberta”: 512, }
