# Multiclass inference with TMVA SOFIE

**URL:** <https://root-forum.cern.ch/t/multiclass-inference-with-tmva-sofie/60562>\
**Category:** TMVA\
**Tags:** rdataframe, python\
**Created:** [August 22, 2024, 9:02am UTC](https://root-forum.cern.ch/t/multiclass-inference-with-tmva-sofie/60562 "2024-08-22T09:02:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scella](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/977dab/32.png) [@scella](https://root-forum.cern.ch/u/scella)\
**Post date:** [August 22, 2024, 9:02am UTC](https://root-forum.cern.ch/t/multiclass-inference-with-tmva-sofie/60562/1 "2024-08-22T09:02:48Z")

</div>

Dear experts,

I’m trying to use TMVA SOFIE to make inference starting from a keras (.h5) model.  
My model is a multiclass DNN, and the output that I expect from the inference is a vector of dimension N for each event, where N is the number of classes. What I get when I call sofie\_functor is a single number, that I think, looking at the line of the code TMVA/SOFIEHelpers.hxx#L49 is the first element of the vector. Is there a way to get all the numbers, or am I missing something here? Thanks a lot.

Technical details:  
I’m using ROOT version 6.28, and TMVA SOFIE with python and RDataFrame.  
To write the code I followed the tutorial root.cern/doc/master/TMVA\_\_SOFIE\_\_RDataFrame\_8py.html without any relevant modifications.

Let me know if you need any additional information.  
Thanks a lot,  
Sofia

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 23, 2024, 7:01am UTC](https://root-forum.cern.ch/t/multiclass-inference-with-tmva-sofie/60562/2 "2024-08-23T07:01:17Z")

</div>

Hi Sofia,

Thanks for reaching out and welcome to the ROOT Community!

Let me add in the loop @moneta , who will be able to address this inquiry.

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [August 23, 2024, 9:32am UTC](https://root-forum.cern.ch/t/multiclass-inference-with-tmva-sofie/60562/3 "2024-08-23T09:32:49Z")

</div>

Hello,

It is correct the corrent SOFIR functor implemented in TMVA/SOFIEHelper.hxx returns a single value. If you have a multiclass model and you need to return a vector of values, you can easly change it to return an std::vector by changing the signature of the `operator()`, function as following:

```auto
std::vector<T> operator()(unsigned slot, AlwaysT<N>... args) {
      fInput[slot] = {args...};
      auto y = fSessions[slot].infer(fInput[slot].data());
      return y;
   }

```

Please let me know if you have any issue using this modifies functor.

Best regards

Lorenzo

---

<div class="post-metadata">

**Author:** ![scella](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/977dab/32.png) [@scella](https://root-forum.cern.ch/u/scella)\
**Post date:** [August 28, 2024, 3:34pm UTC](https://root-forum.cern.ch/t/multiclass-inference-with-tmva-sofie/60562/4 "2024-08-28T15:34:17Z")

</div>

Hi,  
it works, thank you!  
Best regards,  
Sofia
