Views
No views yet
1from transformers import AutoTokenizer, AutoModelForTokenClassification
2
3tokenizer = AutoTokenizer.from_pretrained("Jean-Baptiste/camembert-ner-with-dates")
4model = AutoModelForTokenClassification.from_pretrained("Jean-Baptiste/camembert-ner-with-dates")
5
6
7##### Process text sample (from wikipedia)
8
9from transformers import pipeline
10
11nlp = pipeline('ner', model=model, tokenizer=tokenizer, aggregation_strategy="simple")
12nlp("Apple est créée le 1er avril 1976 dans le garage de la maison d'enfance de Steve Jobs à Los Altos en Californie par Steve Jobs, Steve Wozniak et Ronald Wayne14, puis constituée sous forme de société le 3 janvier 1977 à l'origine sous le nom d'Apple Computer, mais pour ses 30 ans et pour refléter la diversification de ses produits, le mot « computer » est retiré le 9 janvier 2015.")
13
14
15[{'entity_group': 'ORG',
16 'score': 0.9776379466056824,
17 'word': 'Apple',
18 'start': 0,
19 'end': 5},
20 {'entity_group': 'DATE',
21 'score': 0.9793774570737567,
22 'word': 'le 1er avril 1976 dans le',
23 'start': 15,
24 'end': 41},
25 {'entity_group': 'PER',
26 'score': 0.9958226680755615,
27 'word': 'Steve Jobs',
28 'start': 74,
29 'end': 85},
30 {'entity_group': 'LOC',
31 'score': 0.995087186495463,
32 'word': 'Los Altos',
33 'start': 87,
34 'end': 97},
35 {'entity_group': 'LOC',
36 'score': 0.9953305125236511,
37 'word': 'Californie',
38 'start': 100,
39 'end': 111},
40 {'entity_group': 'PER',
41 'score': 0.9961076378822327,
42 'word': 'Steve Jobs',
43 'start': 115,
44 'end': 126},
45 {'entity_group': 'PER',
46 'score': 0.9960325956344604,
47 'word': 'Steve Wozniak',
48 'start': 127,
49 'end': 141},
50 {'entity_group': 'PER',
51 'score': 0.9957776467005411,
52 'word': 'Ronald Wayne',
53 'start': 144,
54 'end': 157},
55 {'entity_group': 'DATE',
56 'score': 0.994030773639679,
57 'word': 'le 3 janvier 1977 à',
58 'start': 198,
59 'end': 218},
60 {'entity_group': 'ORG',
61 'score': 0.9720810294151306,
62 'word': "d'Apple Computer",
63 'start': 240,
64 'end': 257},
65 {'entity_group': 'DATE',
66 'score': 0.9924157659212748,
67 'word': '30 ans et',
68 'start': 272,
69 'end': 282},
70 {'entity_group': 'DATE',
71 'score': 0.9934852868318558,
72 'word': 'le 9 janvier 2015.',
73 'start': 363,
74 'end': 382}]
75'precision': 0.928
'recall': 0.928
'f1': 0.928Label LOC: (precision:0.929, recall:0.932, f1:0.931, support:9510)
Label PER: (precision:0.952, recall:0.965, f1:0.959, support:9399)
Label MISC: (precision:0.878, recall:0.844, f1:0.860, support:5364)
Label ORG: (precision:0.848, recall:0.883, f1:0.865, support:2299)
Label DATE: Not relevant because of method used to add date tag on wikiner dataset (estimated f1 ~90%)