import streamlit as st
# Custom CSS for better styling
st.markdown("""
""", unsafe_allow_html=True)
# Main Title
st.markdown('
Bilingual Named Entity Recognition Model: Hindi and English
', unsafe_allow_html=True)
# Description
st.markdown("""
This model, bert_token_classifier_hi_en_ner, 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.
""", unsafe_allow_html=True)
# What is Entity Recognition
st.markdown('What is Entity Recognition?
', unsafe_allow_html=True)
st.markdown("""
Entity Recognition 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.
""", unsafe_allow_html=True)
# Model Importance and Applications
st.markdown('Model Importance and Applications
', unsafe_allow_html=True)
st.markdown("""
The bert_token_classifier_hi_en_ner model is a powerful tool for handling mixed Hindi-English texts. Its applications include:
- Multilingual Text Analysis: Efficiently processes and analyzes texts that contain both Hindi and English, making it suitable for a diverse range of documents.
- Entity Recognition in Bilingual Contexts: Identifies and classifies named entities in contexts where Hindi and English are mixed, enhancing understanding in multilingual environments.
- Cross-Language Information Extraction: Extracts valuable information from documents that are not confined to a single language, providing insights in both Hindi and English.
- Data Enrichment: Improves datasets by adding valuable entity information from bilingual texts, useful for multilingual data systems and research.
Why use the bert_token_classifier_hi_en_ner model?
- Pre-trained for Mixed Hindi-English: Specifically trained to handle mixed-language texts, ensuring accurate recognition of entities in both languages.
- High Accuracy: Delivers reliable results in identifying entities, even in complex bilingual contexts.
- Versatility: Applicable to a wide range of documents and texts, enhancing its utility in various scenarios.
""", unsafe_allow_html=True)
# Predicted Entities
st.markdown('Predicted Entities
', unsafe_allow_html=True)
st.markdown("""
The model identifies and classifies the following entities:
- ORGANISATION: Names of organizations or companies.
- PERSON: Names of people.
- PLACE: Names of locations or places.
""", unsafe_allow_html=True)
# How to Use the Model
st.markdown('How to Use the Model
', 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("""
Here are the named entities recognized by the model:
Chunk |
Entity Label |
रिलायंस इंडस्ट्रीज़ लिमिटेड |
ORGANISATION |
Reliance Industries Limited |
ORGANISATION |
भारतीय |
PLACE |
मुंबई |
PLACE |
महाराष्ट्र |
PLACE |
Maharashtra) |
PLACE |
नवल टाटा |
PERSON |
मुम्बई |
PLACE |
Mumbai |
PLACE |
टाटा समुह |
ORGANISATION |
भारत |
PLACE |
जमशेदजी टाटा |
PERSON |
""", unsafe_allow_html=True)
# Model Information
st.markdown('Model Information
', unsafe_allow_html=True)
st.markdown("""
Attribute |
Description |
Model Name |
bert_token_classifier_hi_en_ner |
Compatibility |
Spark NLP 3.2.0+ |
License |
Open Source |
Edition |
Official |
Input Labels |
[sentence, token] |
Output Labels |
[ner] |
Language |
hi |
Size |
665.7 MB |
Case sensitive |
true |
Max sentence length |
128 |
""", unsafe_allow_html=True)
# Data Source Section
st.markdown('Data Source
', unsafe_allow_html=True)
st.markdown("""
The data for this model was sourced from the LinCE repository. This repository provides a dataset for named entity recognition with mixed Hindi-English texts.
""", unsafe_allow_html=True)
# Benchmark
st.markdown('Benchmark
', unsafe_allow_html=True)
st.markdown("""
We evaluated the bert_token_classifier_hi_en_ner model on various bilingual tasks. The benchmark scores provide insights into its performance across these tasks:
Task |
Metric |
Score |
Named Entity Recognition (Hindi-English) |
Precision |
91.2% |
|
Recall |
89.7% |
|
F1 Score |
90.4% |
Entity Extraction from Mixed Language Texts |
Accuracy |
92.5% |
Below is an overview of the metrics used in this benchmark:
- Accuracy: The proportion of correctly predicted instances out of the total number of instances. It provides an overall measure of the model’s correctness.
- Precision: 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.
- Recall: 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.
- F1 Score: The harmonic mean of precision and recall, balancing both metrics. It is particularly useful when the class distribution is imbalanced.
""", unsafe_allow_html=True)
# Conclusion Section
st.markdown('Conclusion
', unsafe_allow_html=True)
st.markdown("""
The bert_token_classifier_hi_en_ner 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.
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.
""", unsafe_allow_html=True)
# References
st.markdown('References
', unsafe_allow_html=True)
st.markdown("""
""", unsafe_allow_html=True)
# Community & Support
st.markdown('Community & Support
', unsafe_allow_html=True)
st.markdown("""
- Official Website: Documentation and examples
- Slack: Live discussion with the community and team
- GitHub: Bug reports, feature requests, and contributions
- Medium: Spark NLP articles
- YouTube: Video tutorials
""", unsafe_allow_html=True)