File size: 3,897 Bytes
c075c16 8209234 c075c16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
---
thumbnail: "Аn open multilingual readability scoring model TRank"
base_model: "Peltarion/xlm-roberta-longformer-base-4096"
tags:
- arxiv:2406.01835
- Readability
- Multilingual
- Wikipedia
license: mit
language:
- yi
- xh
- fy
- cy
- vi
- uz
- ug
- ur
- uk
- tr
- th
- te
- ta
- sv
- sw
- su
- es
- so
- sl
- sk
- si
- sd
- sr
- gd
- sa
- ru
- ro
- pa
- pt
- pl
- fa
- ps
- om
- or
- 'no'
- ne
- mn
- mr
- ml
- ms
- mg
- mk
- lt
- lv
- la
- lo
- ky
- ku
- ko
- km
- kk
- kn
- jv
- ja
- it
- ga
- id
- is
- hu
- hi
- he
- ha
- gu
- el
- de
- ka
- gl
- fr
- fi
- tl
- et
- eo
- en
- nl
- da
- cs
- hr
- zh
- ca
- my
- bg
- br
- bs
- bn
- be
- eu
- az
- as
- hy
- ar
- am
- af
- sq
pipeline_tag: text-classification
---
# Open Multilingual Text Readability Scoring Model (TRank)
[![DOI:10.48550/arXiv.2406.01835](https://zenodo.org/badge/DOI/10.48550/arXiv.2406.01835.svg)](https://doi.org/10.48550/arXiv.2406.01835)
[![Readability Experiments repo](https://img.shields.io/badge/GitLab-repo-orange)](https://gitlab.wikimedia.org/repos/research/readability-experiments)
## Overview
This repository contains an open multilingual readability scoring model TRank, presented in the ACL'24 paper **An Open Multilingual System for Scoring Readability of Wikipedia**.
The model is designed to evaluate the readability of text across multiple languages.
## Features
- **Multilingual Support**: Evaluates readability in multiple languages.
- **Pairwise Ranking**: Trained using a Siamese architecture with Margin Ranking Loss to differentiate and rank texts from hardest to simplest.
- **Long Context Window**: Utilizes the Longformer architecture of the base model, supporting inputs up to 4096 tokens.
## Model Training
The model training implementation can be found in the [Readability Experiments repo](https://gitlab.wikimedia.org/repos/research/readability-experiments).
## Usage example
```
import torch
import torch.nn as nn
from transformers import AutoModel
from huggingface_hub import PyTorchModelHubMixin
from transformers import AutoTokenizer
# Define the model:
BASE_MODEL = "Peltarion/xlm-roberta-longformer-base-4096"
class ReadabilityModel(nn.Module, PyTorchModelHubMixin):
def __init__(self, model_name=BASE_MODEL):
super(ReadabilityModel, self).__init__()
self.model = AutoModel.from_pretrained(model_name)
self.drop = nn.Dropout(p=0.2)
self.fc = nn.Linear(768, 1)
def forward(self, ids, mask):
out = self.model(input_ids=ids, attention_mask=mask,
output_hidden_states=False)
out = self.drop(out[1])
outputs = self.fc(out)
return outputs
# Load the model:
model = ReadabilityModel.from_pretrained("trokhymovych/TRank_readability")
# Load the tokenizer:
tokenizer = AutoTokenizer.from_pretrained("trokhymovych/TRank_readability")
# Set the model to evaluation mode
model.eval()
# Example input text
input_text = "This is an example sentence to evaluate readability."
# Tokenize the input text
inputs = tokenizer.encode_plus(
input_text,
add_special_tokens=True,
max_length=512,
truncation=True,
padding='max_length',
return_tensors='pt'
)
ids = inputs['input_ids']
mask = inputs['attention_mask']
# Make prediction
with torch.no_grad():
outputs = model(ids, mask)
readability_score = outputs.item()
# Print the input text and the readability score
print(f"Input Text: {input_text}")
print(f"Readability Score: {readability_score}")
```
## Citation
Preprint:
```
@misc{trokhymovych2024openmultilingualscoringreadability,
title={An Open Multilingual System for Scoring Readability of Wikipedia},
author={Mykola Trokhymovych and Indira Sen and Martin Gerlach},
year={2024},
eprint={2406.01835},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2406.01835},
}
```
|