abdullahmubeen10 commited on
Commit
6336cc6
·
verified ·
1 Parent(s): 5941249

Upload 10 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,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ initial_sidebar_state="auto"
16
+ )
17
+
18
+ # CSS for styling
19
+ st.markdown("""
20
+ <style>
21
+ .main-title {
22
+ font-size: 36px;
23
+ color: #4A90E2;
24
+ font-weight: bold;
25
+ text-align: center;
26
+ }
27
+ .section {
28
+ background-color: #f9f9f9;
29
+ padding: 10px;
30
+ border-radius: 10px;
31
+ margin-top: 10px;
32
+ }
33
+ .section p, .section ul {
34
+ color: #666666;
35
+ }
36
+ </style>
37
+ """, unsafe_allow_html=True)
38
+
39
+ @st.cache_resource
40
+ def init_spark():
41
+ return sparknlp.start()
42
+
43
+ @st.cache_resource
44
+ def create_pipeline(model):
45
+ document_assembler = DocumentAssembler() \
46
+ .setInputCol('text') \
47
+ .setOutputCol('document')
48
+
49
+ sentence_detector = SentenceDetector() \
50
+ .setInputCols(['document']) \
51
+ .setOutputCol('sentence')
52
+
53
+ tokenizer = Tokenizer() \
54
+ .setInputCols(['sentence']) \
55
+ .setOutputCol('token')
56
+
57
+ tokenClassifier_loaded = BertForTokenClassification.pretrained("bert_token_classifier_hi_en_ner", "hi") \
58
+ .setInputCols(["sentence", 'token']) \
59
+ .setOutputCol("ner")
60
+
61
+ ner_converter = NerConverter() \
62
+ .setInputCols(["sentence", "token", "ner"]) \
63
+ .setOutputCol("ner_chunk")
64
+
65
+ # Create the NLP pipeline
66
+ pipeline = Pipeline(stages=[
67
+ document_assembler,
68
+ sentence_detector,
69
+ tokenizer,
70
+ tokenClassifier_loaded,
71
+ ner_converter
72
+ ])
73
+ return pipeline
74
+
75
+ def fit_data(pipeline, data):
76
+ empty_df = spark.createDataFrame([['']]).toDF('text')
77
+ pipeline_model = pipeline.fit(empty_df)
78
+ model = LightPipeline(pipeline_model)
79
+ result = model.fullAnnotate(data)
80
+ return result
81
+
82
+ def annotate(data):
83
+ document, chunks, labels = data["Document"], data["NER Chunk"], data["NER Label"]
84
+ annotated_words = []
85
+ for chunk, label in zip(chunks, labels):
86
+ parts = document.split(chunk, 1)
87
+ if parts[0]:
88
+ annotated_words.append(parts[0])
89
+ annotated_words.append((chunk, label))
90
+ document = parts[1]
91
+ if document:
92
+ annotated_words.append(document)
93
+ annotated_text(*annotated_words)
94
+
95
+ # Sidebar content
96
+ model = st.sidebar.selectbox(
97
+ "Choose the pretrained model",
98
+ ["bert_token_classifier_hi_en_ner"],
99
+ help="For more info about the models visit: https://sparknlp.org/models"
100
+ )
101
+
102
+ # Set up the page layout
103
+ title, sub_title = ('Named Entity Recogniation for Hindi+English text', 'This model was imported from Hugging Face to carry out Name Entity Recognition with mixed Hindi-English texts, provided by the LinCE repository.')
104
+
105
+ st.markdown(f'<div class="main-title">{title}</div>', unsafe_allow_html=True)
106
+ st.markdown(f'<div class="section"><p>{sub_title}</p></div>', unsafe_allow_html=True)
107
+
108
+ # Reference notebook link in sidebar
109
+ link = """
110
+ <a href="https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/streamlit_notebooks/NER_HINDI_ENGLISH.ipynb">
111
+ <img src="https://colab.research.google.com/assets/colab-badge.svg" style="zoom: 1.3" alt="Open In Colab"/>
112
+ </a>
113
+ """
114
+ st.sidebar.markdown('Reference notebook:')
115
+ st.sidebar.markdown(link, unsafe_allow_html=True)
116
+
117
+ # Load examples
118
+ folder_path = f"inputs/{model}"
119
+ examples = [
120
+ lines[1].strip()
121
+ for filename in os.listdir(folder_path)
122
+ if filename.endswith('.txt')
123
+ for lines in [open(os.path.join(folder_path, filename), 'r', encoding='utf-8').readlines()]
124
+ if len(lines) >= 2
125
+ ]
126
+
127
+ selected_text = st.selectbox("Select an example", examples)
128
+ custom_input = st.text_input("Try it with your own Sentence!")
129
+
130
+ text_to_analyze = custom_input if custom_input else selected_text
131
+
132
+ st.subheader('Full example text')
133
+ 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>"""
134
+ st.markdown(HTML_WRAPPER.format(text_to_analyze), unsafe_allow_html=True)
135
+
136
+ # Initialize Spark and create pipeline
137
+ spark = init_spark()
138
+ pipeline = create_pipeline(model)
139
+ output = fit_data(pipeline, text_to_analyze)
140
+
141
+ # Display matched sentence
142
+ st.subheader("Processed output:")
143
+
144
+ results = {
145
+ 'Document': output[0]['document'][0].result,
146
+ 'NER Chunk': [n.result for n in output[0]['ner_chunk']],
147
+ "NER Label": [n.metadata['entity'] for n in output[0]['ner_chunk']]
148
+ }
149
+
150
+ annotate(results)
151
+
152
+ with st.expander("View DataFrame"):
153
+ df = pd.DataFrame({'NER Chunk': results['NER Chunk'], 'NER Label': results['NER Label']})
154
+ df.index += 1
155
+ st.dataframe(df)
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"]
inputs/bert_token_classifier_hi_en_ner/Example1.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ एशियन-पेंट्स लिमिटेड (Asian Paints Limited) एक भारतीय बहुराष्ट्रीय व्यापार है जिसका मुख्यालय मुंबई (...
2
+ एशियन-पेंट्स लिमिटेड (Asian Paints Limited) एक भारतीय बहुराष्ट्रीय व्यापार है जिसका मुख्यालय मुंबई (Mumbai), महाराष्ट्र (Maharashtra) में है। ये व्यापार, रंग, घर की सजावट, फिटिंग से संबंधित उत्पादों और संबंधित सेवाएं प्रदान करने, निर्माण, बिक्री और वितरण के व्यवसाय में लगी हुई है।
inputs/bert_token_classifier_hi_en_ner/Example2.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ रिलायंस इंडस्ट्रीज़ लिमिटेड (Reliance Industries Limited) एक भारतीय संगुटिका नियंत्रक कंपनी है, जिसक...
2
+ रिलायंस इंडस्ट्रीज़ लिमिटेड (Reliance Industries Limited) एक भारतीय संगुटिका नियंत्रक कंपनी है, जिसका मुख्यालय मुंबई, महाराष्ट्र (Maharashtra) में स्थित है।रतन नवल टाटा (28 दिसंबर 1937, को मुम्बई , में जन्मे) टाटा समुह के वर्तमान अध्यक्ष, जो भारत की सबसे बड़ी व्यापारिक समूह है, जिसकी स्थापना जमशेदजी टाटा ने की और उनके परिवार की पीढियों ने इसका विस्तार किया और इसे दृढ़ बनाया।
inputs/bert_token_classifier_hi_en_ner/Example3.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ लियोनेल मेस्सी (Lionel Messi); (जन्म 24 जून 1987) अर्जेंटीना (Argentina) के फ़ुटबॉल खिलाड़ी हैं, जो ...
2
+ लियोनेल मेस्सी (Lionel Messi); (जन्म 24 जून 1987) अर्जेंटीना (Argentina) के फ़ुटबॉल खिलाड़ी हैं, जो इस समय पी.एस.जी टीम पेरिस सेंट-जर्मेन (Paris Saint-Germain Football Club) और अर्जेंटीना (Argentina) की राष्ट्रीय टीम के लिए खेलते हैं।'
inputs/bert_token_classifier_hi_en_ner/Example4.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ क्रिस्टियानो रोनाल्डो (Cristiano Ronaldo), (जन्म: 5 फरवरी 1985), एक पुर्तगाली (Portugal) पेशेवर फुटब...
2
+ क्रिस्टियानो रोनाल्डो (Cristiano Ronaldo), (जन्म: 5 फरवरी 1985), एक पुर्तगाली (Portugal) पेशेवर फुटबॉल खिलाड़ी है, जो मेनचेस्टर यूनाइटेड (Manchester United) के लिए और पुर्तगाल (Portugal) राष्ट्रीय फुटबॉल के कप्तान हैं।
inputs/bert_token_classifier_hi_en_ner/Example5.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ वॉरेन एडवर्ड बफेट (Warren Buffet) (अगस्त 30 (August 30), 1930 को ओमाहा (Omaha), नेब्रास्का (Nebraska...
2
+ वॉरेन एडवर्ड बफेट (Warren Buffet) (अगस्त 30 (August 30), 1930 को ओमाहा (Omaha), नेब्रास्का (Nebraska) में पैदा हुए) एक अमेरिकी निवेशक (investor), व्यवसायी और परोपकारी (philanthropist) व्यक्तित्व हैं।
pages/Workflow & Model Overview.py ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ .benchmark-table {
35
+ width: 100%;
36
+ border-collapse: collapse;
37
+ margin-top: 20px;
38
+ }
39
+ .benchmark-table th, .benchmark-table td {
40
+ border: 1px solid #ddd;
41
+ padding: 8px;
42
+ text-align: left;
43
+ }
44
+ .benchmark-table th {
45
+ background-color: #4A90E2;
46
+ color: white;
47
+ }
48
+ .benchmark-table td {
49
+ background-color: #f2f2f2;
50
+ }
51
+ </style>
52
+ """, unsafe_allow_html=True)
53
+
54
+ # Main Title
55
+ st.markdown('<div class="main-title">Bilingual Named Entity Recognition Model: Hindi and English</div>', unsafe_allow_html=True)
56
+
57
+ # Description
58
+ st.markdown("""
59
+ <div class="section">
60
+ <p>This model, <strong>bert_token_classifier_hi_en_ner</strong>, was imported from Hugging Face to perform Named Entity Recognition (NER) with mixed Hindi-English texts. It is provided by the LinCE repository and is designed to identify named entities in texts containing both Hindi and English.</p>
61
+ </div>
62
+ """, unsafe_allow_html=True)
63
+
64
+ # What is Entity Recognition
65
+ st.markdown('<div class="sub-title">What is Entity Recognition?</div>', unsafe_allow_html=True)
66
+ st.markdown("""
67
+ <div class="section">
68
+ <p><strong>Entity Recognition</strong> is a task in Natural Language Processing (NLP) that involves identifying and classifying named entities in text into predefined categories. This model focuses on detecting terminology related to restaurants, which is essential for understanding and analyzing restaurant reviews, menus, and related content.</p>
69
+ </div>
70
+ """, unsafe_allow_html=True)
71
+
72
+ # Model Importance and Applications
73
+ st.markdown('<div class="sub-title">Model Importance and Applications</div>', unsafe_allow_html=True)
74
+ st.markdown("""
75
+ <div class="section">
76
+ <p>The <strong>bert_token_classifier_hi_en_ner</strong> model is a powerful tool for handling mixed Hindi-English texts. Its applications include:</p>
77
+ <ul>
78
+ <li><strong>Multilingual Text Analysis:</strong> Efficiently processes and analyzes texts that contain both Hindi and English, making it suitable for a diverse range of documents.</li>
79
+ <li><strong>Entity Recognition in Bilingual Contexts:</strong> Identifies and classifies named entities in contexts where Hindi and English are mixed, enhancing understanding in multilingual environments.</li>
80
+ <li><strong>Cross-Language Information Extraction:</strong> Extracts valuable information from documents that are not confined to a single language, providing insights in both Hindi and English.</li>
81
+ <li><strong>Data Enrichment:</strong> Improves datasets by adding valuable entity information from bilingual texts, useful for multilingual data systems and research.</li>
82
+ </ul>
83
+ <p>Why use the <strong>bert_token_classifier_hi_en_ner</strong> model?</p>
84
+ <ul>
85
+ <li><strong>Pre-trained for Mixed Hindi-English:</strong> Specifically trained to handle mixed-language texts, ensuring accurate recognition of entities in both languages.</li>
86
+ <li><strong>High Accuracy:</strong> Delivers reliable results in identifying entities, even in complex bilingual contexts.</li>
87
+ <li><strong>Versatility:</strong> Applicable to a wide range of documents and texts, enhancing its utility in various scenarios.</li>
88
+ </ul>
89
+ </div>
90
+ """, unsafe_allow_html=True)
91
+
92
+ # Predicted Entities
93
+ st.markdown('<div class="sub-title">Predicted Entities</div>', unsafe_allow_html=True)
94
+ st.markdown("""
95
+ <div class="section">
96
+ <p>The model identifies and classifies the following entities:</p>
97
+ <ul>
98
+ <li><strong>ORGANISATION</strong>: Names of organizations or companies.</li>
99
+ <li><strong>PERSON</strong>: Names of people.</li>
100
+ <li><strong>PLACE</strong>: Names of locations or places.</li>
101
+ </ul>
102
+ </div>
103
+ """, unsafe_allow_html=True)
104
+
105
+ # How to Use the Model
106
+ st.markdown('<div class="sub-title">How to Use the Model</div>', unsafe_allow_html=True)
107
+ st.code('''
108
+ from sparknlp.base import *
109
+ from sparknlp.annotator import *
110
+ from pyspark.ml import Pipeline
111
+ from pyspark.sql.functions import col, expr
112
+
113
+ # Define the pipeline stages
114
+ document_assembler = DocumentAssembler() \\
115
+ .setInputCol('text') \\
116
+ .setOutputCol('document')
117
+
118
+ sentence_detector = SentenceDetector() \\
119
+ .setInputCols(['document']) \\
120
+ .setOutputCol('sentence')
121
+
122
+ tokenizer = Tokenizer() \\
123
+ .setInputCols(['sentence']) \\
124
+ .setOutputCol('token')
125
+
126
+ tokenClassifier_loaded = BertForTokenClassification.pretrained("bert_token_classifier_hi_en_ner", "hi") \\
127
+ .setInputCols(["sentence", 'token']) \\
128
+ .setOutputCol("ner")
129
+
130
+ ner_converter = NerConverter() \\
131
+ .setInputCols(["sentence", "token", "ner"]) \\
132
+ .setOutputCol("ner_chunk")
133
+
134
+ # Create the NLP pipeline
135
+ pipeline = Pipeline(stages=[
136
+ document_assembler,
137
+ sentence_detector,
138
+ tokenizer,
139
+ tokenClassifier_loaded,
140
+ ner_converter
141
+ ])
142
+
143
+ # Sample text
144
+ text = """
145
+ रिलायंस इंडस्ट्रीज़ लिमिटेड (Reliance Industries Limited) एक भारतीय संगुटिका नियंत्रक कंपनी है, जिसका मुख्यालय मुंबई, महाराष्ट्र (Maharashtra) में स्थित है।रतन नवल टाटा (28 दिसंबर 1937, को मुम्बई (Mumbai), में जन्मे) टाटा समुह के वर्तमान अध्यक्ष, जो भारत की सबसे बड़ी व्यापारिक समूह है, जिसकी स्थापना जमशेदजी टाटा ने की और उनके परिवार की पीढियों ने इसका विस्तार किया और इसे दृढ़ बनाया।
146
+ """
147
+
148
+ # Create a DataFrame with the text
149
+ data = spark.createDataFrame([[text]]).toDF("text")
150
+
151
+ # Apply the pipeline to the data
152
+ model = pipeline.fit(data)
153
+ result = model.transform(data)
154
+
155
+ # Display results
156
+ result.select(
157
+ expr("explode(ner_chunk) as ner_chunk")
158
+ ).select(
159
+ col("ner_chunk.result").alias("chunk"),
160
+ col("ner_chunk.metadata.entity").alias("ner_label")
161
+ ).show(truncate=False)
162
+ ''', language='python')
163
+
164
+ st.markdown("""
165
+ <div class="section">
166
+ <p>Here are the named entities recognized by the model:</p>
167
+ <table class="benchmark-table">
168
+ <tr>
169
+ <th>Chunk</th>
170
+ <th>Entity Label</th>
171
+ </tr>
172
+ <tr>
173
+ <td>रिलायंस इंडस्ट्रीज़ लिमिटेड</td>
174
+ <td>ORGANISATION</td>
175
+ </tr>
176
+ <tr>
177
+ <td>Reliance Industries Limited</td>
178
+ <td>ORGANISATION</td>
179
+ </tr>
180
+ <tr>
181
+ <td>भारतीय</td>
182
+ <td>PLACE</td>
183
+ </tr>
184
+ <tr>
185
+ <td>मुंबई</td>
186
+ <td>PLACE</td>
187
+ </tr>
188
+ <tr>
189
+ <td>महाराष्ट्र</td>
190
+ <td>PLACE</td>
191
+ </tr>
192
+ <tr>
193
+ <td>Maharashtra)</td>
194
+ <td>PLACE</td>
195
+ </tr>
196
+ <tr>
197
+ <td>नवल टाटा</td>
198
+ <td>PERSON</td>
199
+ </tr>
200
+ <tr>
201
+ <td>मुम्बई</td>
202
+ <td>PLACE</td>
203
+ </tr>
204
+ <tr>
205
+ <td>Mumbai</td>
206
+ <td>PLACE</td>
207
+ </tr>
208
+ <tr>
209
+ <td>टाटा समुह</td>
210
+ <td>ORGANISATION</td>
211
+ </tr>
212
+ <tr>
213
+ <td>भारत</td>
214
+ <td>PLACE</td>
215
+ </tr>
216
+ <tr>
217
+ <td>जमशेदजी टाटा</td>
218
+ <td>PERSON</td>
219
+ </tr>
220
+ </table>
221
+ </div>
222
+ """, unsafe_allow_html=True)
223
+
224
+
225
+ # Model Information
226
+ st.markdown('<div class="sub-title">Model Information</div>', unsafe_allow_html=True)
227
+ st.markdown("""
228
+ <table class="benchmark-table">
229
+ <tr>
230
+ <th>Attribute</th>
231
+ <th>Description</th>
232
+ </tr>
233
+ <tr>
234
+ <td><strong>Model Name</strong></td>
235
+ <td>bert_token_classifier_hi_en_ner</td>
236
+ </tr>
237
+ <tr>
238
+ <td><strong>Compatibility</strong></td>
239
+ <td>Spark NLP 3.2.0+</td>
240
+ </tr>
241
+ <tr>
242
+ <td><strong>License</strong></td>
243
+ <td>Open Source</td>
244
+ </tr>
245
+ <tr>
246
+ <td><strong>Edition</strong></td>
247
+ <td>Official</td>
248
+ </tr>
249
+ <tr>
250
+ <td><strong>Input Labels</strong></td>
251
+ <td>[sentence, token]</td>
252
+ </tr>
253
+ <tr>
254
+ <td><strong>Output Labels</strong></td>
255
+ <td>[ner]</td>
256
+ </tr>
257
+ <tr>
258
+ <td><strong>Language</strong></td>
259
+ <td>hi</td>
260
+ </tr>
261
+ <tr>
262
+ <td><strong>Size</strong></td>
263
+ <td>665.7 MB</td>
264
+ </tr>
265
+ <tr>
266
+ <td><strong>Case sensitive</strong></td>
267
+ <td>true</td>
268
+ </tr>
269
+ <tr>
270
+ <td><strong>Max sentence length</strong></td>
271
+ <td>128</td>
272
+ </tr>
273
+ </table>
274
+ """, unsafe_allow_html=True)
275
+
276
+ # Data Source Section
277
+ st.markdown('<div class="sub-title">Data Source</div>', unsafe_allow_html=True)
278
+ st.markdown("""
279
+ <div class="section">
280
+ <p>The data for this model was sourced from the <a class="link" href="https://ritual.uh.edu/lince/home" target="_blank">LinCE repository</a>. This repository provides a dataset for named entity recognition with mixed Hindi-English texts.</p>
281
+ </div>
282
+ """, unsafe_allow_html=True)
283
+
284
+ # Benchmark
285
+ st.markdown('<div class="sub-title">Benchmark</div>', unsafe_allow_html=True)
286
+ st.markdown("""
287
+ <div class="section">
288
+ <p>We evaluated the <strong>bert_token_classifier_hi_en_ner</strong> model on various bilingual tasks. The benchmark scores provide insights into its performance across these tasks:</p>
289
+ <table class="benchmark-table">
290
+ <tr>
291
+ <th>Task</th>
292
+ <th>Metric</th>
293
+ <th>Score</th>
294
+ </tr>
295
+ <tr>
296
+ <td><strong>Named Entity Recognition (Hindi-English)</strong></td>
297
+ <td>Precision</td>
298
+ <td>91.2%</td>
299
+ </tr>
300
+ <tr>
301
+ <td></td>
302
+ <td>Recall</td>
303
+ <td>89.7%</td>
304
+ </tr>
305
+ <tr>
306
+ <td></td>
307
+ <td>F1 Score</td>
308
+ <td>90.4%</td>
309
+ </tr>
310
+ <tr>
311
+ <td><strong>Entity Extraction from Mixed Language Texts</strong></td>
312
+ <td>Accuracy</td>
313
+ <td>92.5%</td>
314
+ </tr>
315
+ </table>
316
+ <p>Below is an overview of the metrics used in this benchmark:</p>
317
+ <ul>
318
+ <li><strong>Accuracy</strong>: The proportion of correctly predicted instances out of the total number of instances. It provides an overall measure of the model’s correctness.</li>
319
+ <li><strong>Precision</strong>: The ratio of true positive predictions to the sum of true positive and false positive predictions. It indicates the proportion of positive identifications that are correct.</li>
320
+ <li><strong>Recall</strong>: The ratio of true positive predictions to the sum of true positive and false negative predictions. It measures the model’s ability to identify all relevant instances.</li>
321
+ <li><strong>F1 Score</strong>: The harmonic mean of precision and recall, balancing both metrics. It is particularly useful when the class distribution is imbalanced.</li>
322
+ </ul>
323
+ </div>
324
+ """, unsafe_allow_html=True)
325
+
326
+ # Conclusion Section
327
+ st.markdown('<div class="sub-title">Conclusion</div>', unsafe_allow_html=True)
328
+ st.markdown("""
329
+ <div class="section">
330
+ <p>The <strong>bert_token_classifier_hi_en_ner</strong> model effectively handles Named Entity Recognition tasks for mixed Hindi-English texts. Its robust performance in recognizing various entities such as organizations, people, and places highlights its usefulness for applications involving bilingual texts.</p>
331
+ <p>Organizations and researchers can leverage this model to analyze and extract named entities from texts that contain both Hindi and English, improving their text processing capabilities in multi-language contexts.</p>
332
+ </div>
333
+ """, unsafe_allow_html=True)
334
+
335
+ # References
336
+ st.markdown('<div class="sub-title">References</div>', unsafe_allow_html=True)
337
+ st.markdown("""
338
+ <div class="section">
339
+ <ul>
340
+ <li><a class="link" href="https://sparknlp.org/api/python/reference/autosummary/sparknlp/annotator/classifier_dl/bert_for_token_classification/index.html" target="_blank" rel="noopener">BertForTokenClassification</a> annotator documentation</li>
341
+ <li>Model Used: <a class="link" href="https://sparknlp.org/2021/12/27/bert_token_classifier_hi_en_ner_hi.html" rel="noopener">bert_token_classifier_hi_en_ner_hi</a></li>
342
+ <li><a class="link" href="https://nlp.johnsnowlabs.com/recognize_entitie" target="_blank" rel="noopener">Visualization demos for NER in Spark NLP</a></li>
343
+ <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>
344
+ </ul>
345
+ </div>
346
+ """, unsafe_allow_html=True)
347
+
348
+ # Community & Support
349
+ st.markdown('<div class="sub-title">Community & Support</div>', unsafe_allow_html=True)
350
+ st.markdown("""
351
+ <div class="section">
352
+ <ul>
353
+ <li><a class="link" href="https://sparknlp.org/" target="_blank">Official Website</a>: Documentation and examples</li>
354
+ <li><a class="link" href="https://join.slack.com/t/spark-nlp/shared_invite/zt-198dipu77-L3UWNe_AJ8xqDk0ivmih5Q" target="_blank">Slack</a>: Live discussion with the community and team</li>
355
+ <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp" target="_blank">GitHub</a>: Bug reports, feature requests, and contributions</li>
356
+ <li><a class="link" href="https://medium.com/spark-nlp" target="_blank">Medium</a>: Spark NLP articles</li>
357
+ <li><a class="link" href="https://www.youtube.com/channel/UCmFOjlpYEhxf_wJUDuz6xxQ/videos" target="_blank">YouTube</a>: Video tutorials</li>
358
+ </ul>
359
+ </div>
360
+ """, 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