abdullahmubeen10 commited on
Commit
5fea2c5
·
verified ·
1 Parent(s): b364455

Update pages/Workflow & Model Overview.py

Browse files
Files changed (1) hide show
  1. pages/Workflow & Model Overview.py +166 -169
pages/Workflow & Model Overview.py CHANGED
@@ -1,169 +1,166 @@
1
- import streamlit as st
2
-
3
- # Page configuration
4
- st.set_page_config(
5
- layout="wide",
6
- initial_sidebar_state="auto"
7
- )
8
-
9
- # Custom CSS for better styling
10
- st.markdown("""
11
- <style>
12
- .main-title {
13
- font-size: 36px;
14
- color: #4A90E2;
15
- font-weight: bold;
16
- text-align: center;
17
- }
18
- .sub-title {
19
- font-size: 24px;
20
- color: #4A90E2;
21
- margin-top: 20px;
22
- }
23
- .section {
24
- background-color: #f9f9f9;
25
- padding: 15px;
26
- border-radius: 10px;
27
- margin-top: 20px;
28
- }
29
- .section h2 {
30
- font-size: 22px;
31
- color: #4A90E2;
32
- }
33
- .section p, .section ul {
34
- color: #666666;
35
- }
36
- .link {
37
- color: #4A90E2;
38
- text-decoration: none;
39
- }
40
- </style>
41
- """, unsafe_allow_html=True)
42
-
43
- # Title
44
- st.markdown('<div class="main-title">Chat and Conversational LLMs (Facebook Llama-2)</div>', unsafe_allow_html=True)
45
-
46
- # Introduction Section
47
- st.markdown("""
48
- <div class="section">
49
- <p>Facebook's Llama-2 is a cutting-edge family of large language models (LLMs) designed to excel in a variety of conversational tasks. With models ranging from 7 billion to 70 billion parameters, Llama-2 has been fine-tuned specifically for dialogue use cases, making it one of the most powerful and versatile models available for chat and conversational AI.</p>
50
- <p>Llama-2 models have demonstrated superior performance across multiple benchmarks, often outperforming other open-source models and rivaling some of the best closed-source models like ChatGPT and PaLM. These models are capable of handling complex, context-rich conversations with a high degree of accuracy and coherence.</p>
51
- </div>
52
- """, unsafe_allow_html=True)
53
-
54
- # Llama-2 Transformer Overview
55
- st.markdown('<div class="sub-title">Understanding the Llama-2 Transformer</div>', unsafe_allow_html=True)
56
-
57
- st.markdown("""
58
- <div class="section">
59
- <h2>Llama-2: The Transformer Architecture</h2>
60
- <p>Llama-2 is based on the transformer architecture, a deep learning model that has revolutionized the field of natural language processing. The transformer model employs a mechanism called self-attention, which allows it to weigh the importance of different words in a sentence relative to each other. This enables the model to capture long-range dependencies in text, making it highly effective for understanding and generating human-like text.</p>
61
- <p>The Llama-2 model family builds on this architecture, incorporating enhancements that improve its ability to handle longer contexts and generate more accurate and coherent responses. The model is particularly well-suited for dialogue and conversational applications, where understanding context and maintaining coherence over multiple turns of conversation is crucial.</p>
62
- </div>
63
- """, unsafe_allow_html=True)
64
-
65
- # Performance Section
66
- st.markdown('<div class="sub-title">Performance and Benchmarks</div>', unsafe_allow_html=True)
67
-
68
- st.markdown("""
69
- <div class="section">
70
- <p>Llama-2-Chat models have been rigorously tested against a variety of benchmarks to assess their performance in dialogue and conversational tasks. The results have shown that Llama-2 outperforms other open-source chat models on most benchmarks, demonstrating its effectiveness in generating accurate, relevant, and contextually appropriate responses.</p>
71
- <p>In human evaluations, Llama-2-Chat has been found to be on par with some of the leading closed-source models in terms of helpfulness and safety. This makes it a highly reliable option for developers looking to implement conversational AI in their applications.</p>
72
- </div>
73
- """, unsafe_allow_html=True)
74
-
75
- # Implementation Section
76
- st.markdown('<div class="sub-title">Implementing Llama-2 for Conversational AI</div>', unsafe_allow_html=True)
77
-
78
- st.markdown("""
79
- <div class="section">
80
- <p>The following is an example of how to implement a Llama-2 model for generating responses in a conversational AI application. We use the Llama-2 model with a simple Spark NLP pipeline to generate responses to user input.</p>
81
- </div>
82
- """, unsafe_allow_html=True)
83
-
84
- st.code('''
85
- from sparknlp.base import *
86
- from sparknlp.annotator import *
87
- from pyspark.ml import Pipeline
88
- from pyspark.sql.functions import col, expr
89
-
90
- documentAssembler = DocumentAssembler() \\
91
- .setInputCol("text") \\
92
- .setOutputCol("documents")
93
-
94
- llama2 = LLAMA2Transformer \\
95
- .pretrained("llama_2_7b_chat_hf_int4") \\
96
- .setMaxOutputLength(50) \\
97
- .setDoSample(False) \\
98
- .setInputCols(["documents"]) \\
99
- .setOutputCol("generation")
100
-
101
- pipeline = Pipeline().setStages([documentAssembler, llama2])
102
-
103
- data = spark.createDataFrame([["what are your thoughts about the new monkeypox virus"]]).toDF("text")
104
- result = pipeline.fit(data).transform(data)
105
- result.select("generation.result").show(truncate=False)
106
- ''', language='python')
107
-
108
- # Example Output
109
- st.text("""
110
- +------------------------------------------------+
111
- |generation.result |
112
- +------------------------------------------------+
113
- |Monkeypox is a rare disease that has been ... |
114
- +------------------------------------------------+
115
- """)
116
-
117
- # Model Info Section
118
- st.markdown('<div class="sub-title">Choosing the Right Llama-2 Model</div>', unsafe_allow_html=True)
119
-
120
- st.markdown("""
121
- <div class="section">
122
- <p>Llama-2 models are available in various sizes and configurations, depending on the specific needs of your application. For conversational AI, it is important to select a model that balances performance with resource efficiency. The model used in the example, "llama_2_7b_chat_hf_int4," is optimized for chat applications and is a good starting point for many use cases.</p>
123
- <p>For more complex tasks or larger-scale deployments, you may consider using one of the larger Llama-2 models, such as the 13B or 70B parameter variants, which offer greater accuracy and contextual understanding.</p>
124
- <p>Explore the available models on the <a class="link" href="https://sparknlp.org/models?annotator=LLAMA2Transformer" target="_blank">Spark NLP Models Hub</a> to find the one that fits your needs.</p>
125
- </div>
126
- """, unsafe_allow_html=True)
127
-
128
- # Footer
129
- # References Section
130
- st.markdown('<div class="sub-title">References</div>', unsafe_allow_html=True)
131
-
132
- st.markdown("""
133
- <div class="section">
134
- <ul>
135
- <li><a class="link" href="https://ai.facebook.com/" target="_blank">Facebook AI Research</a>: Learn more about Facebook's AI initiatives</li>
136
- <li><a class="link" href="https://sparknlp.org/models?annotator=LLAMA2Transformer" target="_blank">Spark NLP Model Hub</a>: Explore Llama-2 models</li>
137
- <li><a class="link" href="https://huggingface.co/facebook/llama" target="_blank">Hugging Face Model Hub</a>: Explore Llama-2 models</li>
138
- <li><a class="link" href="https://github.com/facebookresearch/llama" target="_blank">GitHub</a>: Access the Llama-2 repository and contribute</li>
139
- <li><a class="link" href="https://ai.facebook.com/blog/introducing-llama-2" target="_blank">Llama-2 Blog Post</a>: Detailed insights from the developers</li>
140
- </ul>
141
- </div>
142
- """, unsafe_allow_html=True)
143
-
144
- st.markdown('<div class="sub-title">Community & Support</div>', unsafe_allow_html=True)
145
-
146
- st.markdown("""
147
- <div class="section">
148
- <ul>
149
- <li><a class="link" href="https://sparknlp.org/" target="_blank">Official Website</a>: Documentation and examples</li>
150
- <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>
151
- <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp" target="_blank">GitHub</a>: Bug reports, feature requests, and contributions</li>
152
- <li><a class="link" href="https://medium.com/spark-nlp" target="_blank">Medium</a>: Spark NLP articles</li>
153
- <li><a class="link" href="https://www.youtube.com/channel/UCmFOjlpYEhxf_wJUDuz6xxQ/videos" target="_blank">YouTube</a>: Video tutorials</li>
154
- </ul>
155
- </div>
156
- """, unsafe_allow_html=True)
157
-
158
- st.markdown('<div class="sub-title">Quick Links</div>', unsafe_allow_html=True)
159
-
160
- st.markdown("""
161
- <div class="section">
162
- <ul>
163
- <li><a class="link" href="https://sparknlp.org/docs/en/quickstart" target="_blank">Getting Started</a></li>
164
- <li><a class="link" href="https://nlp.johnsnowlabs.com/models" target="_blank">Pretrained Models</a></li>
165
- <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp/tree/master/examples/python/annotation/text/english" target="_blank">Example Notebooks</a></li>
166
- <li><a class="link" href="https://sparknlp.org/docs/en/install" target="_blank">Installation Guide</a></li>
167
- </ul>
168
- </div>
169
- """, unsafe_allow_html=True)
 
