<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Eficient fine-tuning of SlovakBERT with Epinet</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Jozef Kubík</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Daniel Kyselica</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Martin Takáč</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Faculty of Mathematics</institution>
          ,
          <addr-line>Physics and Informatics</addr-line>
          ,
          <institution>Comenius University</institution>
          ,
          <addr-line>Bratislava</addr-line>
          ,
          <country country="SK">Slovakia</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>The popularity of creating artificial intelligence models has been incredibly rising. These tools can be used in many diferent areas, including text analysis. Most modern models ofer great accuracy in many diferent text-based tasks but are limited by a huge number of data required to not only pre-train but also fine-tune these models. This problem only deepens in models trained on data from low and mid-resource languages, such as Slovak. In this paper, we examined the fine-tuning process of such models and tried to enhance it by connecting to Epinet to create Epistemic neural network, a relatively new concept that helps the model to detect its own uncertainty to make better decisions in the long run.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>2. Networks details</title>
      <sec id="sec-2-1">
        <title>2.1. SlovakBERT</title>
        <p>
          SlovakBERT is the first monolingual Large language
model (LLM) trained on Slovak text data. It was
introduced in the year 2021, although many diferent
BERTline of models were known for a longer period of time.
As it is in fact RoBERTa model, its strength comes from
the clever design of Transformer architecture [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ], more
concretely its encoder part. The attention mechanism
used in this architecture not only provides great means
of text understanding but also allows for partial process
parallelization, accelerating the training process. The
training process, which can be divided into pre-training
and fine-tuning parts, allows for flexibility not only in a
variety of possible tasks but also in the language of input
data. The size of these models, measured in hundreds
of millions of parameters, was higher when compared
to older architectures, but is a little compared to other
models, such as GPT [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ] models with the number of
parameters counting in hundreds of billions. Although the
size of data used for pre-training seems reasonably big
(almost 20GB), it is little compared to the original RoBERTa
(160GB), which is the base architecture for this model.
        </p>
      </sec>
      <sec id="sec-2-2">
        <title>2.2. Epistemic neural network</title>
        <p>Epistemic neural network (ENN) difers from the
traditional network by taking additional input called epistemic
index. This index, usually sampled by some reference
distribution such as normal distribution or a finite set of
values, is used to help the model recognize its own
epistemic uncertainty. This uncertainty is easier to show in
the joint probability distribution, where multiple samples
(inputs to the network) are considered.
are the same - 0.5. This shows the model’s uncertainty
for the prediction, but the reason for this uncertainty
is not clear. If we took the text sequence and put it as
an input for the neural network a second time, we can
model joint probability distribution by the table of size
2x2. In this case, we can get two diferent edge cases (the
tables on the right). In the upper table, all possible
combinations of classes when given two input samples show
the same probability of 0.25. Summing up for marginal
prediction, for each sample network assigns a probability
of 0.5. This case suggests aleatoric uncertainty which
most probably won’t be solved with future training. The
more interesting case is shown in the table at the bottom
right. Here, the networks’ choice is always consistent
when the class for the first sample is chosen, the same
class is assigned for the same sample for the second time.
The only problem is that the network is not sure which
class to assign in the first place. The sum of the marginal
predictions is, as in the first case, 0.5, but the diference
in distribution is visible. This second example suggests
epistemic uncertainty, i.e. more training could resolve
models’ uncertainty.</p>
        <p>The epistemic index comes as an additional input to
ENN to help with epistemic uncertainty. In figure 2, we
see two diferent use cases. In the first case, ENN doesn’t
use the epistemic index to its benefit and thus indicates
ambiguous data. The possible use of the epistemic index
is shown in the tables below it. Here, according to the
sign of epistemic index, the class is chosen - that holds
true not only for prediction of one input but also when
the same input is given two times in a row. If a prediction
of the network can be manipulated in this way by some
additional input, then we can assume that future training
will resolve some of its uncertainty.</p>
        <sec id="sec-2-2-1">
          <title>In figure 1, for the text classification task, the conven</title>
          <p>
            tional neural network takes as an input a text sequence
