# How To score a model built using BERT?

**URL:** <https://community.wolfram.com/t/how-to-score-a-model-built-using-bert/19985>\
**Category:** Questions\
**Tags:** data-science, external-interfaces, neural-networks\
**Created:** [April 29, 2022, 7:12pm UTC](https://community.wolfram.com/t/how-to-score-a-model-built-using-bert/19985 "2022-04-29T19:12:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalilaben](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@dalilaben](https://community.wolfram.com/u/dalilaben)\
**Post date:** [April 29, 2022, 7:12pm UTC](https://community.wolfram.com/t/how-to-score-a-model-built-using-bert/19985/1 "2022-04-29T19:12:14Z")

</div>

I’ve been trying to use your example using BERT for tweets classification (simple Kaggle dataset)

```
trainembeddings = NetModel["BERT Trained on BookCorpus and English Wikipedia Data"][
    forBERT[[All, 1]], TargetDevice -> "CPU"] -> forBERT[[All, 2]];

classifierhead = NetChain[{DropoutLayer[], NetMapOperator[2], 
                                       AggregationLayer[Max, 1], SoftmaxLayer[]}, 
                                      "Output" -> NetDecoder[{"Class", {"negative", "positive"}}]]
bertresults = NetTrain[classifierhead, trainembeddings, All, TargetDevice -> "CPU",
   MaxTrainingRounds -> 50]

```

But, after I build the model, I’ve no idea how to score with new tweets, and I cannot see how to do it in your [example](https://resources.wolframcloud.com/NeuralNetRepository/resources/BERT-Trained-on-BookCorpus-and-Wikipedia-Data/).

---

<div class="post-metadata">

**Author:** ![jeromel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jeromel/32/30614_2.png) [@jeromel](https://community.wolfram.com/u/jeromel)\
**Post date:** [April 30, 2022, 9:21am UTC](https://community.wolfram.com/t/how-to-score-a-model-built-using-bert/19985/2 "2022-04-30T09:21:29Z")

</div>

It’s true that the example in section “Train a classifier model with the subword embeddings” should be completed to show how to “reconstruct” the full classifier and apply it.

The part that is missing for you is the following:

Extract the trained classifier:

```auto
trainedhead = bertresults["TrainedNet"]

```

![Screenshotfrom2022-04-3011-17-15_1.png](https://global.discourse-cdn.com/wolfram/original/2X/b/b661c37ac950fae21112534a2addd963ffae04d6.png)

Join it with BERT embeddings:

```auto
bertclassifier = NetJoin[
   NetModel["BERT Trained on BookCorpus and Wikipedia Data"], 
   trainedhead]

```

![Screenshotfrom2022-04-3011-17-15_2.png](https://global.discourse-cdn.com/wolfram/original/3X/1/d/1d67a4049f8811fe0436a096eb3709fbc7cf52d3.png)

Apply it to some text:

```auto
bertclassifier["I liked it"]

Out[9]= "positive"

bertclassifier["I hated it", "Probabilities"]

Out[10]= <|"negative" -> 0.979603, "positive" -> 0.0203966|>

```

---

<div class="post-metadata">

**Author:** ![dalilaben](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@dalilaben](https://community.wolfram.com/u/dalilaben)\
**Post date:** [April 30, 2022, 7:04pm UTC](https://community.wolfram.com/t/how-to-score-a-model-built-using-bert/19985/3 "2022-04-30T19:04:27Z")

</div>

Thank You for the prompt Response.

---

<div class="post-metadata">

**Author:** ![dalilaben](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@dalilaben](https://community.wolfram.com/u/dalilaben)\
**Post date:** [April 30, 2022, 11:15pm UTC](https://community.wolfram.com/t/how-to-score-a-model-built-using-bert/19985/4 "2022-04-30T23:15:49Z")

</div>

How To score a model built using BERT?
