import streamlit as st # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Title st.markdown('
Correct Sentences Grammar
', unsafe_allow_html=True) # Introduction Section st.markdown("""

Ensuring correct grammar in sentences is essential for clear and effective communication. Whether writing an email, an academic paper, or a casual message, proper grammar ensures that your message is understood as intended.

This page demonstrates how to implement a grammar correction pipeline using advanced NLP models. We utilize the T5 Transformer model, fine-tuned for grammar error correction, to automatically correct sentences and enhance their grammatical accuracy.

""", unsafe_allow_html=True) # T5 Transformer Overview st.markdown('
Understanding the T5 Transformer for Grammar Correction
', unsafe_allow_html=True) st.markdown("""

The T5 (Text-To-Text Transfer Transformer) model, developed by Google, is a versatile tool for various NLP tasks, including grammar correction. By processing input sentences and applying the appropriate grammar corrections, T5 generates outputs that maintain the original meaning while correcting errors.

This is particularly useful for applications in writing assistance, automated editing, and educational tools, where grammatical accuracy is crucial.

""", unsafe_allow_html=True) # Performance Section st.markdown('
Performance and Use Cases
', unsafe_allow_html=True) st.markdown("""

The T5 model has shown strong performance in grammar correction tasks. It consistently produces accurate and contextually appropriate corrections, making it a valuable tool for improving written communication across various settings.

This capability is beneficial for students, professionals, and anyone who needs to ensure their writing is grammatically correct. The T5 model’s efficiency in correcting errors makes it a powerful asset for enhancing the quality of written content.

""", unsafe_allow_html=True) # Implementation Section st.markdown('
Implementing Grammar Correction
', unsafe_allow_html=True) st.markdown("""

The following example demonstrates how to implement a grammar correction pipeline using Spark NLP. The pipeline includes a document assembler and the T5 model for performing grammar corrections.

""", unsafe_allow_html=True) st.code(''' import sparknlp from sparknlp.base import * from sparknlp.annotator import * from pyspark.ml import Pipeline # Initialize Spark NLP spark = sparknlp.start() # Define the pipeline stages documentAssembler = DocumentAssembler()\\ .setInputCol("text")\\ .setOutputCol("documents") t5 = T5Transformer.pretrained("t5_grammar_error_corrector")\\ .setTask("gec:")\\ .setInputCols(["documents"])\\ .setMaxOutputLength(200)\\ .setOutputCol("corrections") pipeline = Pipeline().setStages([documentAssembler, t5]) # Input data example data = spark.createDataFrame([["She don't knows nothing about what's happening in the office."]]).toDF("text") # Apply the pipeline for grammar correction result = pipeline.fit(data).transform(data) result.select("corrections.result").show(truncate=False) ''', language='python') # Example Output st.text(""" +---------------------------------------------------------------+ |corrections.result | +---------------------------------------------------------------+ |[She doesn't know anything about what's happening in the office.]| +---------------------------------------------------------------+ """) # Model Info Section st.markdown('
Choosing the Right T5 Model for Grammar Correction
', unsafe_allow_html=True) st.markdown("""

For correcting grammar errors, we use the model: "t5_grammar_error_corrector". This model is fine-tuned to detect and correct various types of grammatical errors in English sentences.

Explore other T5 models tailored for different NLP tasks on the Spark NLP Models Hub to find the best fit for your specific needs.

""", unsafe_allow_html=True) # References Section st.markdown('
References
', unsafe_allow_html=True) st.markdown("""
""", unsafe_allow_html=True) # Community & Support Section st.markdown('
Community & Support
', unsafe_allow_html=True) st.markdown("""
""", unsafe_allow_html=True) # Quick Links Section st.markdown('
Quick Links
', unsafe_allow_html=True) st.markdown("""
""", unsafe_allow_html=True)