and outputs a vector containing probability distribution
for 2 classes - positive or negative sentiment. In an edge
case (the table in the middle), the probabilities assigned
One concrete use of ENN was introduced with the
Epinet [
            <xref ref-type="bibr" rid="ref6">6</xref>
            ] network. Visualized in figure 3, Epinet
consists of two networks: learnable and prior. Both of the
networks use the aforementioned epistemic index.
          </p>
          <p>In most cases, these networks are standard Multi-layer
perceptrons with the same architecture but diferent
starting parameters. The prior network has no trainable
parameters and aims to introduce initial knowledge about
uncertainty. Over time, learnable networks’ parameters
are updated, whereas prior networks’ parameters stay
the same. Both of these networks take two inputs:
epistemic index  and so-called features ˜ of the base
network. These features are usually the last layers or (parts
of them) of the base network, which we are trying to
train. These two inputs are concatenated and fed into
the learnable and prior network, which results are then
summed. The final result of ENN  is the sum of the
Epinet networks  result and result of the base network
 :
 (˜, ) =   (˜, ) +  (˜, )</p>
          <p>(, ) =  () +  (˜, )</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Experiments</title>
      <p>In our experiments, we use the base version of the
pretrained SlovakBERT network. On top of it, we add a
Multi-layered perceptron (MLP) with one hidden layer of
size 50. When connecting to Epinet to create an Epistemic
neural network, the result of the SlovakBERT network
present in the representation of [CLS] token at the last
layer is used as the input to this MLP network and also
as ’features’ for the Epinet.</p>
      <p>
        In Epinet, we follow the original implementation in
[
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. We use two MLP networks - the learnable one is
initialized with parameters via Glorot initialization [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]
and takes arguments, which are concatenated together:
 (˜, ) =   (  (˜, ))
      </p>
      <p>The prior network has no trainable parameters. Its
design is the same as for the learnable network:
  (˜, ) =   (  (˜, ))</p>
      <p>Both of these networks are the same in size as the MLP
network connected to the SlovakBERT. The epistemic
index is sampled from a uniform distribution.</p>
      <p>For the size of epistemic indices, we iterate through
multiple possible values. In our experiments, we try to
sample this vector with sizes 10, 30, 50, and 100. The
number of indices sampled in each stochastic gradient
descent step is always 5. With each size we fine-tune
the model from scratch, giving us the best setting for a
reasonable comparison.</p>
      <p>
        For optimization we use Adam [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] optimizer with
starting learning rate  = 5 · 10− 5.
      </p>
      <p>We fine-tune our model for sentiment analysis
classiifcation task on CSFD [ 11] dataset, a publicly available
collection of movie reviews. For this, we preprocess the
dataset in two ways:
• we keep only two data features: text review and
rating
• as the rating column contains values ranging
from 0 to 6, we edit these values to get sentiment
analysis task of 3 possible classes: 0 - negative, 1
- neutral, and 2 - positive. We do this by mapping
original values to predefined classes - values 0
and 1 are mapped to 1, values 2 and 3 are mapped
to 1, and values 4 and 5 are mapped to 2.</p>
      <p>
        No other changes to the text data itself were made. We
ifne-tune the model for 5 epochs on 25k train data and
validate the model after every epoch on 5k validation
data. The loss function used is the standard cross-entropy
function. For determining joint logarithmic loss value
during validation we use the vanilla version of the dyadic
sampling heuristic as described in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. In this method, we
ifrst sample  independent random samples. After that,
we sample another  −  samples with equal probability
from these two points to create a batch of size  which
we use for calculating joint loss. This heuristic is a good
alternative to classic calculation as in high-dimensional
space the size of the batch required to distinguish joint
prediction would be too large to compute in a reasonable
time.
      </p>
      <p>We recognize that other settings could be potentially
better suited for our experiments, but this exact
preprocessing allowed us to easily train the model while keeping
reasonable values for the potential sentiment in the text.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Results</title>
      <p>In this section, we present the results of our experiments.</p>
      <p>To easily recognize the networks, we will always refer
to SlovakBERT connected to only standard MLP as ’base
SlovakBERT’ and SlovakBERT connected not only to
standard MLP but also to Epinet network as ’SlovakBERT
Epinet’ or simply ’Epinet’. Each diferent SlovakBERT
Epinet will also contain in its name the size of the epis- not find any significant change in accuracy while using
temic index used. Epinet. Although it is logical as in the case of training</p>
      <p>Training accuracy nor training loss did not improve accuracy, longer training could still potentially reveal the
significantly when using SlovakBERT Epinet. The result- problem with under-training. On our small dataset, no
ing values did not difer in a major way, which holds major changes were discovered, though.
not only when comparing to base SlovakBERT, but also
diferent index size parameters of SlovakBERT Epinet.</p>
      <p>
        As calculated training loss is in its nature marginal (each
sample is independent), it seems logical that no major
improvements are observed. Results can be seen in
figure 4 and 5. Similarly as in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], the diference in results
between the base networks with Epinet and only the
base network is negligible. Nevertheless, after training
for only 5 epochs on a small dataset, training accuracy
seems to reach great results around 90%.
      </p>
      <sec id="sec-4-1">
        <title>For values of final joint logarithmic loss, calculated</title>
        <p>
          on validation dataset, results show that the networks
