# BERT Model - OSError

**URL:** <https://discuss.huggingface.co/t/bert-model-oserror/15375>\
**Category:** Beginners\
**Created:** [March 5, 2022, 12:31am UTC](https://discuss.huggingface.co/t/bert-model-oserror/15375 "2022-03-05T00:31:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asseged](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@Asseged](https://discuss.huggingface.co/u/Asseged)\
**Post date:** [March 5, 2022, 12:31am UTC](https://discuss.huggingface.co/t/bert-model-oserror/15375/1 "2022-03-05T00:31:12Z")

</div>

When running this BERT Model , it outputs OSError. the following is the model “nlptown/bert-base-multilingual-uncased-sentiment” ,

looking at the 2 recommended solutions, not 100 % positive if they both apply. For the second recommended solution, the file i see missing is “model.ckpt” from the uploaded model in huggingface, but not sure if that matters.

Below is the Code and Error Message,

```auto
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import requests
from bs4 import BeautifulSoup
import re

## Instantiate Model
# the nlp bert pre-trained model used here is from website huggingface. the website is " https://huggingface.co/nlptown/bert-base-multilingual-uncased-sentiment "

tokenizer = AutoTokenizer.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')  
model = AutoModelForSequenceClassification.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')

## Encode and Calculate Sentiment ( Now entering string words to test the sentiment score )

tokens = tokenizer.encode('I hated this, absolutely the worst', return_tensors='pt' )
result = model(tokens)

print(result)

```

Error Message Below,  
" OSError: Can’t load the model for ‘nlptown/bert-base-multilingual-uncased-sentiment’. If you were trying to load it from ‘[Models - Hugging Face](https://huggingface.co/models)’, make sure you don’t have a local directory with the same name. Otherwise, make sure ‘nlptown/bert-base-multilingual-uncased-sentiment’ is the correct path to a directory containing a file named pytorch\_model.bin, tf\_model.h5, model.ckpt or flax\_model.msgpack. "

---

<div class="post-metadata">

**Author:** ![Koushik2179](https://avatars.discourse-cdn.com/v4/letter/k/cab0a1/32.png) [@Koushik2179](https://discuss.huggingface.co/u/Koushik2179)\
**Post date:** [February 26, 2023, 8:22pm UTC](https://discuss.huggingface.co/t/bert-model-oserror/15375/2 "2023-02-26T20:22:58Z")

</div>

Any solution found for this issue? I am also facing same issue.

---

<div class="post-metadata">

**Author:** ![joaogante](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/joaogante/32/20106_2.png) [@joaogante](https://discuss.huggingface.co/u/joaogante)\
**Post date:** [March 1, 2023, 5:01pm UTC](https://discuss.huggingface.co/t/bert-model-oserror/15375/3 "2023-03-01T17:01:13Z")

</div>

Hey folks 👋

I can’t reproduce the issue you described (see [this colab](https://colab.research.google.com/drive/1T9g3i5V6C395vyq7Rx-82FuWbdlrpuYi?usp=sharing)).

My suggestions include:

1. Make sure you don’t have a local folder with the same name
2. Create a fresh python environment and install a recent version of `transformers`

---

<div class="post-metadata">

**Author:** ![mojeime2](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@mojeime2](https://discuss.huggingface.co/u/mojeime2)\
**Post date:** [December 6, 2024, 12:37pm UTC](https://discuss.huggingface.co/t/bert-model-oserror/15375/4 "2024-12-06T12:37:57Z")

</div>

I was having a similar error and managed to fix it by adding `if __name__ == " __main__":` at the start of my code. If your error is the same as mine, you should see

```auto
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == ' __main__':
                freeze_support()

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

```

further above in your stacktrace. Not having `if __name__ == " __main__":` causes a problem with how child processes are created as each child process runs the code for importing the model causing an infinite loop. This also explains why @joaogante could not reproduce the issue in a jupyter notebook.

Hope this helps someone in the future.