1
+ import streamlit as st
2
+
3
+ # Page configuration
4
+ st.set_page_config(
5
+ layout="wide",
6
+ initial_sidebar_state="auto"
7
+ )
8
+
9
+ # Custom CSS for better styling
10
+ st.markdown("""
11
+ <style>
12
+ .main-title {
13
+ font-size: 36px;
14
+ color: #4A90E2;
15
+ font-weight: bold;
16
+ text-align: center;
17
+ }
18
+ .sub-title {
19
+ font-size: 24px;
20
+ color: #4A90E2;
21
+ margin-top: 20px;
22
+ }
23
+ .section {
24
+ background-color: #f9f9f9;
25
+ padding: 15px;
26
+ border-radius: 10px;
27
+ margin-top: 20px;
28
+ }
29
+ .section h2 {
30
+ font-size: 22px;
31
+ color: #4A90E2;
32
+ }
33
+ .section p, .section ul {
34
+ color: #666666;
35
+ }
36
+ .link {
37
+ color: #4A90E2;
38
+ text-decoration: none;
39
+ }
40
+ </style>
41
+ """, unsafe_allow_html=True)
42
+
43
+ # Title
44
+ st.markdown('<div class="main-title">SQL Query Generation</div>', unsafe_allow_html=True)
45
+
46
+ # Introduction Section
47
+ st.markdown("""
48
+ <div class="section">
49
+ <p>SQL Query Generation is a process that involves translating natural language queries into SQL statements. This allows non-technical users to interact with databases by simply asking questions in plain English, making it easier to retrieve specific data without needing to write complex SQL code.</p>
50
+ <p>In this page, we explore how to implement SQL Query Generation using the T5 model in a Spark NLP pipeline. The T5 model is trained to perform various text-to-text transformations, including translating English queries into SQL commands.</p>
51
+ </div>
52
+ """, unsafe_allow_html=True)
53
+
54
+ # T5 Transformer Overview
55
+ st.markdown('<div class="sub-title">T5: The Transformer Architecture</div>', unsafe_allow_html=True)
56
+
57
+ st.markdown("""
58
+ <div class="section">
59
+ <p>The T5 (Text-To-Text Transfer Transformer) model is designed to handle a wide variety of NLP tasks by treating them as text-to-text problems. In the context of SQL Query Generation, T5 takes a natural language input and translates it into an appropriate SQL query.</p>
60
+ <p>This model is built on the transformer architecture, which uses self-attention mechanisms to process input text, making it highly effective for understanding and generating text. The T5 model is particularly well-suited for tasks where the goal is to generate text that corresponds to a specific function, like generating SQL queries from plain English questions.</p>
61
+ </div>
62
+ """, unsafe_allow_html=True)
63
+
64
+ # Performance Section
65
+ st.markdown('<div class="sub-title">Performance and Benchmarks</div>', unsafe_allow_html=True)
66
+
67
+ st.markdown("""
68
+ <div class="section">
69
+ <p>T5 models, including the one used for SQL Query Generation, have been tested on various benchmarks that measure their ability to accurately translate natural language into SQL queries. These models have consistently demonstrated strong performance, accurately generating SQL queries that retrieve the correct data from databases.</p>
70
+ <p>Performance metrics for T5 in this domain show that it can handle a wide range of query types, from simple lookups to more complex queries involving multiple conditions and joins.</p>
71
+ </div>
72
+ """, unsafe_allow_html=True)
73
+
74
+ # Implementation Section
75
+ st.markdown('<div class="sub-title">Implementing SQL Query Generation</div>', unsafe_allow_html=True)
76
+
77
+ st.markdown("""
78
+ <div class="section">
79
+ <p>Below is an example of how to implement SQL Query Generation using a T5 model in a Spark NLP pipeline. This example demonstrates how a natural language query can be transformed into an SQL query that can be executed on a database.</p>
80
+ </div>
81
+ """, unsafe_allow_html=True)
82
+
83
+ st.code('''
84
+ from sparknlp.base import *
85
+ from sparknlp.annotator import *
86
+ from pyspark.ml import Pipeline
87
+ from pyspark.sql.functions import col, expr
88
+
89
+ documentAssembler = DocumentAssembler() \\
90
+ .setInputCol("text") \\
91
+ .setOutputCol("documents")
92
+
93
+ t5 = T5Transformer.pretrained("t5_small_wikiSQL") \\
94
+ .setTask("translate English to SQL:") \\
95
+ .setInputCols(["documents"]) \\
96
+ .setMaxOutputLength(200) \\
97
+ .setOutputCol("sql")
98
+
99
+ pipeline = Pipeline().setStages([documentAssembler, t5])
100
+
101
+ data = spark.createDataFrame([["How many customers have ordered more than 2 items?"]]).toDF("text")
102
+ result = pipeline.fit(data).transform(data)
103
+ result.select("sql.result").show(truncate=False)
104
+ ''', language='python')
105
+
106
+ # Example Output
107
+ st.text("""
108
+ +----------------------------------------------------+
109
+ |result |
110
+ +----------------------------------------------------+
111
+ |[SELECT COUNT Customers FROM table WHERE Orders > 2]|
112
+ +----------------------------------------------------+
113
+ """)
114
+
115
+ # Model Info Section
116
+ st.markdown('<div class="sub-title">Choosing the Right SQL Model</div>', unsafe_allow_html=True)
117
+
118
+ st.markdown("""
119
+ <div class="section">
120
+ <p>The T5 model used in the example, "t5_small_wikiSQL," is optimized for SQL query generation from English language input. Depending on the complexity of the queries you need to generate, you may choose a larger or more specialized version of the T5 model.</p>
121
+ <p>For more complex queries or larger datasets, consider using a model with more parameters, such as T5-base or T5-large, which offer improved performance and accuracy. You can explore different models and find the one that best suits your needs on the <a class="link" href="https://sparknlp.org/models?annotator=T5Transformer" target="_blank">Spark NLP Models Hub</a>.</p>
122
+ </div>
123
+ """, unsafe_allow_html=True)
124
+
125
+ # Footer
126
+ # References Section
127
+ st.markdown('<div class="sub-title">References</div>', unsafe_allow_html=True)
128
+
129
+ st.markdown("""
130
+ <div class="section">
131
+ <ul>
132
+ <li><a class="link" href="https://ai.googleblog.com/2019/10/exploring-transfer-learning-with-t5.html" target="_blank">Google AI Blog on T5</a>: Learn more about the T5 model</li>
133
+ <li><a class="link" href="https://sparknlp.org/models?annotator=T5Transformer" target="_blank">Spark NLP Model Hub</a>: Explore T5 models</li>
134
+ <li><a class="link" href="https://huggingface.co/models" target="_blank">Hugging Face Model Hub</a>: Explore various NLP models</li>
135
+ <li><a class="link" href="https://github.com/google-research/text-to-text-transfer-transformer" target="_blank">GitHub</a>: Access the T5 repository and contribute</li>
136
+ <li><a class="link" href="https://arxiv.org/abs/1910.10683" target="_blank">T5 Paper</a>: Detailed insights from the developers</li>
137
+ </ul>
138
+ </div>
139
+ """, unsafe_allow_html=True)
140
+
141
+ st.markdown('<div class="sub-title">Community & Support</div>', unsafe_allow_html=True)
142
+
143
+ st.markdown("""
144
+ <div class="section">
145
+ <ul>
146
+ <li><a class="link" href="https://sparknlp.org/" target="_blank">Official Website</a>: Documentation and examples</li>
147
+ <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>
148
+ <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp" target="_blank">GitHub</a>: Bug reports, feature requests, and contributions</li>
149
+ <li><a class="link" href="https://medium.com/spark-nlp" target="_blank">Medium</a>: Spark NLP articles</li>
150
+ <li><a class="link" href="https://www.youtube.com/channel/UCmFOjlpYEhxf_wJUDuz6xxQ/videos" target="_blank">YouTube</a>: Video tutorials</li>
151
+ </ul>
152
+ </div>
153
+ """, unsafe_allow_html=True)
154
+
155
+ st.markdown('<div class="sub-title">Quick Links</div>', unsafe_allow_html=True)
156
+
157
+ st.markdown("""
158
+ <div class="section">
159
+ <ul>
160
+ <li><a class="link" href="https://sparknlp.org/docs/en/quickstart" target="_blank">Getting Started</a></li>
161
+ <li><a class="link" href="https://nlp.johnsnowlabs.com/models" target="_blank">Pretrained Models</a></li>
162
+ <li><a class="link" href="https://github.com/JohnSnowLabs/spark-nlp/tree/master/examples/python/annotation/text/english" target="_blank">Example Notebooks</a></li>
163
+ <li><a class="link" href="https://sparknlp.org/docs/en/install" target="_blank">Installation Guide</a></li>
164
+ </ul>
165
+ </div>
166
+ """, unsafe_allow_html=True)