import streamlit as st import pandas as pd # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Main Title st.markdown('
Named Entity Recognition (NER) Model in Bengali (bengaliner_cc_300d)
', unsafe_allow_html=True) # Introduction st.markdown("""

Named Entity Recognition (NER) is the task of identifying important words in a text and associating them with a category. In this post, we introduce an NER model designed for Bengali language texts. This model can detect four different types of entities in Indian text, leveraging the power of Spark NLP.

""", unsafe_allow_html=True) # Model Description st.markdown('
Description
', unsafe_allow_html=True) st.markdown("""

The bengaliner_cc_300d model is designed to detect four different types of entities in Bengali text. The predicted entities include:

""", unsafe_allow_html=True) # Setup Instructions st.markdown('
Setup
', unsafe_allow_html=True) st.markdown('

To install Spark NLP in Python, use your favorite package manager (conda, pip, etc.). For example:

', unsafe_allow_html=True) st.code(""" pip install spark-nlp pip install pyspark """, language="bash") st.markdown("

Then, import Spark NLP and start a Spark session:

", unsafe_allow_html=True) st.code(""" import sparknlp # Start Spark Session spark = sparknlp.start() """, language='python') # Example Usage st.markdown('
Example Usage with Bengali NER Model
', unsafe_allow_html=True) st.markdown("""

Below is an example of how to set up and use the bengaliner_cc_300d model for named entity recognition in Bengali:

""", 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, round, concat, lit # Document Assembler document_assembler = DocumentAssembler()\\ .setInputCol("text")\\ .setOutputCol("document") # Tokenizer tokenizer = Tokenizer()\\ .setInputCols(["document"])\\ .setOutputCol("token") # Word Embeddings embeddings = WordEmbeddingsModel.pretrained("bengali_cc_300d", "bn")\\ .setInputCols(["document", "token"])\\ .setOutputCol("embeddings") # NER Model ner = NerDLModel.pretrained("bengaliner_cc_300d", "bn")\\ .setInputCols(["document", "token", "embeddings"])\\ .setOutputCol("ner") # NER Converter ner_converter = NerConverter()\\ .setInputCols(["document", "token", "ner"])\\ .setOutputCol("ner_chunk") # Pipeline pipeline = Pipeline(stages=[document_assembler, tokenizer, embeddings, ner, ner_converter]) # Example sentence example = spark.createDataFrame([["উইলিয়াম হেনরি গেটস III (জন্ম অক্টোবর ২৮, ১৯৫৫) একজন আমেরিকান ব্যবসায়ী, সফটওয়্যার ডেভেলপার, বিনিয়োগকারী এবং দাতা। তিনি মাইক্রোসফট কর্পোরেশনের সহ-প্রতিষ্ঠাতা হিসেবে সর্বাধিক পরিচিত। মাইক্রোসফটে তাঁর কর্মজীবনে, গেটস চেয়ারম্যান, প্রধান নির্বাহী কর্মকর্তা (CEO), প্রেসিডেন্ট এবং প্রধান সফটওয়্যার স্থপতি হিসেবে দায়িত্ব পালন করেছেন, পাশাপাশি ২০১৪ সালের মে পর্যন্ত সর্বাধিক শেয়ারহোল্ডার ছিলেন। তিনি ১৯৭০ এবং ১৯৮০ এর দশকের মাইক্রোকম্পিউটার বিপ্লবের অন্যতম পরিচিত উদ্যোক্তা এবং অগ্রদূত। সিয়াটল, ওয়াশিংটনে জন্মগ্রহণ ও বড় হওয়া গেটস, ১৯৭৫ সালে শৈশবের বন্ধু পল অ্যালেনের সাথে আলবুকার্কি, নিউ মেক্সিকোতে মাইক্রোসফটের সহ-প্রতিষ্ঠা করেন; এটি বিশ্বের বৃহত্তম ব্যক্তিগত কম্পিউটার সফটওয়্যার কোম্পানিতে পরিণত হয়। গেটস ২০০০ সালের জানুয়ারি পর্যন্ত চেয়ারম্যান ও CEO হিসেবে কোম্পানিকে নেতৃত্ব দেন, কিন্তু তিনি চেয়ারম্যান হিসাবে রয়ে যান এবং প্রধান সফটওয়্যার স্থপতি হন। ১৯৯০-এর দশকের শেষের দিকে, গেটসের ব্যবসায়িক কৌশলগুলোর জন্য সমালোচিত হয়েছিলেন, যা প্রতিযোগিতাহীন বলে বিবেচিত হয়েছে। এই মতামতটি বিভিন্ন আদালতের রায় দ্বারা সমর্থিত হয়েছে। ২০০৬ সালের জুনে, গেটস ঘোষণা করেছিলেন যে তিনি মাইক্রোসফটে আংশিক সময়ের ভূমিকা এবং বিল ও মেলিন্ডা গেটস ফাউন্ডেশনে পূর্ণকালীন কাজ করবেন, যা তিনি এবং তাঁর স্ত্রী মেলিন্ডা গেটস ২০০০ সালে প্রতিষ্ঠা করেছিলেন। তিনি ধীরে ধীরে তার দায়িত্বগুলি রে ওজি এবং ক্রেইগ মন্ডিকে হস্তান্তর করেন। তিনি ২০১৪ সালের ফেব্রুয়ারিতে মাইক্রোসফটের চেয়ারম্যান পদ থেকে সরে যান এবং নতুন নিয়োগপ্রাপ্ত CEO সত্য নাদেলার সমর্থনে প্রযুক্তি উপদেষ্টা হিসাবে নতুন পদ গ্রহণ করেন।"]], ["text"]) # Transforming data result = pipeline.fit(example).transform(example) # Select the result, entity, and confidence columns result.select( expr("explode(ner_chunk) as ner_chunk") ).select( col("ner_chunk.result").alias("chunk"), col("ner_chunk.metadata").getItem("entity").alias("ner_label") ).show(truncate=False) ''', language="python") data = { "Chunk": ["হেনরি গেটস", "সালের মে", "সিয়াটল", "সালে", "পল অ্যালেনের", "আলবুকার্কি", "নিউ মেক্সিকোতে", "সালের", "১৯৯০-এর", "সালের জুনে", "সালে", "ক্রেইগ মন্ডিকে", "সালের ফেব্রুয়ারিতে"], "NER Label": ["PER", "TIME", "LOC", "TIME", "PER", "ORG", "LOC", "TIME", "TIME", "TIME", "TIME", "PER", "TIME"] } st.dataframe(pd.DataFrame(data)) # Model Information st.markdown('
Model Information
', unsafe_allow_html=True) st.markdown("""

