abdullahmubeen10 commited on
Commit
1eb93bf
·
verified ·
1 Parent(s): f3ae920

Upload 5 files

Browse files
.streamlit/config.toml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [theme]
2
+ base="light"
3
+ primaryColor="#29B4E8"
Demo.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sparknlp
3
+ import os
4
+ import pandas as pd
5
+
6
+ from sparknlp.base import *
7
+ from sparknlp.annotator import *
8
+ from pyspark.ml import Pipeline
9
+ from sparknlp.pretrained import PretrainedPipeline
10
+ from annotated_text import annotated_text
11
+
12
+ # Page configuration
13
+ st.set_page_config(
14
+ layout="wide",
15
+ page_title="Spark NLP Demos App",
16
+ initial_sidebar_state="auto"
17
+ )
18
+
19
+ # CSS for styling
20
+ st.markdown("""
21
+ <style>
22
+ .main-title {
23
+ font-size: 36px;
24
+ color: #4A90E2;
25
+ font-weight: bold;
26
+ text-align: center;
27
+ }
28
+ .section p, .section ul {
29
+ color: #666666;
30
+ }
31
+ </style>
32
+ """, unsafe_allow_html=True)
33
+
34
+ @st.cache_resource
35
+ def init_spark():
36
+ return sparknlp.start()
37
+
38
+ @st.cache_resource
39
+ def create_pipeline(model):
40
+ document_assembler = DocumentAssembler() \
41
+ .setInputCol("text") \
42
+ .setOutputCol("document")
43
+
44
+ tokenizer = Tokenizer() \
45
+ .setInputCols(["document"]) \
46
+ .setOutputCol("token")
47
+
48
+ embeddings = WordEmbeddingsModel.pretrained('glove_840B_300', lang='xx') \
49
+ .setInputCols(["document", "token"]) \
50
+ .setOutputCol("embeddings")
51
+
52
+ ner_model = NerDLModel.pretrained(model, 'xx') \
53
+ .setInputCols(["document", "token", "embeddings"]) \
54
+ .setOutputCol("ner")
55
+
56
+ ner_converter = NerConverter() \
57
+ .setInputCols(["document", "token", "ner"]) \
58
+ .setOutputCol("ner_chunk")
59
+
60
+ pipeline = Pipeline(stages=[
61
+ document_assembler,
62
+ tokenizer,
63
+ embeddings,
64
+ ner_model,
65
+ ner_converter
66
+ ])
67
+
68
+ return pipeline
69
+
70
+ def fit_data(pipeline, data):
71
+ empty_df = spark.createDataFrame([['']]).toDF('text')
72
+ pipeline_model = pipeline.fit(empty_df)
73
+ model = LightPipeline(pipeline_model)
74
+ result = model.fullAnnotate(data)
75
+ return result
76
+
77
+ def annotate(data):
78
+ document, chunks, labels = data["Document"], data["NER Chunk"], data["NER Label"]
79
+ annotated_words = []
80
+ for chunk, label in zip(chunks, labels):
81
+ parts = document.split(chunk, 1)
82
+ if parts[0]:
83
+ annotated_words.append(parts[0])
84
+ annotated_words.append((chunk, label))
85
+ document = parts[1]
86
+ if document:
87
+ annotated_words.append(document)
88
+ annotated_text(*annotated_words)
89
+
90
+ # Set up the page layout
91
+ st.markdown('<div class="main-title">Reconnaître les personnes, lieux, organisations et entités diverses</div>', unsafe_allow_html=True)
92
+
93
+ # Sidebar content
94
+ model = st.sidebar.selectbox(
95
+ "Choose the pretrained model",
96
+ ["ner_wikiner_glove_840B_300"],
97
+ help="For more info about the models visit: https://sparknlp.org/models"
98
+ )
99
+
100
+ # Reference notebook link in sidebar
101
+ link = """
102
+ <a href="https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/streamlit_notebooks/NER_FR.ipynb">
103
+ <img src="https://colab.research.google.com/assets/colab-badge.svg" style="zoom: 1.3" alt="Open In Colab"/>
104
+ </a>
105
+ """
106
+ st.sidebar.markdown('Reference notebook:')
107
+ st.sidebar.markdown(link, unsafe_allow_html=True)
108
+
109
+ # Load examples
110
+ examples = [
111
+ """William Henry Gates III (né le 28 octobre 1955) est un magnat des affaires, développeur de logiciels, investisseur et philanthrope américain. Il est surtout connu comme le co-fondateur de Microsoft Corporation. Au cours de sa carrière chez Microsoft, Gates a occupé les postes de président, chef de la direction (PDG), président et architecte logiciel en chef, tout en étant le plus grand actionnaire individuel jusqu'en mai 2014. Il est l'un des entrepreneurs et pionniers les plus connus du révolution des micro-ordinateurs des années 1970 et 1980. Né et élevé à Seattle, Washington, Gates a cofondé Microsoft avec son ami d'enfance Paul Allen en 1975, à Albuquerque, au Nouveau-Mexique; il est devenu la plus grande société de logiciels informatiques au monde. Gates a dirigé l'entreprise en tant que président-directeur général jusqu'à sa démission en tant que PDG en janvier 2000, mais il est resté président et est devenu architecte logiciel en chef. À la fin des années 1990, Gates avait été critiqué pour ses tactiques commerciales, considérées comme anticoncurrentielles. Cette opinion a été confirmée par de nombreuses décisions de justice. En juin 2006, Gates a annoncé qu'il passerait à un poste à temps partiel chez Microsoft et à un emploi à temps plein à la Bill & Melinda Gates Foundation, la fondation caritative privée que lui et sa femme, Melinda Gates, ont créée en 2000. [ 9] Il a progressivement transféré ses fonctions à Ray Ozzie et Craig Mundie. Il a démissionné de son poste de président de Microsoft en février 2014 et a assumé un nouveau poste de conseiller technologique pour soutenir le nouveau PDG Satya Nadella.""",
112
+ """La Joconde est une peinture à l'huile du XVIe siècle créée par Léonard. Il se tient au Louvre à Paris.""",
113
+ """Lorsque Sebastian Thrun a commencé à travailler sur les voitures autonomes chez Google en 2007, peu de personnes en dehors de l'entreprise l'ont pris au sérieux. "Je peux vous dire que des PDG très importants de grands constructeurs automobiles américains me serreraient la main et se détourneraient parce que je n'en valais pas la peine", a déclaré Thrun, désormais co-fondateur et PDG de la startup en ligne d'enseignement supérieur Udacity, dans une interview. avec Recode plus tôt cette semaine.""",
114
+ """Facebook est un service de réseautage social lancé sous le nom de TheFacebook le 4 février 2004. Il a été fondé par Mark Zuckerberg avec ses colocataires et ses collègues étudiants de l'Université Harvard Eduardo Saverin, Andrew McCollum, Dustin Moskovitz et Chris Hughes. L'adhésion au site Web a été initialement limitée par les fondateurs aux étudiants de Harvard, mais a été étendue à d'autres collèges de la région de Boston, à l'Ivy League et, progressivement, à la plupart des universités des États-Unis et du Canada.""",
115
+ """L'histoire du traitement du langage naturel a généralement commencé dans les années 1950, bien que l'on puisse trouver du travail de périodes antérieures. En 1950, Alan Turing a publié un article intitulé «Computing Machinery and Intelligence» qui proposait ce qu'on appelle maintenant le test de Turing comme critère d'intelligence""",
116
+ """Geoffrey Everest Hinton est un psychologue cognitif et un informaticien canadien-anglais, surtout connu pour ses travaux sur les réseaux de neurones artificiels. Depuis 2013, il partage son temps à travailler pour Google et l'Université de Toronto. En 2017, il a cofondé et est devenu le conseiller scientifique en chef du Vector Institute de Toronto.""",
117
+ """Quand j'ai dit à John que je voulais déménager en Alaska, il m'a prévenu que j'aurais du mal à trouver un Starbucks là-bas.""",
118
+ """Steven Paul Jobs était un magnat des affaires américain, designer industriel, investisseur et propriétaire de médias. Il était président du conseil, chef de la direction (PDG) et cofondateur d'Apple Inc., président et actionnaire majoritaire de Pixar, membre du conseil d'administration de The Walt Disney Company à la suite de son acquisition de Pixar, et fondateur, président et PDG de NeXT. Jobs est largement reconnu comme un pionnier de la révolution informatique personnelle des années 1970 et 1980, avec le cofondateur d'Apple, Steve Wozniak. Jobs est né à San Francisco, en Californie, et mis en adoption. Il a été élevé dans la région de la baie de San Francisco. Il a fréquenté le Reed College en 1972 avant d'abandonner la même année et a voyagé à travers l'Inde en 1974 à la recherche de l'illumination et de l'étude du bouddhisme zen.""",
119
+ """Titanic est un film épique et romantique américain de 1997 réalisé, écrit, coproduit et co-édité par James Cameron. Intégrant à la fois des aspects historiques et fictifs, il est basé sur des récits du naufrage du RMS Titanic et met en vedette Leonardo DiCaprio et Kate Winslet en tant que membres de différentes classes sociales qui tombent amoureux à bord du navire pendant son voyage inaugural malheureux.""",
120
+ """En plus d'être le roi du nord, John Snow est un médecin anglais et un leader dans le développement de l'anesthésie et de l'hygiène médicale. Il est considéré comme le premier à utiliser des données pour guérir l'épidémie de choléra en 1834."""
121
+ ]
122
+
123
+ selected_text = st.selectbox("Select an example", examples)
124
+ custom_input = st.text_input("Try it with your own Sentence!")
125
+
126
+ text_to_analyze = custom_input if custom_input else selected_text
127
+
128
+ st.subheader('Full example text')
129
+ HTML_WRAPPER = """<div class="scroll entities" style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem; white-space:pre-wrap">{}</div>"""
130
+ st.markdown(HTML_WRAPPER.format(text_to_analyze), unsafe_allow_html=True)
131
+
132
+ # Initialize Spark and create pipeline
133
+ spark = init_spark()
134
+ pipeline = create_pipeline(model)
135
+ output = fit_data(pipeline, text_to_analyze)
136
+
137
+ # Display matched sentence
138
+ st.subheader("Processed output:")
139
+
140
+ results = {
141
+ 'Document': output[0]['document'][0].result,
142
+ 'NER Chunk': [n.result for n in output[0]['ner_chunk']],
143
+ "NER Label": [n.metadata['entity'] for n in output[0]['ner_chunk']]
144
+ }
145
+
146
+ annotate(results)
147
+
148
+ with st.expander("View DataFrame"):
149
+ df = pd.DataFrame({'NER Chunk': results['NER Chunk'], 'NER Label': results['NER Label']})
150
+ df.index += 1
151
+ st.dataframe(df)
152
+
Dockerfile ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Download base image ubuntu 18.04
2
+ FROM ubuntu:18.04
3
+
4
+ # Set environment variables
5
+ ENV NB_USER jovyan
6
+ ENV NB_UID 1000
7
+ ENV HOME /home/${NB_USER}
8
+
9
+ # Install required packages
10
+ RUN apt-get update && apt-get install -y \
11
+ tar \
12
+ wget \
13
+ bash \
14
+ rsync \
15
+ gcc \
16
+ libfreetype6-dev \
17
+ libhdf5-serial-dev \
18
+ libpng-dev \
19
+ libzmq3-dev \
20
+ python3 \
21
+ python3-dev \
22
+ python3-pip \
23
+ unzip \
24
+ pkg-config \
25
+ software-properties-common \
26
+ graphviz \
27
+ openjdk-8-jdk \
28
+ ant \
29
+ ca-certificates-java \
30
+ && apt-get clean \
31
+ && update-ca-certificates -f;
32
+
33
+ # Install Python 3.8 and pip
34
+ RUN add-apt-repository ppa:deadsnakes/ppa \
35
+ && apt-get update \
36
+ && apt-get install -y python3.8 python3-pip \
37
+ && apt-get clean;
38
+
39
+ # Set up JAVA_HOME
40
+ ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
41
+ RUN mkdir -p ${HOME} \
42
+ && echo "export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/" >> ${HOME}/.bashrc \
43
+ && chown -R ${NB_UID}:${NB_UID} ${HOME}
44
+
45
+ # Create a new user named "jovyan" with user ID 1000
46
+ RUN useradd -m -u ${NB_UID} ${NB_USER}
47
+
48
+ # Switch to the "jovyan" user
49
+ USER ${NB_USER}
50
+
51
+ # Set home and path variables for the user
52
+ ENV HOME=/home/${NB_USER} \
53
+ PATH=/home/${NB_USER}/.local/bin:$PATH
54
+
55
+ # Set the working directory to the user's home directory
56
+ WORKDIR ${HOME}
57
+
58
+ # Upgrade pip and install Python dependencies
59
+ RUN python3.8 -m pip install --upgrade pip
60
+ COPY requirements.txt /tmp/requirements.txt
61
+ RUN python3.8 -m pip install -r /tmp/requirements.txt
62
+
63
+ # Copy the application code into the container at /home/jovyan
64
+ COPY --chown=${NB_USER}:${NB_USER} . ${HOME}
65
+
66
+ # Expose port for Streamlit
67
+ EXPOSE 7860
68
+
69
+ # Define the entry point for the container
70
+ ENTRYPOINT ["streamlit", "run", "Demo.py", "--server.port=7860", "--server.address=0.0.0.0"]
pages/Workflow & Model Overview.py ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Custom CSS for better styling
4
+ st.markdown("""
5
+ <style>
6
+ .main-title {
7
+ font-size: 36px;
8
+ color: #4A90E2;
9
+ font-weight: bold;
10
+ text-align: center;
11
+ }
12
+ .sub-title {
13
+ font-size: 24px;
14
+ color: #4A90E2;
15
+ margin-top: 20px;
16
+ }
17
+ .section {
18
+ background-color: #f9f9f9;
19
+ padding: 15px;
20
+ border-radius: 10px;
21
+ margin-top: 20px;
22
+ }
23
+ .section h2 {
24
+ font-size: 22px;
25
+ color: #4A90E2;
26
+ }
27
+ .section p, .section ul {
28
+ color: #666666;
29
+ }
30
+ .link {
31
+ color: #4A90E2;
32
+ text-decoration: none;
33
+ }
34
+ </style>
35
+ """, unsafe_allow_html=True)
36
+
37
+ # Main Title
38
+ st.markdown('<div class="main-title">State-of-the-Art Named Entity Recognition with Spark NLP (French)</div>', unsafe_allow_html=True)
39
+
40
+ # Introduction
41
+ st.markdown("""
42
+ <div class="section">
43
+ <p>Named Entity Recognition (NER) is the task of identifying important words in a text and associating them with a category. For example, we may be interested in finding all the personal names in documents, or company names in news articles. Other examples include domain-specific uses such as identifying all disease names in a clinical text, or company trading codes in financial ones.</p>
44
+ <p>NER can be implemented with many approaches. In this post, we introduce a deep learning-based method using the NerDL model. This approach leverages the scalability of Spark NLP with Python.</p>
45
+ </div>
46
+ """, unsafe_allow_html=True)
47
+
48
+ # Introduction to Spark NLP
49
+ st.markdown('<div class="sub-title">Introduction to Spark NLP</div>', unsafe_allow_html=True)
50
+ st.markdown("""
51
+ <div class="section">
52
+ <p>Spark NLP is an open-source library maintained by John Snow Labs. It is built on top of Apache Spark and Spark ML and provides simple, performant & accurate NLP annotations for machine learning pipelines that can scale easily in a distributed environment.</p>
53
+ <p>To install Spark NLP, you can simply use any package manager like conda or pip. For example, using pip you can simply run <code>pip install spark-nlp</code>. For different installation options, check the official <a href="https://nlp.johnsnowlabs.com/docs/en/install" target="_blank" class="link">documentation</a>.</p>
54
+ </div>
55
+ """, unsafe_allow_html=True)
56
+
57
+ # Using NerDL Model
58
+ st.markdown('<div class="sub-title">Using NerDL Model</div>', unsafe_allow_html=True)
59
+ st.markdown("""
60
+ <div class="section">
61
+ <p>The NerDL model in Spark NLP is a deep learning-based approach for NER tasks. It uses a Char CNNs - BiLSTM - CRF architecture that achieves state-of-the-art results in most datasets. The training data should be a labeled Spark DataFrame in the format of CoNLL 2003 IOB with annotation type columns.</p>
62
+ </div>
63
+ """, unsafe_allow_html=True)
64
+
65
+ # Setup Instructions
66
+ st.markdown('<div class="sub-title">Setup</div>', unsafe_allow_html=True)
67
+ st.markdown('<p>To install Spark NLP in Python, use your favorite package manager (conda, pip, etc.). For example:</p>', unsafe_allow_html=True)
68
+ st.code("""
69
+ pip install spark-nlp
70
+ pip install pyspark
71
+ """, language="bash")
72
+
73
+ st.markdown("<p>Then, import Spark NLP and start a Spark session:</p>", unsafe_allow_html=True)
74
+ st.code("""
75
+ import sparknlp
76
+
77
+ # Start Spark Session
78
+ spark = sparknlp.start()
79
+ """, language='python')
80
+
81
+ # Example Usage with NerDL Model in Italian
82
+ st.markdown('<div class="sub-title">Example Usage with NerDL Model in Italian</div>', unsafe_allow_html=True)
83
+ st.markdown("""
84
+ <div class="section">
85
+ <p>Below is an example of how to set up and use the NerDL model for named entity recognition in Italian:</p>
86
+ </div>
87
+ """, unsafe_allow_html=True)
88
+ st.code('''
89
+ from sparknlp.base import *
90
+ from sparknlp.annotator import *
91
+ from pyspark.ml import Pipeline
92
+ from pyspark.sql.functions import col, expr, round, concat, lit
93
+
94
+ # Document Assembler
95
+ document_assembler = DocumentAssembler() \\
96
+ .setInputCol("text") \\
97
+ .setOutputCol("document")
98
+
99
+ # Tokenizer
100
+ tokenizer = Tokenizer() \\
101
+ .setInputCols(["document"]) \\
102
+ .setOutputCol("token")
103
+
104
+ # Word Embeddings
105
+ embeddings = WordEmbeddingsModel.pretrained('glove_840B_300', lang='xx') \\
106
+ .setInputCols(["document", "token"]) \\
107
+ .setOutputCol("embeddings")
108
+
109
+ # NerDL Model
110
+ ner_model = NerDLModel.pretrained('ner_wikiner_glove_840B_300', 'xx') \\
111
+ .setInputCols(["document", "token", "embeddings"]) \\
112
+ .setOutputCol("ner")
113
+
114
+ # NER Converter
115
+ ner_converter = NerConverter() \\
116
+ .setInputCols(["document", "token", "ner"]) \\
117
+ .setOutputCol("ner_chunk")
118
+
119
+ # Pipeline
120
+ pipeline = Pipeline(stages=[
121
+ document_assembler,
122
+ tokenizer,
123
+ embeddings,
124
+ ner_model,
125
+ ner_converter
126
+ ])
127
+
128
+ # Example sentence
129
+ example = """William Henry Gates III (* 28. Oktober 1955 in London) ist ein US-amerikanischer Geschäftsmann, Softwareentwickler, Investor und Philanthrop. Er ist bekannt als Mitbegründer der Microsoft Corporation. Während seiner Karriere bei Microsoft war Gates Vorsitzender, Chief Executive Officer (CEO), Präsident und Chief Software Architect und bis Mai 2014 der größte Einzelaktionär. Er ist einer der bekanntesten Unternehmer und Pioniere der Mikrocomputer-Revolution der 1970er und 1980er Jahre. Gates wurde in Seattle, Washington, geboren und wuchs dort auf. 1975 gründete er Microsoft zusammen mit seinem Freund aus Kindertagen, Paul Allen, in Albuquerque, New Mexico. Es entwickelte sich zum weltweit größten Unternehmen für Personal-Computer-Software. Gates leitete das Unternehmen als Chairman und CEO, bis er im Januar 2000 als CEO zurücktrat. Er blieb jedoch Chairman und wurde Chief Software Architect. In den späten neunziger Jahren wurde Gates für seine Geschäftstaktiken kritisiert, die als wettbewerbswidrig angesehen wurden. Diese Meinung wurde durch zahlreiche Gerichtsurteile bestätigt. Im Juni 2006 gab Gates bekannt, dass er eine Teilzeitstelle bei Microsoft und eine Vollzeitstelle bei der Bill & Melinda Gates Foundation, der privaten gemeinnützigen Stiftung, die er und seine Frau Melinda Gates im Jahr 2000 gegründet haben, übernehmen wird. [ 9] Er übertrug seine Aufgaben nach und nach auf Ray Ozzie und Craig Mundie. Im Februar 2014 trat er als Vorsitzender von Microsoft zurück und übernahm eine neue Position als Technologieberater, um den neu ernannten CEO Satya Nadella zu unterstützen."""
130
+ data = spark.createDataFrame([[example]]).toDF("text")
131
+
132
+ # Transforming data
133
+ result = pipeline.fit(data).transform(data)
134
+
135
+ # Select the result, entity, and confidence columns
136
+ result.select(
137
+ expr("explode(ner_chunk) as ner_chunk")
138
+ ).select(
139
+ col("ner_chunk.result").alias("result"),
140
+ col("ner_chunk.metadata").getItem("entity").alias("entity"),
141
+ concat(
142
+ round((col("ner_chunk.metadata").getItem("confidence").cast("float") * 100), 2),
143
+ lit("%")
144
+ ).alias("confidence")
145
+ ).show(truncate=False)
146
+ ''', language="python")
147
+
148
+ st.text("""
149
+ +-------------------------------+------+----------+
150
+ |result |entity|confidence|
151
+ +-------------------------------+------+----------+
152
+ |William Henry Gates III |PER |57.6% |
153
+ |London |LOC |91.51% |
154
+ |US-amerikanischer |MISC |99.56% |
155
+ |Microsoft Corporation |ORG |72.69% |
156
+ |Microsoft |ORG |98.13% |
157
+ |Gates |PER |93.14% |
158
+ |Gates |PER |77.17% |
159
+ |Seattle |LOC |89.12% |
160
+ |Washington |LOC |73.5% |
161
+ |Microsoft |ORG |95.15% |
162
+ |Paul Allen |PER |85.83% |
163
+ |Albuquerque |LOC |84.27% |
164
+ |New Mexico |LOC |67.22% |
165
+ |Gates |PER |97.12% |
166
+ |Gates |PER |97.68% |
167
+ |Gates |PER |98.26% |
168
+ |Microsoft |ORG |98.1% |
169
+ |Bill & Melinda Gates Foundation|MISC |42.91% |
170
+ |Melinda Gates |PER |87.0% |
171
+ |Ray Ozzie |PER |83.86% |
172
+ +-------------------------------+------+----------+
173
+ """)
174
+
175
+ # Benchmark Section
176
+ st.markdown('<div class="sub-title">Benchmark</div>', unsafe_allow_html=True)
177
+ st.markdown("""
178
+ <div class="section">
179
+ <p>Evaluating the performance of NER models is crucial to understanding their effectiveness in real-world applications. Below are the benchmark results for the "ner_wikiner_glove_840B_300" model on <strong>French</strong> text, focusing on various named entity categories. The metrics used include precision, recall, and F1-score, which are standard for evaluating classification models.</p>
180
+ </div>
181
+ """, unsafe_allow_html=True)
182
+ st.markdown("""
183
+ ---
184
+ #### Classification Report
185
+
186
+ | Label | Precision | Recall | F1-Score | Support |
187
+ |-------|-----------|--------|----------|---------|
188
+ | B-LOC | 0.81 | 0.87 | 0.84 | 11482 |
189
+ | I-ORG | 0.81 | 0.74 | 0.77 | 2143 |
190
+ | I-LOC | 0.75 | 0.60 | 0.67 | 4495 |
191
+ | I-PER | 0.95 | 0.94 | 0.95 | 5339 |
192
+ | B-ORG | 0.86 | 0.78 | 0.82 | 2556 |
193
+ | B-PER | 0.92 | 0.94 | 0.93 | 7524 |
194
+
195
+ #### Averages
196
+
197
+ | Metric | Precision | Recall | F1-Score | Support |
198
+ |----------------|-----------|--------|----------|---------|
199
+ | Micro Average | 0.86 | 0.85 | 0.85 | 33539 |
200
+ | Macro Average | 0.85 | 0.81 | 0.83 | 33539 |
201
+ | Weighted Avg | 0.86 | 0.85 | 0.85 | 33539 |
202
+
203
+ #### Overall Metrics
204
+
205
+ - Processed 348,522 tokens with 25,499 phrases; found: 25,298 phrases; correct: 21,261.
206
+ - Accuracy (non-O): **80.86%**
207
+ - Overall Accuracy: **97.44%**
208
+ - Precision: **84.04%**
209
+ - Recall: **83.38%**
210
+ - F1 Score: **83.71**
211
+
212
+ #### Entity-Specific Metrics
213
+
214
+ | Entity | Precision | Recall | F1-Score | Instances |
215
+ |--------|-----------|--------|----------|-----------|
216
+ | LOC | 80.06% | 85.79% | 82.83 | 12303 |
217
+ | MISC | 82.42% | 63.25% | 71.57 | 3021 |
218
+ | ORG | 83.49% | 75.59% | 79.34 | 2314 |
219
+ | PER | 91.24% | 92.89% | 92.06 | 7660 |
220
+
221
+ ---
222
+ """, unsafe_allow_html=True)
223
+
224
+ # Summary
225
+ st.markdown('<div class="sub-title">Summary</div>', unsafe_allow_html=True)
226
+ st.markdown("""
227
+ <div class="section">
228
+ <p>In this article, we discussed named entity recognition using a deep learning-based method with the "wikiner_840B_300" model for Italian. We introduced how to perform the task using the open-source Spark NLP library with Python, which can be used at scale in the Spark ecosystem. These methods can be used for natural language processing applications in various fields, including finance and healthcare.</p>
229
+ </div>
230
+ """, unsafe_allow_html=True)
231
+
232
+ # References
233
+ st.markdown('<div class="sub-title">References</div>', unsafe_allow_html=True)
234
+ st.markdown("""
235
+ <div class="section">
236
+ <ul>
237
+ <li><a class="link" href="https://sparknlp.org/api/python/reference/autosummary/sparknlp/annotator/ner/ner_dl/index.html" target="_blank" rel="noopener">NerDLModel</a> annotator documentation</li>
238
+ <li>Model Used: <a class="link" href="https://sparknlp.org/2021/07/19/ner_wikiner_glove_840B_300_xx.html" target="_blank" rel="noopener">ner_wikiner_glove_840B_300</a></li>
239
+ <li><a class="link" href="https://nlp.johnsnowlabs.com/recognize_entitie" target="_blank" rel="noopener">Visualization demos for NER in Spark NLP</a></li>
240
+ <li><a class="link" href="https://www.johnsnowlabs.com/named-entity-recognition-ner-with-bert-in-spark-nlp/">Named Entity Recognition (NER) with BERT in Spark NLP</a></li>
241
+ </ul>
242
+ </div>
243
+ """, unsafe_allow_html=True)
244
+
245
+ # Community & Support
246
+ st.markdown('<div class="sub-title">Community & Support</div>', unsafe_allow_html=True)
247
+ st.markdown("""
248
+ <div class="section">
249
+ <ul>
250
+ <li><a class="link" href="https://sparknlp.org/" target="_blank">Official Website</a>: Documentation and examples</li>
251
+ <li><a class="link" href="https://join.slack.com/t/spark-nlp/shared_invite/zt-198dipu77-L3UWNe_AJf4Rqb3DaMb-7A" target="_blank">Slack Community</a>: Connect with other Spark NLP users</li>
252
+ <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp" target="_blank">GitHub Repository</a>: Source code and issue tracker</li>
253
+ </ul>
254
+ </div>
255
+ """, unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ st-annotated-text
3
+ pandas
4
+ numpy
5
+ spark-nlp
6
+ pyspark