Spaces:
Sleeping
Sleeping
| 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; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Title | |
| st.markdown('<div class="main-title">Correct Sentences Grammar</div>', unsafe_allow_html=True) | |
| # Introduction Section | |
| st.markdown(""" | |
| <div class="section"> | |
| <p>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.</p> | |
| <p>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.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # T5 Transformer Overview | |
| st.markdown('<div class="sub-title">Understanding the T5 Transformer for Grammar Correction</div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="section"> | |
| <p>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.</p> | |
| <p>This is particularly useful for applications in writing assistance, automated editing, and educational tools, where grammatical accuracy is crucial.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Performance Section | |
| st.markdown('<div class="sub-title">Performance and Use Cases</div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="section"> | |
| <p>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.</p> | |
| <p>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.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Implementation Section | |
| st.markdown('<div class="sub-title">Implementing Grammar Correction</div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="section"> | |
| <p>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.</p> | |
| </div> | |
| """, 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('<div class="sub-title">Choosing the Right T5 Model for Grammar Correction</div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="section"> | |
| <p>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.</p> | |
| <p>Explore other T5 models tailored for different NLP tasks on the <a class="link" href="https://sparknlp.org/models?annotator=T5Transformer" target="_blank">Spark NLP Models Hub</a> to find the best fit for your specific needs.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # References Section | |
| st.markdown('<div class="sub-title">References</div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="section"> | |
| <ul> | |
| <li><a class="link" href="https://ai.googleblog.com/2020/02/exploring-transfer-learning-with-t5.html" target="_blank">Google AI Blog</a>: Exploring Transfer Learning with T5</li> | |
| <li><a class="link" href="https://sparknlp.org/models?annotator=T5Transformer" target="_blank">Spark NLP Model Hub</a>: Explore T5 models</li> | |
| <li>Model used for Grammar Correction: <a class="link" href="https://sparknlp.org/2022/11/28/t5_grammar_error_corrector_en.html" target="_blank">t5_grammar_error_corrector</a></li> | |
| <li><a class="link" href="https://github.com/google-research/text-to-text-transfer-transformer" target="_blank">GitHub</a>: T5 Transformer repository</li> | |
| <li><a class="link" href="https://arxiv.org/abs/1910.10683" target="_blank">T5 Paper</a>: Detailed insights from the developers</li> | |
| </ul> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Community & Support Section | |
| 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) | |
| # Quick Links Section | |
| st.markdown('<div class="sub-title">Quick Links</div>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="section"> | |
| <ul> | |
| <li><a class="link" href="https://sparknlp.org/docs/en/quickstart" target="_blank">Getting Started</a></li> | |
| <li><a class="link" href="https://nlp.johnsnowlabs.com/models" target="_blank">Pretrained Models</a></li> | |
| <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp/tree/master/examples/python/annotation/text/english" target="_blank">Example Notebooks</a></li> | |
| <li><a class="link" href="https://sparknlp.org/docs/en/install" target="_blank">Installation Guide</a></li> | |
| </ul> | |
| </div> | |
| """, unsafe_allow_html=True) | |