All Implemented Interfaces:
IMatcher<org.apache.jena.ontology.OntModel,Alignment,Properties>, eu.sealsproject.platform.res.domain.omt.IOntologyMatchingToolBridge, eu.sealsproject.platform.res.tool.api.IPlugin, eu.sealsproject.platform.res.tool.api.IToolBridge
Direct Known Subclasses:
SentenceTransformersFineTuner, TransformersFineTuner

public abstract class TransformersBaseFineTuner extends TransformersBase
This is a base class for all Transformers fine tuners. It just contains some variables and getter and setters.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • NEWLINE

      protected static final String NEWLINE
    • resultingModelLocation

      protected File resultingModelLocation
    • trainingFile

      protected File trainingFile
    • additionallySwitchSourceTarget

      protected boolean additionallySwitchSourceTarget
  • Constructor Details

  • Method Details

    • match

      public Alignment match(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment inputAlignment, Properties properties) throws Exception
      This method does only fine tune the model and does not match any entities.
      Specified by:
      match in interface IMatcher<org.apache.jena.ontology.OntModel,Alignment,Properties>
      Specified by:
      match in class MatcherYAAAJena
      Parameters:
      source - This OntModel represents the source ontology.
      target - This OntModel represents the target ontology.
      inputAlignment - This mapping represents the input alignment.
      properties - Additional properties.
      Returns:
      the resulting alignment - in this special case the unmodified input alignment.
      Throws:
      Exception - in case something goes wrong
    • createTrainingFile

      public File createTrainingFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment trainingAlignment) throws IOException
      Creates a new file and writes all correspondences as textual data to it. Can also be used for creating a validation file.
      Parameters:
      source - the source model
      target - the target model
      trainingAlignment - the training alignment to be written to file.
      Returns:
      the training file.
      Throws:
      IOException - in case the writing fails
    • writeTrainingFile

      public int writeTrainingFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment trainingAlignment, File trainFile, boolean append) throws IOException
      Writes the correspondences to a file (append or not can be chosen by a parameter).
      Parameters:
      source - the source model
      target - the target model
      trainingAlignment - the training alignment to be written to file.
      trainFile - the file to write all texts
      append - true if all content should be appended to the file.
      Returns:
      how many correspondences were written to the file.
      Throws:
      IOException - in case the writing fails
    • writeClassificationFormat

      protected int writeClassificationFormat(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment trainingAlignment, File trainFile, boolean append) throws IOException
      Throws:
      IOException
    • finetuneModel

      public abstract File finetuneModel(File trainingFile) throws Exception
      Finetune a given model with the provided text in the csv file (three columns: first text, second text, label(0/1))
      Parameters:
      trainingFile - csv file with three columns: first text, second text, label(0/1) (can be generated with createTrainingFile(OntModel, OntModel, Alignment) )
      Returns:
      the final location (directory) of the finetuned model (which is also given in the constructor)
      Throws:
      Exception - in case of any error
    • finetuneModel

      public File finetuneModel() throws Exception
      This method should only be used when appendOnlyToFile is set to true. This will train a transformers model on the file generated by the match method during possibley multiple calls.
      Returns:
      the final location (directory) of the fine-tuned model (which is also given in the constructor)
      Throws:
      Exception - in case of any error
    • clearTrainingData

      public void clearTrainingData()
      Removes the training data
    • getTrainingFile

      public File getTrainingFile()
      Returns the training file generated during multiple calls of the match method. If the match method is not called yet, this will return a non existent file.
      Returns:
      the training file
    • getResultingModelLocation

      public File getResultingModelLocation()
      Returns the final location where the finetuned model should be stored
      Returns:
      the location for the trained model.
    • setResultingModelLocation

      public void setResultingModelLocation(File resultingModelLocation)
      Sets the final location where the finetuned model should be stored.
      Parameters:
      resultingModelLocation - the model location as a file.
    • isAdditionallySwitchSourceTarget

      public boolean isAdditionallySwitchSourceTarget()
      Return the boolean value if training examples are additionally changed in their order. If true, the training examples not only contain e.g. A,B but also B,A because positive and negative examples still hold even when the order is changed. This will double the number of training examples.
      Returns:
      true, training examples are additionally changed in their order
    • setAdditionallySwitchSourceTarget

      public void setAdditionallySwitchSourceTarget(boolean additionallySwitchSourceTarget)
      If set to true, the training examples not only contain e.g. A,B but also B,A because positive and negative example still hold even when the order is changed. This will double the number of training examples. The default is false.
      Parameters:
      additionallySwitchSourceTarget - true, if source and target should be changed.