readme: ---
  license: cc-by-sa-4.0
  
  language: 
  - multilingual
  - af
  - am
  - ar
  - as
  - az
  - be
  - bg
  - bn
  - br
  - bs
  - ca
  - cs
  - cy
  - da
  - de
  - el
  - en
  - eo
  - es
  - et
  - eu
  - fa
  - fi
  - fr
  - fy
  - ga
  - gd
  - gl
  - gu
  - ha
  - he
  - hi
  - hr
  - hu
  - hy
  - id
  - is
  - it
  - ja
  - jv
  - ka
  - kk
  - km
  - kn
  - ko
  - ku
  - ky
  - la
  - lo
  - lt
  - lv
  - mg
  - mk
  - ml
  - mn
  - mr
  - ms
  - my
  - ne
  - nl
  - no
  - om
  - or
  - pa
  - pl
  - ps
  - pt
  - ro
  - ru
  - sa
  - sd
  - si
  - sk
  - sl
  - so
  - sq
  - sr
  - su
  - sv
  - sw
  - ta
  - te
  - th
  - tl
  - tr
  - ug
  - uk
  - ur
  - uz
  - vi
  - xh
  - yi
  - zh
  
  tags:
  - text-classification
  - genre
  - text-genre
  
  widget:
  - text: "On our site, you can find a great genre identification model which you can use for thousands of different tasks. For free!"
    example_title: "English"
  - text: "Na naši spletni strani lahko najdete odličen model za prepoznavanje žanrov, ki ga lahko uporabite pri na tisoče različnih nalogah. In to brezplačno!"
    example_title: "Slovene"
  - text: "Sur notre site, vous trouverez un modèle d'identification de genre très intéressant que vous pourrez utiliser pour des milliers de tâches différentes. C'est gratuit !"
    example_title: "French"
  
  ---
  
  # X-GENRE classifier - multilingual text genre classifier
  
  Text classification model based on [`xlm-roberta-base`](https://huggingface.co/xlm-roberta-base) and fine-tuned on a combination of three genre datasets: Slovene GINCO<sup>1</sup> dataset, the English CORE<sup>2</sup> dataset and the English FTD<sup>3</sup> dataset. The model can be used for automatic genre identification, applied to any text in a language, supported by the `xlm-roberta-base`.
  
  ## Model description
  
  The model was fine-tuned on the "X-GENRE" dataset which consists of three genre datasets: CORE, FTD and GINCO dataset. Each of the datasets has their own genre schema, so they were combined into a joint schema ("X-GENRE" schema) based on the comparison of labels and cross-dataset experiments (described in details [here](https://github.com/TajaKuzman/Genre-Datasets-Comparison)).
  
  ### Fine-tuning hyperparameters
  
  Fine-tuning was performed with `simpletransformers`. Beforehand, a brief hyperparameter optimization was performed and the presumed optimal hyperparameters are:
  
  ```python
  model_args= {
              "num_train_epochs": 15,
              "learning_rate": 1e-5,
              "max_seq_length": 512,
              }        
        
  ```
  
  ## Intended use and limitations
  
  ## Usage
  
  An example of preparing data for genre identification and post-processing of the results can be found [here](https://github.com/TajaKuzman/Applying-GENRE-on-MaCoCu-bilingual) where we applied X-GENRE classifier to the English part of [MaCoCu](https://macocu.eu/) parallel corpora.
  
  For reliable results, genre classifier should be applied to documents of sufficient length (the rule of thumbs is at least 75 words). It is advised that the predictions, predicted with confidence lower than 0.9, are not used. Furthermore, the label "Other" can be used as another indicator of low confidence of the predictions, as it often indicates that the text does not have enough features of any genre, and these predictions can be discarded as well.
  
  After proposed post-processing (removal of low-confidence predictions, labels "Other" and in this specific case also label "Forum"), the performance on the MaCoCu data based on manual inspection reached macro and micro F1 of 0.92.
  
  
  ### Use examples
  
  ```python
  from simpletransformers.classification import ClassificationModel
  model_args= {
              "num_train_epochs": 15,
              "learning_rate": 1e-5,
              "max_seq_length": 512,
              "silent": True
              }
  model = ClassificationModel(
      "xlmroberta", "TajaKuzman/xlm-roberta-base-multilingual-text-genres", use_cuda=True,
      args=model_args
      
  )
  predictions, logit_output = model.predict(["How to create a good text classification model? First step is to prepare good data. Make sure not to skip the exploratory data analysis. Pre-process the text if necessary for the task. The next step is to perform hyperparameter search to find the optimum hyperparameters. After fine-tuning the model, you should look into the predictions and analyze the model's performance. You might want to perform the post-processing of data as well and keep only reliable predictions.", 
                                          "On our site, you can find a great genre identification model which you can use for thousands of different tasks. With our model, you can fastly and reliably obtain high-quality genre predictions and explore which genres exist in your corpora. Available for free!"]
                                          )
  predictions
  # Output: array([3, 8])
  
  [model.config.id2label[i] for i in predictions]
  # Output: ['Instruction', 'Promotion']
  
  ```
  
  Use example for prediction on a dataset, using batch processing, is available via [Google Collab](https://colab.research.google.com/drive/1yC4L_p2t3oMViC37GqSjJynQH-EWyhLr?usp=sharing).
  
  ## X-GENRE categories
  
  List of labels:
  ```
  label