mBERT Multilingual XNLI

Model Overview

This is a fine-tuned multilingual BERT (mBERT) model designed for Natural Language Inference (NLI).

It demonstrate the capabilities of an encoder-only transformer architecture for multilingual text understanding.

Given a premise and a hypothesis, the model predicts the relationship between them:

  • Entailment
  • Neutral
  • Contradiction

Base Model

The pretrained model used for fine-tuning is:

google-bert/bert-base-multilingual-cased

This is the multilingual BERT model from Google. It is designed to process text in multiple languages.


Model Architecture

The model uses an encoder-only Transformer architecture.

Architecture Details

  • Architecture: BERT / Encoder-only Transformer
  • Base model: google-bert/bert-base-multilingual-cased
  • Task: Natural Language Inference
  • Number of labels: 3
  • Framework: Hugging Face Transformers
  • Model type: Sequence Classification

For sequence classification, a classification layer is added on top of the pretrained BERT encoder to predict the NLI label.


Task

The model performs Natural Language Inference (NLI).

NLI determines the logical relationship between two pieces of text.

Labels

The model predicts one of three classes:

Label Meaning
Entailment The hypothesis is supported by the premise.
Neutral The hypothesis may be true, but it cannot be determined from the premise.
Contradiction The hypothesis conflicts with the premise.

Example

Premise:

A man is riding a bicycle.

Hypothesis:

A person is riding something.

The model analyzes both sentences and predicts their relationship.


Dataset

The model was fine-tuned using the XNLI (Cross-lingual Natural Language Inference) dataset.

Dataset used:

facebook/xnli

The all_languages configuration was used.

The original dataset contains the following splits:

  • Training set: 392,702 examples
  • Validation set: 2,490 examples
  • Test set: 5,010 examples

For this project, a smaller subset was selected for practical training in Google Colab:

  • Training examples: 10,000
  • Validation examples: 2,000
  • Test examples: 2,000

The dataset contains:

  • premise
  • hypothesis
  • label

Data Preprocessing

The premise and hypothesis were processed using the mBERT tokenizer.

The tokenizer was loaded from:

google-bert/bert-base-multilingual-cased

Each example was tokenized as a pair of sentences.

The maximum sequence length was set to:

128 tokens

The tokenization process included truncation so that longer examples would fit within the maximum sequence length.


Fine-Tuning Process

The pretrained mBERT model was loaded using:

AutoModelForSequenceClassification

with:

num_labels=3

The model was then fine-tuned on the selected XNLI training data.

Fine-Tuning Steps

  1. Load the XNLI dataset.
  2. Select training, validation, and test subsets.
  3. Load the pretrained multilingual BERT tokenizer.
  4. Tokenize the premise and hypothesis pairs.
  5. Load the pretrained mBERT model.
  6. Add a three-class sequence classification layer.
  7. Train the model using the selected training data.
  8. Evaluate the model on the validation data during training.
  9. Evaluate the final model on the test dataset.
  10. Save the fine-tuned model and tokenizer.
  11. Upload the model to Hugging Face.

Training Configuration

The model was fine-tuned using Google Colab.

The training configuration used in the notebook was:

Parameter Value
Base model google-bert/bert-base-multilingual-cased
Dataset facebook/xnli
Dataset configuration all_languages
Training examples 10,000
Validation examples 2,000
Test examples 2,000
Learning rate 2e-5
Training batch size 8
Evaluation batch size 8
Number of epochs 2
Weight decay 0.01
Maximum sequence length 128
Evaluation strategy Every epoch
Save strategy Every epoch

Evaluation Results

The final model was evaluated on the selected test dataset containing 2,000 examples.

The evaluation produced:

Metric Result
Test Loss 1.1007304191589355
Test Accuracy 0.3525
Test Accuracy (%) 35.25%

The final training loss reported after 2 epochs was:

1.0960737030029297

Interpretation

The model achieved an accuracy of 35.25% on the selected test subset.

This result represents the performance of the fine-tuned model under the specific training configuration and limited dataset subset used in this academic project.


How to Use

The model can be loaded using the Hugging Face Transformers library.

from transformers import pipeline

model_name = "Soho77/mbert-xnli-multilingual"

classifier = pipeline(
    "text-classification",
    model=model_name,
    tokenizer=model_name
)

For NLI, provide a premise and hypothesis as a pair of texts.

Example:

premise = "A man is riding a bicycle."
hypothesis = "A person is riding something."

result = classifier(premise, hypothesis)

print(result)

The output contains the predicted label and confidence score.


Intended Use

This model is intended for:

  • Natural Language Inference experiments
  • Multilingual text understanding
  • Academic NLP projects
  • Transformer model demonstrations
  • Research and educational purposes
  • Text classification experiments

Limitations

This model was created as part of an academic project and was fine-tuned using a relatively small subset of the XNLI dataset.

The reported accuracy should therefore not be interpreted as the performance of the original pretrained mBERT model or as a benchmark for all multilingual NLI tasks.

Performance can vary depending on:

  • Language
  • Domain
  • Sentence length
  • Vocabulary
  • Input quality
  • Training data

The model should not be considered a general-purpose language understanding system.

Training Environment

The model was fine-tuned using:

  • Google Colab
  • Python
  • PyTorch
  • Hugging Face Transformers
  • Hugging Face Datasets
  • Hugging Face Evaluate

Author

Developed as part of a Natural Language processing (NLP) project.

License

Apache-2.0

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support