JamSpell es una biblioteca de corrección ortográfica con las siguientes características:
Ejemplo de colaboración
jamspell.com: consulte una nueva versión de jamspell con las siguientes características
en, ru, de, fr, it, es, tr, uk, pl, nl, pt, hi, no
Java, C#, Ruby
Errores | Los 7 errores principales | Tasa fija | Las 7 principales tasas de fijación | Roto | Velocidad (palabras/segundo) | |
JamSpell | 3,25% | 1,27% | 79,53% | 84,10% | 0,64% | 4854 |
Noruega | 7,62% | 5,00% | 46,58% | 66,51% | 0,69% | 395 |
Hunspell | 13,10% | 10,33% | 47,52% | 68,56% | 7,14% | 163 |
Ficticio | 13,14% | 13,14% | 0,00% | 0,00% | 0,00% | - |
El modelo fue entrenado con 300.000 oraciones de Wikipedia + 300.000 oraciones de noticias (inglés). El 95% se utilizó para entrenar, el 5% se utilizó para evaluación. Se utilizó el modelo de errores para generar texto con errores a partir del original. El corrector JamSpell se comparó con el de Norvig, Hunspell y uno ficticio (sin correcciones).
Utilizamos las siguientes métricas:
Para asegurarnos de que nuestro modelo no esté demasiado adaptado a wikipedia+noticias, lo verificamos en el texto "Las aventuras de Sherlock Holmes":
Errores | Los 7 errores principales | Tasa fija | Las 7 principales tasas de fijación | Roto | Velocidad (palabras por segundo) | |
JamSpell | 3,56% | 1,27% | 72,03% | 79,73% | 0,50% | 5524 |
Noruega | 7,60% | 5,30% | 35,43% | 56,06% | 0,45% | 647 |
Hunspell | 9,36% | 6,44% | 39,61% | 65,77% | 2,95% | 284 |
Ficticio | 11,16% | 11,16% | 0,00% | 0,00% | 0,00% | - |
Más detalles sobre la reproducción disponibles en la sección "Tren".
Instale swig3
(generalmente está en el administrador de paquetes de su distribución)
Instalar jamspell
:
pip install jamspell
Descargar o entrenar el modelo de lenguaje
Úselo:
import jamspell
corrector = jamspell . TSpellCorrector ()
corrector . LoadLangModel ( 'en.bin' )
corrector . FixFragment ( 'I am the begt spell cherken!' )
# u'I am the best spell checker!'
corrector . GetCandidates ([ 'i' , 'am' , 'the' , 'begt' , 'spell' , 'cherken' ], 3 )
# (u'best', u'beat', u'belt', u'bet', u'bent', ... )
corrector . GetCandidates ([ 'i' , 'am' , 'the' , 'begt' , 'spell' , 'cherken' ], 5 )
# (u'checker', u'chicken', u'checked', u'wherein', u'coherent', ...)
Agregue directorios jamspell
y contrib
a su proyecto
Úselo:
# include < jamspell/spell_corrector.hpp >
int main ( int argc, const char ** argv) {
NJamSpell::TSpellCorrector corrector;
corrector. LoadLangModel ( " model.bin " );
corrector. FixFragment ( L" I am the begt spell cherken! " );
// "I am the best spell checker!"
corrector. GetCandidates ({ L" i " , L" am " , L" the " , L" begt " , L" spell " , L" cherken " }, 3 );
// "best", "beat", "belt", "bet", "bent", ... )
corrector. GetCandidates ({ L" i " , L" am " , L" the " , L" begt " , L" spell " , L" cherken " }, 3 );
// "checker", "chicken", "checked", "wherein", "coherent", ... )
return 0 ;
}
Puedes generar extensiones para otros idiomas usando el tutorial swig. El archivo de interfaz de trago es jamspell.i
. Las solicitudes de extracción con scripts de compilación son bienvenidas.
Instalar cmake
Clona y construye jamspell (incluye servidor http):
git clone https://github.com/bakwc/JamSpell.git
cd JamSpell
mkdir build
cd build
cmake ..
make
./web_server/web_server en.bin localhost 8080
$ curl " http://localhost:8080/fix?text=I am the begt spell cherken "
I am the best spell checker
$ curl -d " I am the begt spell cherken " http://localhost:8080/fix
I am the best spell checker
curl " http://localhost:8080/candidates?text=I am the begt spell cherken "
# or
curl -d " I am the begt spell cherken " http://localhost:8080/candidates
{
"results" : [
{
"candidates" : [
"best" ,
"beat" ,
"belt" ,
"bet" ,
"bent" ,
"beet" ,
"beit"
] ,
"len" : 4 ,
"pos_from" : 9
} ,
{
"candidates" : [
"checker" ,
"chicken" ,
"checked" ,
"wherein" ,
"coherent" ,
"cheered" ,
"cherokee"
] ,
"len" : 7 ,
"pos_from" : 20
}
]
}
Aquí pos_from
- posición de la primera letra de la palabra mal escrita, len
- palabra mal escrita len
Para entrenar un modelo personalizado necesitas:
Instalar cmake
Clona y construye jamspell:
git clone https://github.com/bakwc/JamSpell.git
cd JamSpell
mkdir build
cd build
cmake ..
make
Prepare un archivo de texto utf-8 con oraciones para entrenar (p. ej., sherlockholmes.txt
) y otro archivo con el alfabeto del idioma (p. ej., alphabet_en.txt
).
Modelo de tren:
./main/jamspell train ../test_data/alphabet_en.txt ../test_data/sherlockholmes.txt model_sherlock.bin
evaluate/evaluate.py
: python evaluate/evaluate.py -a alphabet_file.txt -jsp your_model.bin -mx 50000 your_test_data.txt
evaluate/generate_dataset.py
para generar sus datos de entrenamiento/prueba. Admite archivos txt, formato Leipzig Corpora Collection y libros fb2. Aquí hay algunos modelos simples. Se entrenaron con 300.000 noticias + 300.000 frases de Wikipedia. Recomendamos encarecidamente entrenar su propio modelo, al menos en unos pocos millones de oraciones para lograr una mejor calidad. Consulte la sección Tren más arriba.