ar-seq2seq-gender (decoder)

This is a seq2seq model (decoder half) to "flip" gender in first-person Arabic sentences. The model can augment your existing Arabic data, or generate counterfactuals to test a model's decisions (would changing the gender of the subject or speaker change output?).

Intended Examples:

  • 'أنا سعيد' <=> 'انا سعيدة'
  • 'ركض إلى المتجر' <=> 'ركضت إلى المتجر'

People's names, gender pronouns, gendered words (father, mother), and many other values are currently unchanged by this model. Future versions may be trained on more data.

Sample Code

import torch
from transformers import AutoTokenizer, EncoderDecoderModel

model = EncoderDecoderModel.from_encoder_decoder_pretrained(
tokenizer = AutoTokenizer.from_pretrained('monsoon-nlp/ar-seq2seq-gender-decoder') # same as MARBERT original

input_ids = torch.tensor(tokenizer.encode("أنا سعيدة")).unsqueeze(0)
generated = model.generate(input_ids, decoder_start_token_id=model.config.decoder.pad_token_id)
tokenizer.decode(generated.tolist()[0][1 : len(input_ids[0]) - 1])
> 'انا سعيد'


I originally developed a gender flip Python script for Spanish sentences, using BETO, and spaCy. More about this project:

The Arabic model encoder and decoder started with weights and vocabulary from MARBERT from UBC-NLP, and was trained on the Arabic Parallel Gender Corpus from NYU Abu Dhabi. The text is first-person sentences from OpenSubtitles, with parallel gender-reinflected sentences generated by Arabic speakers.

Training notebook:

Non-binary gender

This model is useful to generate male and female text samples, but falls short of capturing gender diversity in the world and in the Arabic language. This subject is discussed in the bias statement of the Gender Reinflection paper.


Select AutoNLP in the “Train” menu to fine-tune this model automatically.

Downloads last month
Hosted inference API
Mask token: [MASK]
This model can be loaded on the Inference API on-demand.