The bengaliner_cc_300d model details are as follows:

""", unsafe_allow_html=True) # Benchmark Section st.markdown('
Benchmark
', unsafe_allow_html=True) st.markdown("""

Evaluating the performance of NER models is crucial to understanding their effectiveness in real-world applications. Below are the benchmark results for the bengaliner_cc_300d model, focusing on various named entity categories. The metrics used include precision, recall, and F1-score, which are standard for evaluating classification models.

""", unsafe_allow_html=True) st.markdown(""" --- | Label | TP | FP | FN | Precision | Recall | F1-Score | |--------|------|------|------|-----------|--------|----------| | I-TIME | 167 | 37 | 25 | 0.8186 | 0.8698 | 0.8434 | | B-LOC | 678 | 114 | 195 | 0.8561 | 0.7766 | 0.8144 | | I-ORG | 287 | 104 | 143 | 0.7340 | 0.6674 | 0.6991 | | B-TIME | 414 | 54 | 123 | 0.8846 | 0.7710 | 0.8239 | | I-LOC | 98 | 50 | 76 | 0.6622 | 0.5632 | 0.6087 | | I-PER | 805 | 38 | 55 | 0.9549 | 0.9360 | 0.9454 | | B-ORG | 446 | 108 | 225 | 0.8051 | 0.6647 | 0.7282 | | B-PER | 764 | 48 | 183 | 0.9409 | 0.8068 | 0.8687 | | Macro-average | - | - | - | 0.8320 | 0.7569 | 0.7927 | | Micro-average | - | - | - | 0.8687 | 0.7812 | 0.8226 | --- """, unsafe_allow_html=True) # Summary st.markdown('
Summary
', unsafe_allow_html=True) st.markdown("""

In this article, we discussed named entity recognition using the bengaliner_cc_300d model for Bengali texts. We introduced how to perform NER with Spark NLP, set up the environment, and use the model. We also provided a detailed benchmark for the model's performance, demonstrating its effectiveness across various named entity categories.

For more information, refer to the official documentation.

""", 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("""
""", unsafe_allow_html=True)