Complétion Simple#

Links: notebook, html, PDF, python, slides, GitHub

Evaluation d’une métrique pour un système de complétion sur quelques cas simples.

from jyquickhelper import add_notebook_menu
add_notebook_menu()

Métrique M’#

from mlstatpy.nlp import CompletionSystem
mots = ["po", "po rouge", "po vert", "po orange", "port", "port blanc", "port bleu", "port rouge"]
ens = CompletionSystem(mots)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 | po
n=1 : M'=2 | po rouge
n=2 : M'=3 | po vert
n=3 : M'=4 | po orange
n=4 : M'=3 | port
n=5 : M'=4 | port blanc
n=6 : M'=5 | port bleu
n=7 : M'=6 | port rouge
mots_rev = mots.copy()
mots_rev[4], mots_rev[-1] = mots_rev[-1], mots_rev[4]
ens = CompletionSystem(mots_rev)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 | po
n=1 : M'=2 | po rouge
n=2 : M'=3 | po vert
n=3 : M'=4 | po orange
n=4 : M'=3 | port rouge
n=5 : M'=4 | port blanc
n=6 : M'=5 | port bleu
n=7 : M'=3 | port
mots_court = [m[4:] for m in mots if m.startswith("port") and len(m) > 4]
ens = CompletionSystem(mots_court)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 |  blanc
n=1 : M'=2 |  bleu
n=2 : M'=3 |  rouge
mots_court = [m for m in mots if m != "port"]
ens = CompletionSystem(mots_court)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 | po
n=1 : M'=2 | po rouge
n=2 : M'=3 | po vert
n=3 : M'=4 | po orange
n=4 : M'=3 | port blanc
n=5 : M'=4 | port bleu
n=6 : M'=5 | port rouge
couleur = ["blanc", "vert", "orange", "rouge", "noir", "noire", "blanche"]
key = "portes"
mots = ["port", "port rouge", "port vert", "port orange", "pore", "pour"]
mots.append(key)
mots += [key + " " + c for c in couleur]
ens = CompletionSystem(mots)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 | port
n=1 : M'=2 | port rouge
n=2 : M'=3 | port vert
n=3 : M'=4 | port orange
n=4 : M'=4 | pore
n=5 : M'=4 | pour
n=6 : M'=3 | portes
n=7 : M'=4 | portes blanc
n=8 : M'=5 | portes vert
n=9 : M'=6 | portes orange
n=10 : M'=6 | portes rouge
n=11 : M'=6 | portes noir
n=12 : M'=7 | portes noire
n=13 : M'=5 | portes blanche
mots2 = [m for m in mots if m != "portes"]
ens = CompletionSystem(mots2)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 | port
n=1 : M'=2 | port rouge
n=2 : M'=3 | port vert
n=3 : M'=4 | port orange
n=4 : M'=4 | pore
n=5 : M'=4 | pour
n=6 : M'=3 | portes blanc
n=7 : M'=4 | portes vert
n=8 : M'=5 | portes orange
n=9 : M'=6 | portes rouge
n=10 : M'=6 | portes noir
n=11 : M'=7 | portes noire
n=12 : M'=4 | portes blanche
mots3 = mots2.copy()
mots3.insert(1, "portes")
ens = CompletionSystem(mots3)
ens.compute_metrics()
for el in ens:
    print("n={1} : M'={0} | {2}".format(el.mks1, el.weight, el.value))
n=0 : M'=1 | port
n=1 : M'=2 | portes
n=2 : M'=3 | port rouge
n=3 : M'=4 | port vert
n=4 : M'=4 | port orange
n=5 : M'=4 | pore
n=6 : M'=4 | pour
n=7 : M'=3 | portes blanc
n=8 : M'=4 | portes vert
n=9 : M'=5 | portes orange
n=10 : M'=5 | portes rouge
n=11 : M'=5 | portes noir
n=12 : M'=6 | portes noire
n=13 : M'=4 | portes blanche