Skip to content

Commit 0cc4b0c

Browse files
authored
Language tags (#771)
* Added languages widget to UI. * Style fixes. * Added English tag to existing datasets. * Add languages to viewer mode. * Update language codes. * Update CONTRIBUTING.md. * Update screenshot. * Add "Prompt" to UI to clarify languages tag usage.
1 parent ab6ad7e commit 0cc4b0c

File tree

283 files changed

+4580
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+4580
-176
lines changed

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can always update the name later. If you want to cancel the prompt, select
2929
1. **Write the prompt**. In the box labeled "Template," enter a Jinja expression.
3030
See the [getting started guide](#getting-started-using-jinja-to-write-prompts)
3131
and [cookbook](#jinja-cookbook) for details on how to write templates.
32-
1. **Fill in metadata**. Fill in the metadata for the current prompt: reference, original task, choices in templates, and answer choices.
32+
1. **Fill in metadata**. Fill in the metadata for the current prompt: reference, original task, choices in templates, metrics, languages, and answer choices.
3333
See [Metadata](#metadata) for more details about these fields.
3434
1. **Save the prompt**. Hit the "Save" button. The output of the prompt
3535
applied to the current example will appear in the right sidebar.
@@ -124,6 +124,7 @@ to generate a question for a given answer would not.
124124
the options for the possible outputs (regardless of whether `answer_choices` is used).
125125
* **Metrics.** Use the multiselect widget to select all metrics commonly used to evaluate
126126
this task. Choose “Other” if there is one that is not included in the list.
127+
* **Languages.** Use the multiselect widget to select all languages used in the prompt. This is independent of what languages are used in the underlying dataset. For example, you could have an English prompt for a Spanish dataset.
127128
* **Answer Choices.** If the prompt has a small set of possible outputs (e.g., Yes/No,
128129
class labels, entailment judgements, etc.), then the prompt should define and use answer
129130
choices as follows. This allows evaluation to consider just the possible targets for

assets/promptsource_app.png

327 KB
Loading

promptsource/app.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from promptsource import DEFAULT_PROMPTSOURCE_CACHE_HOME
1919
from promptsource.session import _get_state
20-
from promptsource.templates import INCLUDED_USERS, DatasetTemplates, Template, TemplateCollection
20+
from promptsource.templates import INCLUDED_USERS, LANGUAGES, METRICS, DatasetTemplates, Template, TemplateCollection
2121
from promptsource.utils import (
2222
get_dataset,
2323
get_dataset_confs,
@@ -57,6 +57,17 @@ def get_infos(all_infos, d_name):
5757
all_infos[d_name] = infos_dict
5858

5959

60+
def format_language(tag):
61+
"""
62+
Formats a language tag for display in the UI.
63+
64+
For example, if the tag is "en", then the function returns "en (English)"
65+
:param tag: language tag
66+
:return: formatted language name
67+
"""
68+
return tag + " (" + LANGUAGES[tag] + ")"
69+
70+
6071
# add an argument for read-only
6172
# At the moment, streamlit does not handle python script arguments gracefully.
6273
# Thus, for read-only mode, you have to type one of the below two:
@@ -421,6 +432,11 @@ def show_text(t, width=WIDTH, with_markdown=False):
421432
st.text(template.metadata.choices_in_prompt)
422433
st.markdown("##### Metrics")
423434
st.text(", ".join(template.metadata.metrics) if template.metadata.metrics else None)
435+
st.markdown("##### Prompt Languages")
436+
if template.metadata.languages:
437+
st.text(", ".join([format_language(tag) for tag in template.metadata.languages]))
438+
else:
439+
st.text(None)
424440
st.markdown("##### Answer Choices")
425441
if template.get_answer_choices_expr() is not None:
426442
show_jinja(template.get_answer_choices_expr())
@@ -557,35 +573,24 @@ def show_text(t, width=WIDTH, with_markdown=False):
557573
help="Prompt explicitly lists choices in the template for the output.",
558574
)
559575

560-
# Metrics from here:
561-
# https://github.com/google-research/text-to-text-transfer-transformer/blob/4b580f23968c2139be7fb1cd53b22c7a7f686cdf/t5/evaluation/metrics.py
562-
metrics_choices = [
563-
"BLEU",
564-
"ROUGE",
565-
"Squad",
566-
"Trivia QA",
567-
"Accuracy",
568-
"Pearson Correlation",
569-
"Spearman Correlation",
570-
"MultiRC",
571-
"AUC",
572-
"COQA F1",
573-
"Edit Distance",
574-
]
575-
# Add mean reciprocal rank
576-
metrics_choices.append("Mean Reciprocal Rank")
577-
# Add generic other
578-
metrics_choices.append("Other")
579-
# Sort alphabetically
580-
metrics_choices = sorted(metrics_choices)
581576
state.metadata.metrics = st.multiselect(
582577
"Metrics",
583-
metrics_choices,
578+
sorted(METRICS),
584579
default=template.metadata.metrics,
585580
help="Select all metrics that are commonly used (or should "
586581
"be used if a new task) to evaluate this prompt.",
587582
)
588583

584+
state.metadata.languages = st.multiselect(
585+
"Prompt Languages",
586+
sorted(LANGUAGES.keys()),
587+
default=template.metadata.languages,
588+
format_func=format_language,
589+
help="Select all languages used in this prompt. "
590+
"This annotation is independent from the language(s) "
591+
"of the dataset.",
592+
)
593+
589594
# Answer choices
590595
if template.get_answer_choices_expr() is not None:
591596
answer_choices = template.get_answer_choices_expr()

promptsource/templates.py

+211
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,212 @@
2828
# filter_english_datasets (regardless of their metadata)
2929
INCLUDED_USERS = {"Zaid", "craffel"}
3030

31+
# These are the metrics with which templates can be tagged
32+
METRICS = {
33+
"BLEU",
34+
"ROUGE",
35+
"Squad",
36+
"Trivia QA",
37+
"Accuracy",
38+
"Pearson Correlation",
39+
"Spearman Correlation",
40+
"MultiRC",
41+
"AUC",
42+
"COQA F1",
43+
"Edit Distance",
44+
"Mean Reciprocal Rank",
45+
"Other",
46+
}
47+
48+
# These are the languages with which templates can be tagged. Keys are ISO 639-1
49+
# tags, which are the actual tags we use. Values are English names shown in the
50+
# UI for convenience.
51+
LANGUAGES = {
52+
"ab": "Abkhazian",
53+
"aa": "Afar",
54+
"af": "Afrikaans",
55+
"ak": "Akan",
56+
"sq": "Albanian",
57+
"am": "Amharic",
58+
"ar": "Arabic",
59+
"an": "Aragonese",
60+
"hy": "Armenian",
61+
"as": "Assamese",
62+
"av": "Avaric",
63+
"ae": "Avestan",
64+
"ay": "Aymara",
65+
"az": "Azerbaijani",
66+
"bm": "Bambara",
67+
"ba": "Bashkir",
68+
"eu": "Basque",
69+
"be": "Belarusian",
70+
"bn": "Bengali",
71+
"bi": "Bislama",
72+
"bs": "Bosnian",
73+
"br": "Breton",
74+
"bg": "Bulgarian",
75+
"my": "Burmese",
76+
"ca": "Catalan, Valencian",
77+
"ch": "Chamorro",
78+
"ce": "Chechen",
79+
"ny": "Chichewa, Chewa, Nyanja",
80+
"zh": "Chinese",
81+
"cu": "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic",
82+
"cv": "Chuvash",
83+
"kw": "Cornish",
84+
"co": "Corsican",
85+
"cr": "Cree",
86+
"hr": "Croatian",
87+
"cs": "Czech",
88+
"da": "Danish",
89+
"dv": "Divehi, Dhivehi, Maldivian",
90+
"nl": "Dutch, Flemish",
91+
"dz": "Dzongkha",
92+
"en": "English",
93+
"eo": "Esperanto",
94+
"et": "Estonian",
95+
"ee": "Ewe",
96+
"fo": "Faroese",
97+
"fj": "Fijian",
98+
"fi": "Finnish",
99+
"fr": "French",
100+
"fy": "Western Frisian",
101+
"ff": "Fulah",
102+
"gd": "Gaelic, Scottish Gaelic",
103+
"gl": "Galician",
104+
"lg": "Ganda",
105+
"ka": "Georgian",
106+
"de": "German",
107+
"el": "Greek, Modern (1453–)",
108+
"kl": "Kalaallisut, Greenlandic",
109+
"gn": "Guarani",
110+
"gu": "Gujarati",
111+
"ht": "Haitian, Haitian Creole",
112+
"ha": "Hausa",
113+
"he": "Hebrew",
114+
"hz": "Herero",
115+
"hi": "Hindi",
116+
"ho": "Hiri Motu",
117+
"hu": "Hungarian",
118+
"is": "Icelandic",
119+
"io": "Ido",
120+
"ig": "Igbo",
121+
"id": "Indonesian",
122+
"ia": "Interlingua (International Auxiliary Language Association)",
123+
"ie": "Interlingue, Occidental",
124+
"iu": "Inuktitut",
125+
"ik": "Inupiaq",
126+
"ga": "Irish",
127+
"it": "Italian",
128+
"ja": "Japanese",
129+
"jv": "Javanese",
130+
"kn": "Kannada",
131+
"kr": "Kanuri",
132+
"ks": "Kashmiri",
133+
"kk": "Kazakh",
134+
"km": "Central Khmer",
135+
"ki": "Kikuyu, Gikuyu",
136+
"rw": "Kinyarwanda",
137+
"ky": "Kirghiz, Kyrgyz",
138+
"kv": "Komi",
139+
"kg": "Kongo",
140+
"ko": "Korean",
141+
"kj": "Kuanyama, Kwanyama",
142+
"ku": "Kurdish",
143+
"lo": "Lao",
144+
"la": "Latin",
145+
"lv": "Latvian",
146+
"li": "Limburgan, Limburger, Limburgish",
147+
"ln": "Lingala",
148+
"lt": "Lithuanian",
149+
"lu": "Luba-Katanga",
150+
"lb": "Luxembourgish, Letzeburgesch",
151+
"mk": "Macedonian",
152+
"mg": "Malagasy",
153+
"ms": "Malay",
154+
"ml": "Malayalam",
155+
"mt": "Maltese",
156+
"gv": "Manx",
157+
"mi": "Maori",
158+
"mr": "Marathi",
159+
"mh": "Marshallese",
160+
"mn": "Mongolian",
161+
"na": "Nauru",
162+
"nv": "Navajo, Navaho",
163+
"nd": "North Ndebele",
164+
"nr": "South Ndebele",
165+
"ng": "Ndonga",
166+
"ne": "Nepali",
167+
"no": "Norwegian",
168+
"nb": "Norwegian Bokmål",
169+
"nn": "Norwegian Nynorsk",
170+
"ii": "Sichuan Yi, Nuosu",
171+
"oc": "Occitan",
172+
"oj": "Ojibwa",
173+
"or": "Oriya",
174+
"om": "Oromo",
175+
"os": "Ossetian, Ossetic",
176+
"pi": "Pali",
177+
"ps": "Pashto, Pushto",
178+
"fa": "Persian",
179+
"pl": "Polish",
180+
"pt": "Portuguese",
181+
"pa": "Punjabi, Panjabi",
182+
"qu": "Quechua",
183+
"ro": "Romanian, Moldavian, Moldovan",
184+
"rm": "Romansh",
185+
"rn": "Rundi",
186+
"ru": "Russian",
187+
"se": "Northern Sami",
188+
"sm": "Samoan",
189+
"sg": "Sango",
190+
"sa": "Sanskrit",
191+
"sc": "Sardinian",
192+
"sr": "Serbian",
193+
"sn": "Shona",
194+
"sd": "Sindhi",
195+
"si": "Sinhala, Sinhalese",
196+
"sk": "Slovak",
197+
"sl": "Slovenian",
198+
"so": "Somali",
199+
"st": "Southern Sotho",
200+
"es": "Spanish, Castilian",
201+
"su": "Sundanese",
202+
"sw": "Swahili",
203+
"ss": "Swati",
204+
"sv": "Swedish",
205+
"tl": "Tagalog",
206+
"ty": "Tahitian",
207+
"tg": "Tajik",
208+
"ta": "Tamil",
209+
"tt": "Tatar",
210+
"te": "Telugu",
211+
"th": "Thai",
212+
"bo": "Tibetan",
213+
"ti": "Tigrinya",
214+
"to": "Tonga (Tonga Islands)",
215+
"ts": "Tsonga",
216+
"tn": "Tswana",
217+
"tr": "Turkish",
218+
"tk": "Turkmen",
219+
"tw": "Twi",
220+
"ug": "Uighur, Uyghur",
221+
"uk": "Ukrainian",
222+
"ur": "Urdu",
223+
"uz": "Uzbek",
224+
"ve": "Venda",
225+
"vi": "Vietnamese",
226+
"vo": "Volapük",
227+
"wa": "Walloon",
228+
"cy": "Welsh",
229+
"wo": "Wolof",
230+
"xh": "Xhosa",
231+
"yi": "Yiddish",
232+
"yo": "Yoruba",
233+
"za": "Zhuang, Chuang",
234+
"zu": "Zulu",
235+
}
236+
31237

32238
def highlight(input):
33239
return "<span style='color: #F08080'>" + input + "</span>"
@@ -220,6 +426,7 @@ def __init__(
220426
original_task: Optional[bool] = None,
221427
choices_in_prompt: Optional[bool] = None,
222428
metrics: Optional[List[str]] = None,
429+
languages: Optional[List[str]] = None,
223430
):
224431
"""
225432
Initializes template metadata.
@@ -233,10 +440,12 @@ def __init__(
233440
:param choices_in_prompt: If True, the answer choices are included in the templates such that models
234441
see those choices in the input. Only applicable to classification tasks.
235442
:param metrics: List of strings denoting metrics to use for evaluation
443+
:param metrics: List of strings denoting languages used in the prompt (not the associated dataset!)
236444
"""
237445
self.original_task = original_task
238446
self.choices_in_prompt = choices_in_prompt
239447
self.metrics = metrics
448+
self.languages = languages
240449

241450

242451
class TemplateCollection:
@@ -496,6 +705,7 @@ def get_templates_data_frame():
496705
"original_task": [],
497706
"choices_in_prompt": [],
498707
"metrics": [],
708+
"languages": [],
499709
"answer_choices": [],
500710
"jinja": [],
501711
}
@@ -514,6 +724,7 @@ def get_templates_data_frame():
514724
data["original_task"].append(template.metadata.original_task)
515725
data["choices_in_prompt"].append(template.metadata.choices_in_prompt)
516726
data["metrics"].append(template.metadata.metrics)
727+
data["languages"].append(template.metadata.languages)
517728
data["answer_choices"].append(template.get_answer_choices_expr())
518729
data["jinja"].append(template.jinja)
519730

0 commit comments

Comments
 (0)