<jupyter_start><jupyter_text>Train Model Spacy<jupyter_code>def train_spacy(data,iterations):
    TRAIN_DATA = data
    nlp = spacy.blank('en')  # create blank Language class
    # create the built-in pipeline components and add them to the pipeline
    # nlp.create_pipe works for built-ins that are registered with spaCy
    if 'ner' not in nlp.pipe_names:
        ner = nlp.create_pipe('ner')
        nlp.add_pipe(ner, last=True)
       

    # add labels
    for _, annotations in TRAIN_DATA:
         for ent in annotations.get('entities'):
            ner.add_label(ent[2])

    # get names of other pipes to disable them during training
    other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner']
    with nlp.disable_pipes(*other_pipes):  # only train NER
        optimizer = nlp.begin_training()
        for itn in range(iterations):
            print("Statring iteration " + str(itn))
            random.shuffle(TRAIN_DATA)
            losses = {}
            for text, annotations in TRAIN_DATA:
                nlp.update(
                    [text],  # batch of texts
                    [annotations],  # batch of annotations
                    drop=0.2,  # dropout - make it harder to memorise data
                    sgd=optimizer,  # callable to update weights
                    losses=losses)
            print(losses)
    return nlp


prdnlp = train_spacy(TRAIN_DATA, 80)<jupyter_output>D:\ANACONDA\envs\PFA\lib\site-packages\spacy\language.py:639: UserWarning: [W033] Training a new parser or NER using a model with an empty lexeme normalization table. This may degrade the performance to some degree. If this is intentional or this language doesn't have a normalization table, please ignore this warning.
  **kwargs
D:\ANACONDA\envs\PFA\lib\site-packages\spacy\language.py:639: UserWarning: [W034] Please install the package spacy-lookups-data in order to include the default lexeme normalization table for the language 'en'.
  **kwargs<jupyter_text>Save Model<jupyter_code>prdnlp.to_disk("C:\PFA-FINALE\preTrained_model")<jupyter_output><empty_output><jupyter_text>Evaluer Model<jupyter_code>def evaluate(ner_model, test_data):
    scorer = Scorer()
    for input_, annot in test_data:
        doc_gold_text = ner_model.make_doc(input_)
        gold = GoldParse(doc_gold_text, entities=annot['entities'])
        pred_value = ner_model(input_)
        scorer.score(pred_value, gold)
    return scorer.scores
output_dir=Path("C:\\PFA-FINALE\\preTrained_model")
nlp2 = spacy.load(output_dir)
results = evaluate(nlp2, TEST_DATA)
#print(json.dumps(results,indent=4))
print(results)<jupyter_output>D:\ANACONDA\envs\PFA\lib\site-packages\ipykernel_launcher.py:5: UserWarning: [W030] Some entities could not be aligned in the text "Je suis <NAME>, j'habite à 68 QUARTIE EL QO..." with entities "[(380, 394, 'numéro téléphone'), (189, 206, 'email...". Use `spacy.gold.biluo_tags_from_offsets(nlp.make_doc(text), entities)` to check the alignment. Misaligned entities (with BILUO tag '-') will be ignored during training.
  """
D:\ANACONDA\envs\PFA\lib\site-packages\ipykernel_launcher.py:5: UserWarning: [W030] Some entities could not be aligned in the text "Je suis <NAME>, j'habite à 14 rue des petites..." with entities "[(274, 288, 'numéro téléphone'), (149, 166, 'email...". Use `spacy.gold.biluo_tags_from_offsets(nlp.make_doc(text), entities)` to check the alignment. Misaligned entities (with BILUO tag '-') will be ignored during training.
  """<jupyter_text>Test de Model<jupyter_code>output_dir=Path("C:\\PFA-FINALE\\preTrained_model")
nlp2 = spacy.load(output_dir)
test_text = input("Enter your testing text: ")
doc = nlp2(test_text)
for ent in doc.ents:
    print(ent.text,"==>", ent.label_)
    #print(ent.text,"==>", ent.start_char, ent.end_char, ent.label_)<jupyter_output>Enter your testing text: Je suis <NAME>, j'habite à 101 BOULEVARD ZAYED,ABOU DABI. Je suis étudiant en médias visuels avec une spécialisation dans la production cinématographique.En effet , mon email est <EMAIL> .Je suis travailleur, diligent et dévoué - toutes les qualités que je mets en avant dans tout ce que je fais. Si vous avez besoin de moi, voilà mon numéro 04 20 21 82 51 n'hésité pas de vous me contactez .
Alfredo ==> prénom
Torres ==> nom
101 BOULEVARD ZAYED,ABOU DABI ==> adresse
<EMAIL> ==> email
04 20 21 82 51 ==> numéro téléphone
{'fraction_non_alphanumeric': 0.10543204217281688, 'fraction_numerical': 0.01925280770112308, 'mean_word_length': 3.7025862068965516, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '568318', 'license': 'Apache-2.0', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1431, 'n_words': 418, 'path': 'Train-Model.ipynb', 'repo_name': 'otmane07/ExDATA', 'size': '4409'}