BeardedMonster commited on
Commit
3ef41e0
·
verified ·
1 Parent(s): d16eece
Files changed (1) hide show
  1. app.py +27 -21
app.py CHANGED
@@ -18,31 +18,31 @@ st.sidebar.title("Instructions: How to use")
18
  st.sidebar.write("""
19
  1. Write something in the text area (a prompt or random text) or use the dropdown menu to select predefined sample text.
20
  2. Select a task from the **task dropdown menu** below if you are providing your own text. **This is very important as it ensures the model responds accordingly.**
21
- 3. If you provide your own text, please do not select any predefined sample text from the dropdown menu.
22
  3. If a dropdown menu pops up for a nigerian language, **select the target nigerian language.**
23
  4. Click the Generate button to get a response below the text area.\n
24
- **Note: Model's performance when given prompts vary due to model size and training data distribution.**\n
25
  5. Lastly, you can play with some of the generation parameters below to improve performance.
26
  """)
27
 
28
  max_length = 100
29
  max_new_tokens = 50
30
  num_beams = 5
31
- temperature = 1.1
32
  top_k = 75
33
  top_p = 0.95
34
  repetition_penalty = 4.0
35
  length_penalty = 2.0
36
 
37
  # Create sliders in the sidebar
38
- max_length = st.sidebar.slider("Max Length", min_value=10, max_value=500, value=max_length)
39
- max_new_tokens = st.sidebar.slider("Max tokens", min_value=30, max_value=768, value=max_new_tokens)
40
- num_beams = st.sidebar.slider("Number of Beams", min_value=1, max_value=10, value=num_beams)
41
- temperature = st.sidebar.slider("Temperature", min_value=0.1, max_value=2.0, value=temperature)
42
- top_k = st.sidebar.slider("Top-K", min_value=1, max_value=100, value=top_k)
43
  top_p = st.sidebar.slider("Top-P", min_value=0.1, max_value=1.0, value=top_p)
44
- repetition_penalty = st.sidebar.slider("Repetition Penalty", min_value=1.0, max_value=10.0, value=repetition_penalty)
45
- length_penalty = st.sidebar.slider("Length Penalty", min_value=0.1, max_value=10.0, value=length_penalty)
46
 
47
 
48
  # Define generation configuration
@@ -69,7 +69,7 @@ generation_config = {
69
  }
70
 
71
  # Streamlit app
72
- st.title("SabiYarn-125M: Generates text in multiple Nigerian languages.")
73
 
74
  st.write("**Supported Languages: English, Yoruba, Igbo, Hausa, Pidgin, Efik, Urhobo, Fulfulde, Fulah. \nResults might not be coherent for less represented languages (i.e Efik, \
75
  Urhobo, Fulfulde, Fulah).**")
@@ -96,15 +96,18 @@ async def generate_from_api(user_input, generation_config):
96
 
97
  # Sample texts
98
  sample_texts = {
99
- "":"",
100
- "Tell me a story in pidgin": "Tell me a story in pidgin",
101
  "Oma Ede, Mi ji ogede...": "Oma Ede, Mi ji ogede mi a foroma orhorho edha meji ri eka. ",
 
102
  "who are you?": "who are you?",
 
 
103
  "Translate 'how are you?' to Yoruba": "Translate 'how are you?' to Yoruba",
104
  "Classify the sentiment": "Anyi na-echefu oke ike.",
105
  "what is the topic of this text": "Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn",
106
  "diacritize this text: ": "E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon!",
107
- "clean this text": "Di service say sheVbin doE tlykto find out how Zelensky wak^ g3 be before im go visit MykolailXwey flood fKg Junew Zele?sky confam s,y rem don inform a2 abouo di frrest, im sHy dR_head of SBU bin don update aI abou.Wdi 'fiMht againsX traitorsfLZelevsky bin visi# Mykolaiv for June tk see di dam&ge wey di collapse of KakhoYka dam 'ause Rgd den im v:sit again for July afta Russia1heavy bo+bing. Di 8ecurity sBrviceTs1y dem bin know/Mbout di plan bev9re di ;isit, snd dat onG make put vdditional security measurZs{",
108
  "headline of this text": '** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage,"'
109
  }
