import streamlit as st # Page configuration st.set_page_config( layout="wide", initial_sidebar_state="auto" ) # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Title st.markdown('
Introduction to XLM-RoBERTa Annotators in Spark NLP
', unsafe_allow_html=True) # Subtitle st.markdown("""

XLM-RoBERTa (Cross-lingual Robustly Optimized BERT Approach) is an advanced multilingual model that extends the capabilities of RoBERTa to over 100 languages. Pre-trained on a massive, diverse corpus, XLM-RoBERTa is designed to handle various NLP tasks in a multilingual context, making it ideal for applications that require cross-lingual understanding. Below, we provide an overview of the XLM-RoBERTa annotators for these tasks:

""", unsafe_allow_html=True) st.markdown("""
Zero-Shot Classification with XLM-RoBERTa
""", unsafe_allow_html=True) st.markdown("""

Zero-shot classification is a powerful technique that allows models to classify text into categories that the model has never seen before during training. This is particularly useful in scenarios where labeled training data is scarce or when new categories emerge frequently.

XLM-RoBERTa is a multilingual model, making it highly effective for zero-shot classification tasks across various languages. It leverages large-scale cross-lingual pretraining to understand and classify text in multiple languages without requiring language-specific annotated data.

Using XLM-RoBERTa for Zero-Shot Classification enables:

Advantages of using XLM-RoBERTa for Zero-Shot Classification in Spark NLP include:

""", unsafe_allow_html=True) st.markdown("""
How to Use XLM-RoBERTa for Token Classification in Spark NLP
""", unsafe_allow_html=True) st.markdown("""

To leverage XLM-RoBERTa for zero-shot classification, Spark NLP offers a seamless pipeline configuration. The following example demonstrates how to utilize XLM-RoBERTa for zero-shot text classification, enabling the classification of text into categories that the model has never encountered during training. Thanks to its multilingual training, XLM-RoBERTa can perform zero-shot classification across various languages, making it a versatile tool for global NLP applications.

""", unsafe_allow_html=True) st.code(''' from sparknlp.base import * from sparknlp.annotator import * from pyspark.ml import Pipeline document_assembler = DocumentAssembler() \\ .setInputCol('text') \\ .setOutputCol('document') tokenizer = Tokenizer() \\ .setInputCols(['document']) \\ .setOutputCol('token') zeroShotClassifier = XlmRoBertaForZeroShotClassification \\ .pretrained('xlm_roberta_large_zero_shot_classifier_xnli_anli', 'xx') \\ .setInputCols(['token', 'document']) \\ .setOutputCol('class') \\ .setCaseSensitive(False) \\ .setMaxSentenceLength(512) \\ .setCandidateLabels(["urgent", "mobile", "travel", "movie", "music", "sport", "weather", "technology"]) pipeline = Pipeline(stages=[ document_assembler, tokenizer, zeroShotClassifier ]) example = spark.createDataFrame([['I have a problem with my iphone that needs to be resolved asap!!']]).toDF("text") result = pipeline.fit(example).transform(example) result.select("class.result").show(truncate=False) ''', language='python') st.text(""" +------------------+ |result | +------------------+ |["urgent"] | +------------------+ """) # Example Output st.markdown("""

This pipeline processes the input text and classifies it into one of the candidate labels provided. In the example given, the text is classified into categories such as "urgent", "mobile", "travel", etc.

""", unsafe_allow_html=True) # Model Info Section st.markdown('
Choosing the Right Model
', unsafe_allow_html=True) st.markdown("""

The XLM-RoBERTa model used here is pretrained on large multilingual datasets and fine-tuned for zero-shot classification tasks. It is available in Spark NLP, providing robust performance across different languages without needing task-specific annotated data.

For more information about the model, visit the XLM-RoBERTa Model Hub.

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