emanuelaboros commited on
Commit
dd5a61f
·
verified ·
1 Parent(s): 906dab9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +21 -24
README.md CHANGED
@@ -22,9 +22,9 @@ You can use this model with Transformers *pipeline* for NER.
22
 
23
  <!-- Provide a longer summary of what this model is. -->
24
  ```python
25
- # Import necessary modules from the transformers library
26
- from transformers import pipeline
27
  from transformers import AutoModelForTokenClassification, AutoTokenizer
 
28
 
29
  # Define the model name to be used for token classification, we use the Impresso NER
30
  # that can be found at "https://huggingface.co/impresso-project/ner-stacked-bert-multilingual"
@@ -37,28 +37,25 @@ ner_pipeline = pipeline("generic-ner", model=MODEL_NAME,
37
  tokenizer=ner_tokenizer,
38
  trust_remote_code=True,
39
  device='cpu')
40
- sentences = ["""In the year 1789, King Louis XVI, ruler of France, convened the Estates-General at the Palace of Versailles,
41
- where Marie Antoinette, the Queen of France, alongside Maximilien Robespierre, a leading member of the National Assembly,
42
- debated with Jean-Jacques Rousseau, the famous philosopher, and Charles de Talleyrand, the Bishop of Autun,
43
- regarding the future of the French monarchy. At the same time, across the Atlantic in Philadelphia,
44
- George Washington, the first President of the United States, and Thomas Jefferson, the nation's Secretary of State,
45
- were drafting policies for the newly established American government following the signing of the Constitution."""]
46
-
47
- print(sentences[0])
48
-
49
- # Helper function to print entities one per row
50
- def print_nicely(entities):
51
- for entity in entities:
52
- print(f"Entity: {entity['entity']} | Confidence: {entity['score']:.2f}% | Text: {entity['word'].strip()} | Start: {entity['start']} | End: {entity['end']}")
53
-
54
- # Visualize stacked entities for each sentence
55
- for sentence in sentences:
56
- results = ner_pipeline(sentence)
57
-
58
- # Extract coarse and fine entities
59
- for key in results.keys():
60
- # Visualize the coarse entities
61
- print_nicely(results[key])
62
  ```
63
 
64
 
 
22
 
23
  <!-- Provide a longer summary of what this model is. -->
24
  ```python
25
+ # Import necessary Python modules from the Transformers library
 
26
  from transformers import AutoModelForTokenClassification, AutoTokenizer
27
+ from transformers import pipeline
28
 
29
  # Define the model name to be used for token classification, we use the Impresso NER
30
  # that can be found at "https://huggingface.co/impresso-project/ner-stacked-bert-multilingual"
 
37
  tokenizer=ner_tokenizer,
38
  trust_remote_code=True,
39
  device='cpu')
40
+
41
+ sentence = "En l'an 1348, au plus fort des ravages de la peste noire à travers l'Europe, le Royaume de France se trouvait à la fois au bord du désespoir et face à une opportunité. À la cour du roi Philippe VI, les murs du Louvre étaient animés par les rapports sombres venus de Paris et des villes environnantes. La peste ne montrait aucun signe de répit, et le chancelier Guillaume de Nogaret, le conseiller le plus fidèle du roi, portait le lourd fardeau de gérer la survie du royaume."
42
+
43
+ entities = ner_pipeline(sentence)
44
+ print(entities)
45
+ ```
46
+
47
+ ```
48
+ [
49
+ {'type': 'time.date.abs', 'score': 85.0, 'index': (0, 5), 'surface': "En l'an 1348", 'start': 0, 'end': 12, 'lOffset': 0, 'rOffset': 12},
50
+ {'type': 'loc.adm.nat', 'score': 90.75, 'index': (19, 20), 'surface': 'Europe', 'start': 69, 'end': 75, 'lOffset': 0, 'rOffset': 6},
51
+ {'type': 'loc', 'score': 75.45, 'index': (22, 25), 'surface': 'Royaume de France', 'start': 80, 'end': 97, 'lOffset': 0, 'rOffset': 17},
52
+ {'type': 'pers.ind', 'score': 85.27, 'index': (44, 47), 'surface': 'roi Philippe VI', 'start': 181, 'end': 196, 'lOffset': 0, 'rOffset': 15, 'title': 'roi', 'name': 'roi Philippe VI'},
53
+ {'type': 'loc.adm.town', 'score': 30.59, 'index': (51, 52), 'surface': 'Louvre', 'start': 210, 'end': 216, 'lOffset': 0, 'rOffset': 6},
54
+ {'type': 'loc.adm.town', 'score': 94.46, 'index': (60, 61), 'surface': 'Paris', 'start': 266, 'end': 271, 'lOffset': 0, 'rOffset': 5},
55
+ {'type': 'pers.ind', 'score': 96.1, 'index': (77, 81), 'surface': 'chancelier Guillaume de Nogaret', 'start': 350, 'end': 381, 'lOffset': 0, 'rOffset': 31, 'title': 'chancelier', 'name': 'chancelier Guillaume de Nogaret'},
56
+ {'type': 'loc.adm.nat', 'score': 49.35, 'index': (22, 23), 'surface': 'Royaume', 'start': 80, 'end': 87, 'lOffset': 0, 'rOffset': 7},
57
+ {'type': 'loc.adm.nat', 'score': 24.18, 'index': (24, 25), 'surface': 'France', 'start': 91, 'end': 97, 'lOffset': 0, 'rOffset': 6}]
58
+
 
 
 
59
  ```
60
 
61