.. _completionsimplerst: ================= Complétion Simple ================= .. only:: html **Links:** :download:`notebook `, :downloadlink:`html `, :download:`PDF `, :download:`python `, :downloadlink:`slides `, :githublink:`GitHub|_doc/notebooks/nlp/completion_simple.ipynb|*` Evaluation d’une métrique pour un système de complétion sur quelques cas simples. .. code:: ipython3 from jyquickhelper import add_notebook_menu add_notebook_menu() .. contents:: :local: Métrique M’ ----------- .. code:: ipython3 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)) .. parsed-literal:: 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 .. code:: ipython3 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)) .. parsed-literal:: 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 .. code:: ipython3 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)) .. parsed-literal:: n=0 : M'=1 | blanc n=1 : M'=2 | bleu n=2 : M'=3 | rouge .. code:: ipython3 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)) .. parsed-literal:: 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 .. code:: ipython3 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)) .. parsed-literal:: 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 .. code:: ipython3 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)) .. parsed-literal:: 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 .. code:: ipython3 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)) .. parsed-literal:: 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