Spaces:
Sleeping
Sleeping
File size: 15,250 Bytes
6336cc6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
import streamlit as st
# Custom CSS for better styling
st.markdown("""
<style>
.main-title {
font-size: 36px;
color: #4A90E2;
font-weight: bold;
text-align: center;
}
.sub-title {
font-size: 24px;
color: #4A90E2;
margin-top: 20px;
}
.section {
background-color: #f9f9f9;
padding: 15px;
border-radius: 10px;
margin-top: 20px;
}
.section h2 {
font-size: 22px;
color: #4A90E2;
}
.section p, .section ul {
color: #666666;
}
.link {
color: #4A90E2;
text-decoration: none;
}
.benchmark-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.benchmark-table th, .benchmark-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.benchmark-table th {
background-color: #4A90E2;
color: white;
}
.benchmark-table td {
background-color: #f2f2f2;
}
</style>
""", unsafe_allow_html=True)
# Main Title
st.markdown('<div class="main-title">Bilingual Named Entity Recognition Model: Hindi and English</div>', unsafe_allow_html=True)
# Description
st.markdown("""
<div class="section">
<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>
</div>
""", unsafe_allow_html=True)
# What is Entity Recognition
st.markdown('<div class="sub-title">What is Entity Recognition?</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<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>
</div>
""", unsafe_allow_html=True)
# Model Importance and Applications
st.markdown('<div class="sub-title">Model Importance and Applications</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<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>
<ul>
<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>
<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>
<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>
<li><strong>Data Enrichment:</strong> Improves datasets by adding valuable entity information from bilingual texts, useful for multilingual data systems and research.</li>
</ul>
<p>Why use the <strong>bert_token_classifier_hi_en_ner</strong> model?</p>
<ul>
<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>
<li><strong>High Accuracy:</strong> Delivers reliable results in identifying entities, even in complex bilingual contexts.</li>
<li><strong>Versatility:</strong> Applicable to a wide range of documents and texts, enhancing its utility in various scenarios.</li>
</ul>
</div>
""", unsafe_allow_html=True)
# Predicted Entities
st.markdown('<div class="sub-title">Predicted Entities</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<p>The model identifies and classifies the following entities:</p>
<ul>
<li><strong>ORGANISATION</strong>: Names of organizations or companies.</li>
<li><strong>PERSON</strong>: Names of people.</li>
<li><strong>PLACE</strong>: Names of locations or places.</li>
</ul>
</div>
""", unsafe_allow_html=True)
# How to Use the Model
st.markdown('<div class="sub-title">How to Use the Model</div>', unsafe_allow_html=True)
st.code('''
from sparknlp.base import *
from sparknlp.annotator import *
from pyspark.ml import Pipeline
from pyspark.sql.functions import col, expr
# Define the pipeline stages
document_assembler = DocumentAssembler() \\
.setInputCol('text') \\
.setOutputCol('document')
sentence_detector = SentenceDetector() \\
.setInputCols(['document']) \\
.setOutputCol('sentence')
tokenizer = Tokenizer() \\
.setInputCols(['sentence']) \\
.setOutputCol('token')
tokenClassifier_loaded = BertForTokenClassification.pretrained("bert_token_classifier_hi_en_ner", "hi") \\
.setInputCols(["sentence", 'token']) \\
.setOutputCol("ner")
ner_converter = NerConverter() \\
.setInputCols(["sentence", "token", "ner"]) \\
.setOutputCol("ner_chunk")
# Create the NLP pipeline
pipeline = Pipeline(stages=[
document_assembler,
sentence_detector,
tokenizer,
tokenClassifier_loaded,
ner_converter
])
# Sample text
text = """
रिलायंस इंडस्ट्रीज़ लिमिटेड (Reliance Industries Limited) एक भारतीय संगुटिका नियंत्रक कंपनी है, जिसका मुख्यालय मुंबई, महाराष्ट्र (Maharashtra) में स्थित है।रतन नवल टाटा (28 दिसंबर 1937, को मुम्बई (Mumbai), में जन्मे) टाटा समुह के वर्तमान अध्यक्ष, जो भारत की सबसे बड़ी व्यापारिक समूह है, जिसकी स्थापना जमशेदजी टाटा ने की और उनके परिवार की पीढियों ने इसका विस्तार किया और इसे दृढ़ बनाया।
"""
# Create a DataFrame with the text
data = spark.createDataFrame([[text]]).toDF("text")
# Apply the pipeline to the data
model = pipeline.fit(data)
result = model.transform(data)
# Display results
result.select(
expr("explode(ner_chunk) as ner_chunk")
).select(
col("ner_chunk.result").alias("chunk"),
col("ner_chunk.metadata.entity").alias("ner_label")
).show(truncate=False)
''', language='python')
st.markdown("""
<div class="section">
<p>Here are the named entities recognized by the model:</p>
<table class="benchmark-table">
<tr>
<th>Chunk</th>
<th>Entity Label</th>
</tr>
<tr>
<td>रिलायंस इंडस्ट्रीज़ लिमिटेड</td>
<td>ORGANISATION</td>
</tr>
<tr>
<td>Reliance Industries Limited</td>
<td>ORGANISATION</td>
</tr>
<tr>
<td>भारतीय</td>
<td>PLACE</td>
</tr>
<tr>
<td>मुंबई</td>
<td>PLACE</td>
</tr>
<tr>
<td>महाराष्ट्र</td>
<td>PLACE</td>
</tr>
<tr>
<td>Maharashtra)</td>
<td>PLACE</td>
</tr>
<tr>
<td>नवल टाटा</td>
<td>PERSON</td>
</tr>
<tr>
<td>मुम्बई</td>
<td>PLACE</td>
</tr>
<tr>
<td>Mumbai</td>
<td>PLACE</td>
</tr>
<tr>
<td>टाटा समुह</td>
<td>ORGANISATION</td>
</tr>
<tr>
<td>भारत</td>
<td>PLACE</td>
</tr>
<tr>
<td>जमशेदजी टाटा</td>
<td>PERSON</td>
</tr>
</table>
</div>
""", unsafe_allow_html=True)
# Model Information
st.markdown('<div class="sub-title">Model Information</div>', unsafe_allow_html=True)
st.markdown("""
<table class="benchmark-table">
<tr>
<th>Attribute</th>
<th>Description</th>
</tr>
<tr>
<td><strong>Model Name</strong></td>
<td>bert_token_classifier_hi_en_ner</td>
</tr>
<tr>
<td><strong>Compatibility</strong></td>
<td>Spark NLP 3.2.0+</td>
</tr>
<tr>
<td><strong>License</strong></td>
<td>Open Source</td>
</tr>
<tr>
<td><strong>Edition</strong></td>
<td>Official</td>
</tr>
<tr>
<td><strong>Input Labels</strong></td>
<td>[sentence, token]</td>
</tr>
<tr>
<td><strong>Output Labels</strong></td>
<td>[ner]</td>
</tr>
<tr>
<td><strong>Language</strong></td>
<td>hi</td>
</tr>
<tr>
<td><strong>Size</strong></td>
<td>665.7 MB</td>
</tr>
<tr>
<td><strong>Case sensitive</strong></td>
<td>true</td>
</tr>
<tr>
<td><strong>Max sentence length</strong></td>
<td>128</td>
</tr>
</table>
""", unsafe_allow_html=True)
# Data Source Section
st.markdown('<div class="sub-title">Data Source</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<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>
</div>
""", unsafe_allow_html=True)
# Benchmark
st.markdown('<div class="sub-title">Benchmark</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<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>
<table class="benchmark-table">
<tr>
<th>Task</th>
<th>Metric</th>
<th>Score</th>
</tr>
<tr>
<td><strong>Named Entity Recognition (Hindi-English)</strong></td>
<td>Precision</td>
<td>91.2%</td>
</tr>
<tr>
<td></td>
<td>Recall</td>
<td>89.7%</td>
</tr>
<tr>
<td></td>
<td>F1 Score</td>
<td>90.4%</td>
</tr>
<tr>
<td><strong>Entity Extraction from Mixed Language Texts</strong></td>
<td>Accuracy</td>
<td>92.5%</td>
</tr>
</table>
<p>Below is an overview of the metrics used in this benchmark:</p>
<ul>
<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>
<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>
<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>
<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>
</ul>
</div>
""", unsafe_allow_html=True)
# Conclusion Section
st.markdown('<div class="sub-title">Conclusion</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<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>
<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>
</div>
""", unsafe_allow_html=True)
# References
st.markdown('<div class="sub-title">References</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<ul>
<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>
<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>
<li><a class="link" href="https://nlp.johnsnowlabs.com/recognize_entitie" target="_blank" rel="noopener">Visualization demos for NER in Spark NLP</a></li>
<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>
</ul>
</div>
""", unsafe_allow_html=True)
# Community & Support
st.markdown('<div class="sub-title">Community & Support</div>', unsafe_allow_html=True)
st.markdown("""
<div class="section">
<ul>
<li><a class="link" href="https://sparknlp.org/" target="_blank">Official Website</a>: Documentation and examples</li>
<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>
<li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp" target="_blank">GitHub</a>: Bug reports, feature requests, and contributions</li>
<li><a class="link" href="https://medium.com/spark-nlp" target="_blank">Medium</a>: Spark NLP articles</li>
<li><a class="link" href="https://www.youtube.com/channel/UCmFOjlpYEhxf_wJUDuz6xxQ/videos" target="_blank">YouTube</a>: Video tutorials</li>
</ul>
</div>
""", unsafe_allow_html=True) |