110
 
@@ -113,7 +116,7 @@ instruction_wrap = {
113
  "Translate 'how are you?' to Yoruba": "<prompt> Translate 'how are you?' to Yoruba <response>:",
114
  "who are you?": "<prompt> who are you? <response>:",
115
  "Classify the sentiment" : "<classify> Anyi na-echefu oke ike. <sentiment>",
116
- "clean this text": "<clean> Di service say sheVbin doE tlykto find out how Zelensky wak^ g3 be before im go visit MykolailXwey flood fKg Junew Zele?sky confam s,y rem don inform a2 abouo di frrest, im sHy dR_head of SBU bin don update aI abou.Wdi 'fiMht againsX traitorsfLZelevsky bin visi# Mykolaiv for June tk see di dam&ge wey di collapse of KakhoYka dam 'ause Rgd den im v:sit again for July afta Russia1heavy bo+bing. Di 8ecurity sBrviceTs1y dem bin know/Mbout di plan bev9re di ;isit, snd dat onG make put vdditional security measurZs{ <pcm>",
117
  "diacritize this text: ": "<diacritize> E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon! <yor>",
118
  "what is the topic of this text": "<classify> Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn <topic>",
119
  'headline of this text': '<title> ** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage," <headline>',
@@ -121,16 +124,19 @@ instruction_wrap = {
121
 
122
  # Task options
123
  task_options = {
124
- "Instruction following": "<prompt> {} <response>:",
125
- "Sentiment classification": "<classify> {} <sentiment>",
126
- "Topic classification": "<classify> {} <topic>",
 
 
127
  "Title Generation": "<title> {} <headline>",
128
- "Diacritize text": "<diacritize> {}",
129
- "Clean text": "<clean> {}"
130
  }
131
 
132
  # Language options for diacritize and clean tasks
133
  language_options = {
 
134
  "Yoruba": "<yor>",
135
  "Hausa": "<hau>",
136
  "Ibo": "<ibo>",
@@ -149,7 +155,7 @@ task = st.selectbox("Select a task for the model:", list(task_options.keys()))
149
 
150
  # Conditionally show language options dropdown for diacritize and clean tasks
151
  if task in ["Diacritize text", "Clean text"]:
152
- language = st.selectbox("Select a language:", list(language_options.keys()))
153
  task_value = f"{task_options[task]} {language_options[language]}"
154
  else:
155
  task_value = task_options[task]
 
18
  st.sidebar.write("""
19
  1. Write something in the text area (a prompt or random text) or use the dropdown menu to select predefined sample text.
20
  2. Select a task from the **task dropdown menu** below if you are providing your own text. **This is very important as it ensures the model responds accordingly.**
21
+ 3. If you are providing your own text, please do not select any predefined sample text from the dropdown menu.
22
  3. If a dropdown menu pops up for a nigerian language, **select the target nigerian language.**
23
  4. Click the Generate button to get a response below the text area.\n
24
+ **Note: Model's overall performance vary (hallucinates) due to model size and training data distribution.**\n
25
  5. Lastly, you can play with some of the generation parameters below to improve performance.
26
  """)
27
 
28
  max_length = 100
29
  max_new_tokens = 50
30
  num_beams = 5
31
+ temperature = 0.9
32
  top_k = 75
33
  top_p = 0.95
34
  repetition_penalty = 4.0
35
  length_penalty = 2.0
36
 
37
  # Create sliders in the sidebar
38
+ max_length = st.sidebar.slider("Max. output length", min_value=10, max_value=500, value=max_length)
39
+ max_new_tokens = st.sidebar.slider("Max. generated tokens", min_value=30, max_value=768, value=max_new_tokens)
40
+ num_beams = st.sidebar.slider("Number of Beams: Improves coherence of the model output.", min_value=1, max_value=10, value=num_beams)
41
+ temperature = st.sidebar.slider("Temperature: Controls the creativity of the model", min_value=0.1, max_value=2.0, value=temperature)
42
+ top_k = st.sidebar.slider("Top-K: Controls model's sampling space.", min_value=1, max_value=100, value=top_k)
43
  top_p = st.sidebar.slider("Top-P", min_value=0.1, max_value=1.0, value=top_p)
44
+ repetition_penalty = st.sidebar.slider("Repetition Penalty: Discourages token repitition during generation.", min_value=1.0, max_value=10.0, value=repetition_penalty)
45
+ length_penalty = st.sidebar.slider("Length Penalty: Discourages poor output as token length grows.", min_value=0.1, max_value=10.0, value=length_penalty)
46
 
47
 
48
  # Define generation configuration
 
69
  }
70
 
71
  # Streamlit app
72
+ st.title("SabiYarn-125M : Generates text in multiple Nigerian languages.")
73
 
74
  st.write("**Supported Languages: English, Yoruba, Igbo, Hausa, Pidgin, Efik, Urhobo, Fulfulde, Fulah. \nResults might not be coherent for less represented languages (i.e Efik, \
75
  Urhobo, Fulfulde, Fulah).**")
 
96
 
97
  # Sample texts
98
  sample_texts = {
99
+ "select":"",
100
+ "Tell me a story in pidgin": "Tell me a story in Yoruba",
101
  "Oma Ede, Mi ji ogede...": "Oma Ede, Mi ji ogede mi a foroma orhorho edha meji ri eka. ",
102
+ "Igbo: N'ala Igbo ...": "N'ala Igbo, ọtụtụ ndị mmadụ kwenyere na e nwere mmiri ara na elu-ilu",
103
  "who are you?": "who are you?",
104
+ "urhobo: Eshare nana ri...":"Eshare nana ri vwo ẹguọnọ rẹ iyono rẹ Aristotle vẹ Plato na",
105
+ "Efik: Ke eyo ...":"Ke eyo Jesus ye mme mbet esie, etop emi ama ada ifụre ọsọk mme Jew oro esịt okobụn̄ọde ke ntak idiọkido ke Israel, oro ẹkenyụn̄ ẹdude ke mfụhọ ke itie-ufụn mme nsunsu ido edinam Ido Ukpono Mme Jew eke akpa isua ikie.",
106
  "Translate 'how are you?' to Yoruba": "Translate 'how are you?' to Yoruba",
107
  "Classify the sentiment": "Anyi na-echefu oke ike.",
108
  "what is the topic of this text": "Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn",
109
  "diacritize this text: ": "E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon!",
110
+ "clean this text": "Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir!",
111
  "headline of this text": '** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage,"'
112
  }
113
 
 
116
  "Translate 'how are you?' to Yoruba": "<prompt> Translate 'how are you?' to Yoruba <response>:",
117
  "who are you?": "<prompt> who are you? <response>:",
118
  "Classify the sentiment" : "<classify> Anyi na-echefu oke ike. <sentiment>",
119
+ "clean this text": "<clean> Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir! <pcm>",
120
  "diacritize this text: ": "<diacritize> E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon! <yor>",
121
  "what is the topic of this text": "<classify> Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn <topic>",
122
  'headline of this text': '<title> ** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage," <headline>',
 
124
 
125
  # Task options
126
  task_options = {
127
+ "select": "",
128
+ "Text Generation": "{}",
129
+ "Instruction Following": "<prompt> {} <response>:",
130
+ "Sentiment Classification": "<classify> {} <sentiment>",
131
+ "Topic Classification": "<classify> {} <topic>",
132
  "Title Generation": "<title> {} <headline>",
133
+ "Text Diacritization": "<diacritize> {}",
134
+ "Text Cleaning": "<clean> {}"
135
  }
136
 
137
  # Language options for diacritize and clean tasks
138
  language_options = {
139
+ "select": "",
140
  "Yoruba": "<yor>",
141
  "Hausa": "<hau>",
142
  "Ibo": "<ibo>",
 
155
 
156
  # Conditionally show language options dropdown for diacritize and clean tasks
157
  if task in ["Diacritize text", "Clean text"]:
158
+ language = st.selectbox("Select a Nigerian language:", list(language_options.keys()))
159
  task_value = f"{task_options[task]} {language_options[language]}"
160
  else:
161
  task_value = task_options[task]