monsoon-nlp/es-seq2seq-gender-decoder
121
1---2language: es3---4 5# es-seq2seq-gender (decoder)6 7This is a seq2seq model (decoder half) to "flip" gender in Spanish sentences.8The model can augment your existing Spanish data, or generate counterfactuals9to test a model's decisions (would changing the gender of the subject or speaker change output?).10 11Intended Examples:12 13- el profesor viejo => la profesora vieja (article, noun, adjective all flip)14- una actriz => un actor (irregular noun)15- el lingüista => la lingüista (irregular noun)16- la biblioteca => la biblioteca (no person, no flip)17 18People's names are unchanged in this version, but you can use packages19such as https://pypi.org/project/gender-guesser/20 21## Sample code22 23https://colab.research.google.com/drive/1Ta_YkXx93FyxqEu_zJ-W23PjPumMNHe524 25```26import torch27from transformers import AutoTokenizer, EncoderDecoderModel28 29model = EncoderDecoderModel.from_encoder_decoder_pretrained("monsoon-nlp/es-seq2seq-gender-encoder", "monsoon-nlp/es-seq2seq-gender-decoder")30tokenizer = AutoTokenizer.from_pretrained('monsoon-nlp/es-seq2seq-gender-decoder') # all are same as BETO uncased original31 32input_ids = torch.tensor(tokenizer.encode("la profesora vieja")).unsqueeze(0)33generated = model.generate(input_ids, decoder_start_token_id=model.config.decoder.pad_token_id)34tokenizer.decode(generated.tolist()[0])35> '[PAD] el profesor viejo profesor viejo profesor...'36```37 38## Training39 40I originally developed 41<a href="https://github.com/MonsoonNLP/el-la">a gender flip Python script</a>42with 43<a href="https://huggingface.co/dccuchile/bert-base-spanish-wwm-uncased">BETO</a>,44the Spanish-language BERT from Universidad de Chile,45and spaCy to parse dependencies in sentences.46 47More about this project: https://medium.com/ai-in-plain-english/gender-bias-in-spanish-bert-1f4d7678061748 49The seq2seq model is trained on gender-flipped text from that script run on the50<a href="https://huggingface.co/datasets/muchocine">muchocine dataset</a>, 51and the first 6,853 lines from the52<a href="https://oscar-corpus.com/">OSCAR corpus</a>53(Spanish ded-duped).54 55The encoder and decoder started with weights and vocabulary from BETO (uncased).56 57## Non-binary gender58 59This model is useful to generate male and female text samples, but falls60short of capturing gender diversity in the world and in the Spanish61language. Some communities prefer the plural -@s to represent62-os and -as, or -e and -es for gender-neutral or mixed-gender plural,63or use fewer gendered professional nouns (la juez and not jueza). This is not yet64embraced by the Royal Spanish Academy 65and is not represented in the corpora and tokenizers used to build this project.66 67This seq2seq project and script could, in the future, help generate more text samples 68and prepare NLP models to understand us all better.69 70#### Sources71 72- https://www.nytimes.com/2020/04/15/world/americas/argentina-gender-language.html73- https://www.washingtonpost.com/dc-md-va/2019/12/05/teens-argentina-are-leading-charge-gender-neutral-language/?arc404=true74- https://www.theguardian.com/world/2020/jan/19/gender-neutral-language-battle-spain75- https://es.wikipedia.org/wiki/Lenguaje_no_sexista76- https://remezcla.com/culture/argentine-company-re-imagines-little-prince-gender-neutral-language/77 