# Error in Mathematica 12, BERT example?

**URL:** <https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175>\
**Category:** Questions\
**Tags:** data-science, mathematica, machine-learning, neural-networks\
**Created:** [December 30, 2019, 5:56pm UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175 "2019-12-30T17:56:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbl](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@dbl](https://community.wolfram.com/u/dbl)\
**Post date:** [December 30, 2019, 5:56pm UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/1 "2019-12-30T17:56:08Z")

</div>

Any idea why I am getting the following error in Mathematica 12 running a BERT example?

```
input = "Hello world! I am here";
embeddings = 

  NetModel["BERT Trained on BookCorpus and English Wikipedia Data"][
   input];

NetChain::invindata3: Data supplied to port "Input" could not be encoded; "Function" encoder did not produce an output that was a n*2 matrix of integers between 1 and 30522.

```

 ![ScreenShot2019-12-29at11.11.44AM.png](https://global.discourse-cdn.com/wolfram/original/3X/7/d/7d30fab33e34fe5df2252f7bb752f44262cc0ccb.png)

---

<div class="post-metadata">

**Author:** ![tuseetab](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@tuseetab](https://community.wolfram.com/u/tuseetab)\
**Post date:** [January 3, 2020, 8:29am UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/2 "2020-01-03T08:29:42Z")

</div>

It works for me, could you please ResourceRemove the ResourceObject and re-download the model?

```
In[1]:= input = "Hello world! I am here";
Dimensions@
 NetModel["BERT Trained on BookCorpus and English Wikipedia Data"][
  input]

Out[2]= {8, 768}

```

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [January 3, 2020, 2:25pm UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/3 "2020-01-03T14:25:47Z")

</div>

Hi Tuseeta,

I have the same problem. I tried

```
ResourceRemove[
 ResourceObject[
  "BERT Trained on BookCorpus and English Wikipedia Data"]]

```

Quit the kernel

```
input = "Hello world! I am here";
net = NetModel["BERT Trained on BookCorpus and English Wikipedia Data"]
net[input]

```

> NetChain::invindata3: Data supplied to port “Input” could not be  
> encoded; “Function” encoder did not produce an output that was a n\*2  
> matrix of integers between 1 and 30522.

Other examples from the documentation also do not work as expected e.g.

```
net = NetModel[{"BERT Trained on BookCorpus and English Wikipedia Data", "InputType" -> "ListOfStrings"}];
netencoder = NetExtract[net, "Input"]
netencoder[{"Hello world!", "I am here"}]

```

Result is

```
Developer`NumericArrayQ[{{{102, 1}, {7593, 1}, {2089, 1}, {1000, 1}, {103, 1}, {1046, 2}, {2573, 2}, {2183, 2}, {103, 2}}}]

```

The result should be

```
{{102, 1}, {7593, 1}, {2089, 1}, {1000, 1}, {103, 1}, {1046, 2}, {2573, 2}, {2183, 2}, {103, 2}}

```

I am running

```
$Version
(* 12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019) *)

```

Any suggestions?

Thanks, Rohit

---

<div class="post-metadata">

**Author:** ![tuseetab](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@tuseetab](https://community.wolfram.com/u/tuseetab)\
**Post date:** [January 3, 2020, 3:26pm UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/4 "2020-01-03T15:26:23Z")

</div>

Can you try this?  
PacletUpdate[“NeuralNetworks”]  
Quit and retry?

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [January 4, 2020, 1:57am UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/5 "2020-01-04T01:57:24Z")

</div>

Hi Tuseeta,

I tried your suggestion, it did not solve the problem. Same error message.

---

<div class="post-metadata">

**Author:** ![whaeffner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/whaeffner/32/26870_2.png) [@whaeffner](https://community.wolfram.com/u/whaeffner)\
**Post date:** [January 4, 2020, 5:03pm UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/6 "2020-01-04T17:03:55Z")

</div>

Hi,

I just checked an example from above using Mathematica 12 / Win 10 64bit. While running the code example the first time Mathematica automatically executed updates and eventually produced the result as expected by Rohit. See the notebook attached.

Regards

Walter

[Test\_Example .nb](https://community.wolfram.com/uploads/short-url/ndudpLUzhyTFWzOLlMIW2DxKXOc.nb) (10.5 KB)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [January 9, 2020, 7:34pm UTC](https://community.wolfram.com/t/error-in-mathematica-12-bert-example/15175/7 "2020-01-09T19:34:25Z")

</div>

Hi Tuseeta,

Do you have any other suggestions to try and fix this problem?

BTW it works fine on 12.1 prerelease version 12.1.0 for Mac OS X x86 (64-bit) (December 21, 2019)

Thanks, Rohit