using epistemic index performed much better than base
SlovakBERT without Epinet in average. We also found
out that the networks are really sensitive to the size of
the epistemic index. In the table 1 below, we present
the percent value of the final joint logarithmic loss of
Epinet networks when compared to the value of the base
SlovakBERT.
(i.e. lower) joint loss values as networks with small epis- LLMs in terms of raw joint log-loss values but also
postemic indices sizes such as 10. It doesn’t mean that each sibly lower the amount of annotated data needed in the
consecutive epoch in training helps in lowering joint loss ifne-tuning process, e.g. with the help of Active learning
value, though. This can be also seen in the final loss val- methods. As most of these methods try to estimate
modues for Epinet 1 and 30, where the final value was actually els’ uncertainty on the input data, their combination and
higher than the final loss value of base SlovakBERT. As in uncertainty estimation with epistemic index and Epinet,
[
          <xref ref-type="bibr" rid="ref6">6</xref>
          ] the authors worked with image data, is hard to make in general, can bring interesting results when fine-tuning
a meaningful comparison to their results, nevertheless, low-resource language models.
our results show that benefit of using Epinet expands to
Large language models as well.
        </p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgement</title>
      <p>This research has been supported by grants
APVV-210114 and UK/96/2023.</p>
      <p>
        As the results suggest, ENN can serve as an
improvement to conventional neural networks, but our results
indicate some sort of instability, possibly caused by a lack
of fine-tuning data or weak adaptability of the network
parameters when used with a low-resource language
model. Both of these possible causes can be solved with
additional research, though. Still, finding this instability
is an interesting aspect of the ENN network, which was
not presented yet. The argument that in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] the
experiments were focused mainly on image data can be made,
although it doesn’t seem very likely that this can be a
cause for instability. A more reasonable conclusion is
that the under-trained model itself creates this instability.
      </p>
    </sec>
    <sec id="sec-6">
      <title>5. Conclusion</title>
      <p>We showed that Large language models pre-trained in
