174 lines
5.7 KiB
Markdown
174 lines
5.7 KiB
Markdown
---
|
||
license: apache-2.0
|
||
datasets:
|
||
- FBK-MT/GNR-it
|
||
language:
|
||
- it
|
||
base_model:
|
||
- Qwen/Qwen3-8B
|
||
pipeline_tag: text-generation
|
||
library_name: transformers
|
||
tags:
|
||
- rewriting
|
||
- fairness
|
||
- gender-inclusive
|
||
- gender-neutral
|
||
metrics:
|
||
- accuracy
|
||
- bertscore
|
||
---
|
||
|
||
# Qwen3-8B-GNR-it-clean
|
||
|
||
Qwen3-8B-GNR-it-clean is a fine-tuned version of [Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B) for the task of gender-neutral rewriting (GNR) in Italian.
|
||
|
||
## Table of Contents
|
||
1. [Overview](#overview)
|
||
2. [Usage](#Usage)
|
||
3. [License](#license)
|
||
4. [Citation](#citation)
|
||
5. [Contributions](#contributions)
|
||
|
||
## Overview
|
||
|
||
This model is part of a family release of four models (8B/14B × clean/full) trained on [GNR-it](https://huggingface.co/datasets/FBK-MT/GNR-it), a dataset of parallel Italian gendered and gender-neutral sentences.
|
||
The _clean_ variants are trained on a BERTScore-filtered subset of the data, whereas the _full_ ones use the complete dataset.
|
||
Here is the complete family of models:
|
||
|
||
- [Qwen3-8B-GNR-it-clean](https://huggingface.co/FBK-MT/Qwen3-8B-GNR-it-clean)
|
||
- [Qwen3-8B-GNR-it-full](https://huggingface.co/FBK-MT/Qwen3-8B-GNR-it-full)
|
||
- [Qwen3-14B-GNR-it-clean](https://huggingface.co/FBK-MT/Qwen3-14B-GNR-it-clean)
|
||
- [Qwen3-14B-GNR-it-full](https://huggingface.co/FBK-MT/Qwen3-14B-GNR-it-full)
|
||
|
||
We are releasing these models to support reproducibility of the experiments reported in the paper [Gender-Neutral Rewriting in Italian: Models, Approaches,
|
||
and Trade-offs]([PLACEHOLDER](https://arxiv.org/abs/2509.13480)) and provide the community with open baselines for GNR in Italian.
|
||
The models are not intended as prescriptive tools for language use, but rather as research artifacts to study fairness in natural language generation.
|
||
|
||
For more information about these models, please check the paper [pre-print]([PLACEHOLDER](https://arxiv.org/abs/2509.13480)).
|
||
|
||
## Usage
|
||
|
||
This model is supported in Hugging Face 🤗 Transformers and vLLM.
|
||
|
||
### Simple inference
|
||
To run the model, first install the Transformers library.
|
||
|
||
```sh
|
||
pip install transformers>=4.51.0
|
||
```
|
||
|
||
Then run standard inference:
|
||
|
||
```python
|
||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||
|
||
model_name = "FBK-MT/Qwen3-8B-GNR-it-clean"
|
||
|
||
# load the tokenizer and the model
|
||
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
||
model = AutoModelForCausalLM.from_pretrained(
|
||
model_name,
|
||
torch_dtype="auto",
|
||
device_map="auto"
|
||
)
|
||
|
||
# prepare the model input
|
||
system_message = "Rewrite the following Italian sentence using a gender-neutral language in reference to human beings, avoiding masculine or feminine forms."
|
||
input_sentence = "Sono convinto che dobbiamo tutelare tutti i cittadini, a partire dai più poveri."
|
||
messages = [
|
||
{"role": "system", "content": system_message},
|
||
{"role": "user", "content": input_sentence}
|
||
]
|
||
text = tokenizer.apply_chat_template(
|
||
messages,
|
||
tokenize=False,
|
||
add_generation_prompt=True,
|
||
enable_thinking=False
|
||
)
|
||
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
||
|
||
generated_ids = model.generate(
|
||
**model_inputs,
|
||
max_new_tokens=200
|
||
)
|
||
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
||
|
||
result = tokenizer.decode(output_ids[0][model_inputs["input_ids"].shape[-1]:])
|
||
print(result)
|
||
# "Sono dell'opinione che dobbiamo tutelare tutte le fasce sociali, a partire dalle più deboli"
|
||
```
|
||
|
||
### Batch inference
|
||
|
||
To perform batched inference we recommend using [vLLM](https://docs.vllm.ai/en/latest/index.html).
|
||
|
||
First, install the library following [the official guide](https://docs.vllm.ai/en/latest/getting_started/installation/).
|
||
|
||
Then, prepare a list of inputs and let vLLM handle batching:
|
||
|
||
```python
|
||
import torch
|
||
from vllm import LLM
|
||
|
||
model = LLM(
|
||
model='FBK-MT/Qwen3-8B-GNR-it-clean',
|
||
enable_prefix_caching=True,
|
||
disable_sliding_window=True,
|
||
tensor_parallel_size=torch.cuda.device_count(),
|
||
gpu_memory_utilization=0.9,
|
||
trust_remote_code=True)
|
||
|
||
system_message = "Rewrite the following Italian sentence using a gender-neutral language in reference to human beings, avoiding masculine or feminine forms."
|
||
input_sentences = [
|
||
"Il candidato che è stato scelto per la posizione ha dimostrato di avere un'ottima preparazione e di essere adeguadatmente preparato.",
|
||
"Verrà istituito un sistema di informazione per i consumatori che acquistano prodotti elettronici.",
|
||
"Lo studente deve consegnare il compito entro venerdì."
|
||
]
|
||
|
||
tokenizer = model.get_tokenizer()
|
||
|
||
input_data = [
|
||
tokenizer.apply_chat_template(
|
||
[
|
||
{"role": "system", "content": system_message},
|
||
{"role": "user", "content": text},
|
||
],
|
||
add_generation_prompt=True,
|
||
tokenize=False,
|
||
enable_thinking=False
|
||
)
|
||
for text in input_sentences
|
||
]
|
||
|
||
responses = model.generate(input_data, use_tqdm=True)
|
||
results = [response.outputs[0].text for response in responses]
|
||
print(results)
|
||
# ["La persona che è stata scelta per la posizione ha dimostrato di avere un'ottima preparazione e di essere adeguatamente qualificata.",
|
||
# "Verrà istituito un sistema di informazione per i soggetti che acquistano prodotti elettronici.",
|
||
# "Il compito deve essere consegnato entro venerdì."]
|
||
```
|
||
|
||
## License
|
||
|
||
We release this model under the Apache 2.0 license.
|
||
|
||
## Citation
|
||
|
||
If you this model in your work, please cite:
|
||
|
||
```
|
||
@misc{piergentili2025genderneutralrewritingitalianmodels,
|
||
title={Gender-Neutral Rewriting in Italian: Models, Approaches, and Trade-offs},
|
||
author={Andrea Piergentili and Beatrice Savoldi and Matteo Negri and Luisa Bentivogli},
|
||
year={2025},
|
||
eprint={2509.13480},
|
||
archivePrefix={arXiv},
|
||
primaryClass={cs.CL},
|
||
url={https://arxiv.org/abs/2509.13480},
|
||
}
|
||
```
|
||
|
||
## Contributions
|
||
|
||
Thanks to [@apiergentili](https://huggingface.co/apiergentili) for adding this model.
|