Output range of BERT model shrinks after fine-tuning on domain specific dataset












1












$begingroup$


My model's sigmoid output range has shrunk after transfer learning with small a dataset. My pretrained model has an output range of 0 to 1. After fine-tuning with a smaller domain specific dataset, the model's output range is about 0.25 to 0.6. What is wrong with this model? I will show some key methods and code of my training. Please help, thanks.



My purpose is to train a model to score how relevant a sentence is to a query.
So I trained a LTR (learning to rank) model with a big dataset. I use BERT (nlp-pretrained model) to do the LM model training. BERT is used to extract the feature of sentences. Then I map the output of BERT to a single number using linear layer. Finally I use a sigmoid function to make the output range 0 to 1. Eventually I make the score function like this:



score of sentence = sigmoid(Linear(Bert(query,sentence)))


model:



model_output = score(q,a)-score(q,b)


The dataset consist of pairwise queries and sentences. The loss function is like hinge loss:



loss=1/2*sum(square(max(0,tau-(score_func(query,senA)-score_func(query,senB))))


It could also be written as this:



loss=1/2*sum(square(max(0,tau - model_output)))


The tau is the minus gap of score of two sentences. I use tau = 0.1 all the time.



After LM model training I use a test dataset to evaluate the model. The output range of model is 0 to 1.
Then I use a smaller domain specific dataset to fine-tune the model. Finally I use the same test dataset as above to evaluate this fine-tuned model, that resulted in the model output range changing. It changed from 0 - 1 to about 0.25 to 0.6.



It look like fine-tuning with domain data compresses the output range of model. Why did this happen?



I guess output range of the original model must have the same distribution when it is fine-tuned.










share|improve this question









New contributor




liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    1












    $begingroup$


    My model's sigmoid output range has shrunk after transfer learning with small a dataset. My pretrained model has an output range of 0 to 1. After fine-tuning with a smaller domain specific dataset, the model's output range is about 0.25 to 0.6. What is wrong with this model? I will show some key methods and code of my training. Please help, thanks.



    My purpose is to train a model to score how relevant a sentence is to a query.
    So I trained a LTR (learning to rank) model with a big dataset. I use BERT (nlp-pretrained model) to do the LM model training. BERT is used to extract the feature of sentences. Then I map the output of BERT to a single number using linear layer. Finally I use a sigmoid function to make the output range 0 to 1. Eventually I make the score function like this:



    score of sentence = sigmoid(Linear(Bert(query,sentence)))


    model:



    model_output = score(q,a)-score(q,b)


    The dataset consist of pairwise queries and sentences. The loss function is like hinge loss:



    loss=1/2*sum(square(max(0,tau-(score_func(query,senA)-score_func(query,senB))))


    It could also be written as this:



    loss=1/2*sum(square(max(0,tau - model_output)))


    The tau is the minus gap of score of two sentences. I use tau = 0.1 all the time.



    After LM model training I use a test dataset to evaluate the model. The output range of model is 0 to 1.
    Then I use a smaller domain specific dataset to fine-tune the model. Finally I use the same test dataset as above to evaluate this fine-tuned model, that resulted in the model output range changing. It changed from 0 - 1 to about 0.25 to 0.6.



    It look like fine-tuning with domain data compresses the output range of model. Why did this happen?



    I guess output range of the original model must have the same distribution when it is fine-tuned.










    share|improve this question









    New contributor




    liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      1












      1








      1





      $begingroup$


      My model's sigmoid output range has shrunk after transfer learning with small a dataset. My pretrained model has an output range of 0 to 1. After fine-tuning with a smaller domain specific dataset, the model's output range is about 0.25 to 0.6. What is wrong with this model? I will show some key methods and code of my training. Please help, thanks.



      My purpose is to train a model to score how relevant a sentence is to a query.
      So I trained a LTR (learning to rank) model with a big dataset. I use BERT (nlp-pretrained model) to do the LM model training. BERT is used to extract the feature of sentences. Then I map the output of BERT to a single number using linear layer. Finally I use a sigmoid function to make the output range 0 to 1. Eventually I make the score function like this:



      score of sentence = sigmoid(Linear(Bert(query,sentence)))


      model:



      model_output = score(q,a)-score(q,b)


      The dataset consist of pairwise queries and sentences. The loss function is like hinge loss:



      loss=1/2*sum(square(max(0,tau-(score_func(query,senA)-score_func(query,senB))))


      It could also be written as this:



      loss=1/2*sum(square(max(0,tau - model_output)))


      The tau is the minus gap of score of two sentences. I use tau = 0.1 all the time.



      After LM model training I use a test dataset to evaluate the model. The output range of model is 0 to 1.
      Then I use a smaller domain specific dataset to fine-tune the model. Finally I use the same test dataset as above to evaluate this fine-tuned model, that resulted in the model output range changing. It changed from 0 - 1 to about 0.25 to 0.6.



      It look like fine-tuning with domain data compresses the output range of model. Why did this happen?



      I guess output range of the original model must have the same distribution when it is fine-tuned.










      share|improve this question









      New contributor




      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      My model's sigmoid output range has shrunk after transfer learning with small a dataset. My pretrained model has an output range of 0 to 1. After fine-tuning with a smaller domain specific dataset, the model's output range is about 0.25 to 0.6. What is wrong with this model? I will show some key methods and code of my training. Please help, thanks.



      My purpose is to train a model to score how relevant a sentence is to a query.
      So I trained a LTR (learning to rank) model with a big dataset. I use BERT (nlp-pretrained model) to do the LM model training. BERT is used to extract the feature of sentences. Then I map the output of BERT to a single number using linear layer. Finally I use a sigmoid function to make the output range 0 to 1. Eventually I make the score function like this:



      score of sentence = sigmoid(Linear(Bert(query,sentence)))


      model:



      model_output = score(q,a)-score(q,b)


      The dataset consist of pairwise queries and sentences. The loss function is like hinge loss:



      loss=1/2*sum(square(max(0,tau-(score_func(query,senA)-score_func(query,senB))))


      It could also be written as this:



      loss=1/2*sum(square(max(0,tau - model_output)))


      The tau is the minus gap of score of two sentences. I use tau = 0.1 all the time.



      After LM model training I use a test dataset to evaluate the model. The output range of model is 0 to 1.
      Then I use a smaller domain specific dataset to fine-tune the model. Finally I use the same test dataset as above to evaluate this fine-tuned model, that resulted in the model output range changing. It changed from 0 - 1 to about 0.25 to 0.6.



      It look like fine-tuning with domain data compresses the output range of model. Why did this happen?



      I guess output range of the original model must have the same distribution when it is fine-tuned.







      nlp transfer-learning bert






      share|improve this question









      New contributor




      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited yesterday







      liang miao













      New contributor




      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      liang miaoliang miao

      63




      63




      New contributor




      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      liang miao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "557"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          liang miao is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48850%2foutput-range-of-bert-model-shrinks-after-fine-tuning-on-domain-specific-dataset%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          liang miao is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          liang miao is a new contributor. Be nice, and check out our Code of Conduct.













          liang miao is a new contributor. Be nice, and check out our Code of Conduct.












          liang miao is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48850%2foutput-range-of-bert-model-shrinks-after-fine-tuning-on-domain-specific-dataset%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Callistus I

          Tabula Rosettana

          How to label and detect the document text images