low-resource languages, such as Slovak, can benefit from
modeling their uncertainty in the fine-tuning process
to reach better results. This was made possible by
connecting this model to the Epinet network, creating an
Epistemic neural network. Results don’t indicate a major
improvement in classification accuracy, but joint
logarithmic loss seems to improve substantially. More research
and experiments on this topic are needed, though. Our
next potential step is to not only enhance these kinds of
tic optimization, arXiv preprint arXiv:1412.6980
(2014).
[11] Fewshot-goes-multilingual, 2022. Data retrieved
from Huggingface site, https://huggingface.
co/datasets/fewshot-goes-multilingual/sk_
csfd-movie-reviews.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>J.</given-names>
            <surname>Devlin</surname>
          </string-name>
          , M.-
          <string-name>
            <given-names>W.</given-names>
            <surname>Chang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Lee</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Toutanova</surname>
          </string-name>
          , Bert:
          <article-title>Pre-training of deep bidirectional transformers for language understanding</article-title>
          , arXiv preprint arXiv:
          <year>1810</year>
          .
          <volume>04805</volume>
          (
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Liu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ott</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Goyal</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Du</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Joshi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Chen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Levy</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Lewis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Zettlemoyer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Stoyanov</surname>
          </string-name>
          ,
          <article-title>Roberta: A robustly optimized bert pretraining approach</article-title>
          , arXiv preprint arXiv:
          <year>1907</year>
          .
          <volume>11692</volume>
          (
          <year>2019</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Z.</given-names>
            <surname>Lan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Chen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Goodman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Gimpel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Sharma</surname>
          </string-name>
          , R. Soricut,
          <string-name>
            <surname>Albert:</surname>
          </string-name>
          <article-title>A lite bert for self-supervised learning of language representations</article-title>
          , arXiv preprint arXiv:
          <year>1909</year>
          .
          <volume>11942</volume>
          (
          <year>2019</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>P.</given-names>
            <surname>He</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Liu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Gao</surname>
          </string-name>
          , W. Chen, Deberta:
          <article-title>Decodingenhanced bert with disentangled attention</article-title>
          , arXiv preprint arXiv:
          <year>2006</year>
          .
          <volume>03654</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>M.</given-names>
            <surname>Pikuliak</surname>
          </string-name>
          , Š. Grivalský,
          <string-name>
            <given-names>M.</given-names>
            <surname>Konôpka</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Blšták</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Tamajka</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Bachratý</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Šimko</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Balážik</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Trnka</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Uhlárik</surname>
          </string-name>
          ,
          <article-title>SlovakBERT: Slovak masked language model</article-title>
          ,
          <source>arXiv preprint arXiv:2109.15254</source>
          (
          <year>2021</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>I.</given-names>
            <surname>Osband</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Z.</given-names>
            <surname>Wen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S. M.</given-names>
            <surname>Asghari</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Dwaracherla</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Ibrahimi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Lu</surname>
          </string-name>
          ,
          <string-name>
            <surname>B. Van Roy</surname>
          </string-name>
          ,
          <article-title>Epistemic neural networks</article-title>
          ,
          <source>arXiv preprint arXiv:2107.08924</source>
          (
          <year>2021</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>A.</given-names>
            <surname>Vaswani</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Shazeer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Parmar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Uszkoreit</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Jones</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. N.</given-names>
            <surname>Gomez</surname>
          </string-name>
          , Ł. Kaiser,
          <string-name>
            <surname>I. Polosukhin</surname>
          </string-name>
          ,
          <article-title>Attention is all you need</article-title>
          ,
          <source>Advances in neural information processing systems</source>
          <volume>30</volume>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>A.</given-names>
            <surname>Radford</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Narasimhan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Salimans</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Sutskever</surname>
          </string-name>
          ,
          <article-title>Improving language understanding by generative pre-training (</article-title>
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>X.</given-names>
            <surname>Glorot</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Bengio</surname>
          </string-name>
          ,
          <article-title>Understanding the dificulty of training deep feedforward neural networks</article-title>
          ,
          <source>in: Proceedings of the thirteenth international conference on artificial intelligence and statistics, JMLR Workshop and Conference Proceedings</source>
          ,
          <year>2010</year>
          , pp.
          <fpage>249</fpage>
          -
          <lpage>256</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>D. P.</given-names>
            <surname>Kingma</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Ba</surname>
          </string-name>
          ,
          <article-title>Adam: A method for stochas-</article-title>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>