Is there a way to filter models by task and group the results?
Author: alvations
Pull request: no

# 🚀 Feature request

Is there a way to filter groups of models by task? Is it possible to add these tags/filters to https://huggingface.co/models

E.g. if I use the `translation` tag, multiple `Helsinki-NLP` models appeared and I had to programmatically do this to find out all the possible arcs:

```python
for s in list(all_possible_lang_code):
    for t in list(all_possible_lang_code):
        try:
            model_name = f"Helsinki-NLP/opus-mt-{s}-{t}"
            mtokenizer = MarianTokenizer.from_pretrained(model_name)
            print(s, t, mtokenizer.supported_language_codes)
            supported.append((s,t))
        except:
            continue
```

## Motivation

When I was trying to get all the available models for machine translation, I was going through each encoder-decoder model on the list and trying to run their decoders to see whether they can do translation out of the box.

## Your contribution

Currently, I have a list that looks like this for `Helsinki-NLP` models, not sure if it's complete though.

```
{'af': {'sv', 'fi', 'ru', 'nl', 'de', 'es', 'fr', 'en'},
             'am': {'sv'},
             'ar': {'he', 'ru', 'de', 'it', 'el', 'pl', 'tr', 'es', 'fr', 'en'},
             'az': {'es', 'tr', 'en'},
             'be': {'es'},
             'bg': {'uk', 'sv', 'fi', 'ru', 'de', 'it', 'tr', 'es', 'fr', 'en'},
             'bn': {'en'},
             'ca': {'uk', 'nl', 'pt', 'it', 'de', 'es', 'fr', 'en'},
             'ceb': {'sv', 'fi', 'es', 'fr', 'en'},
             'cs': {'uk', 'sv', 'fi', 'de', 'fr', 'en'},
             'cy': {'en'},
             'da': {'fi', 'ru', 'de', 'es', 'no', 'fr', 'en'},
             'de': {'af', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es',
                    'et', 'fi', 'fr', 'ha', 'he', 'hr', 'ht', 'hu', 'ig', 'ilo',
                    'is', 'it', 'ln', 'lt', 'ms', 'nl', 'no', 'pl', 'tl', 'uk',
                    'vi'},
             'el': {'sv', 'fi', 'fr', 'ar'},
             'en': {'af', 'ar', 'az', 'bg', 'ca', 'ceb', 'cs', 'cy', 'da', 'de',
                    'el', 'es', 'et', 'fi', 'fr', 'ga', 'gl', 'ha', 'he', 'hi',
                    'ht', 'hu', 'hy', 'id', 'ig', 'ilo', 'is', 'it', 'lg', 'ln',
                    'mg', 'mk', 'ml', 'mr', 'nl', 'ro', 'ru', 'sk', 'sq', 'ss',
                    'sv', 'sw', 'tl', 'tn', 'uk', 'ur', 'vi', 'xh', 'zh'},
             'es': {'af', 'ar', 'bg', 'ca', 'ceb', 'cs', 'da', 'de', 'el', 'en',
                    'es', 'et', 'fi', 'fr', 'gl', 'ha', 'he', 'hr', 'ht', 'id',
                    'ig', 'ilo', 'is', 'it', 'ln', 'lt', 'mk', 'nl', 'no', 'pl',
                    'ro', 'ru', 'sl', 'tl', 'tn', 'uk', 'vi', 'xh', 'yo'},
             'et': {'sv', 'fi', 'ru', 'de', 'es', 'fr', 'en'},
             'fi': {'af', 'bg', 'ceb', 'cs', 'de', 'el', 'en', 'es', 'et', 'fi',
                    'fr', 'ha', 'he', 'hr', 'ht', 'hu', 'id', 'ig', 'ilo', 'is',
                    'it', 'lg', 'ln', 'lv', 'mg', 'mk', 'nl', 'no', 'ro', 'ru',
                    'sk', 'sl', 'sq', 'sv', 'sw', 'tn', 'tr', 'uk', 'xh',
                    'yo'},
             'fr': {'af', 'ar', 'bg', 'ca', 'ceb', 'de', 'el', 'en', 'es', 'ha',
                    'he', 'hr', 'ht', 'hu', 'id', 'ig', 'ilo', 'lg', 'ln', 'ms',
                    'no', 'pl', 'ro', 'ru', 'sk', 'sl', 'sv', 'tl', 'tn', 'uk',
                    'vi', 'xh', 'yo'},
             'ga': {'en'},
             'gl': {'es', 'pt', 'en'},
             'ha': {'sv', 'fi', 'es', 'fr', 'en'},
             'he': {'uk', 'sv', 'fi', 'ru', 'it', 'de', 'ar', 'es'},
             'hi': {'ur', 'en'},
             'hr': {'fi', 'sv', 'es', 'fr'},
             'ht': {'sv', 'fi', 'es', 'fr', 'en'},
             'hu': {'uk', 'sv', 'fi', 'de', 'fr', 'en'},
             'hy': {'ru', 'en'},
             'id': {'sv', 'fi', 'es', 'fr', 'en'},
             'ig': {'sv', 'fi', 'de', 'es', 'fr', 'en'},
             'ilo': {'sv', 'fi', 'de', 'es', 'en'},
             'is': {'sv', 'fi', 'de', 'it', 'es', 'fr', 'en'},
             'it': {'ar', 'bg', 'ca', 'de', 'en', 'es', 'fr', 'is', 'lt', 'ms',
                    'sv', 'uk', 'vi'},
             'ja': {'ar', 'bg', 'da', 'de', 'en', 'es', 'fi', 'fr', 'he', 'hu',
                    'it', 'ms', 'nl', 'pl', 'pt', 'ru', 'sv', 'tr', 'vi'},
             'ka': {'ru', 'en'},
             'ko': {'sv', 'fi', 'ru', 'de', 'hu', 'es', 'fr', 'en'},
             'lg': {'sv', 'fi', 'es', 'fr', 'en'},
             'ln': {'fr', 'es', 'de', 'en'},
             'lt': {'sv', 'ru', 'it', 'de', 'pl', 'tr', 'es', 'fr'},
             'lv': {'sv', 'fi', 'ru', 'es', 'fr', 'en'},
             'mg': {'es', 'en'},
             'mk': {'fi', 'es', 'fr', 'en'},
             'ml': {'en'},
             'mr': {'en'},
             'ms': {'fr', 'it', 'ms', 'de'},
             'nl': {'uk', 'sv', 'fi', 'af', 'es', 'no', 'ca', 'fr', 'en'},
             'no': {'da', 'de', 'es', 'fi', 'fr', 'nl', 'no', 'pl', 'ru', 'sv',
                    'uk'},
             'pa': {'en'},
             'pl': {'uk', 'sv', 'de', 'ar', 'es', 'no', 'lt', 'fr', 'en'},
             'pt': {'ca', 'uk', 'tl', 'gl'},
             'ro': {'sv', 'fi', 'fr'},
             'ru': {'af', 'ar', 'bg', 'da', 'en', 'es', 'et', 'fi', 'fr', 'he',
                    'hy', 'lt', 'lv', 'no', 'sl', 'sv', 'uk', 'vi'},
             'sk': {'sv', 'fi', 'es', 'fr', 'en'},
             'sl': {'uk', 'sv', 'fi', 'ru', 'es', 'fr'},
             'sq': {'sv', 'es', 'en'},
             'ss': {'en'},
             'sv': {'af', 'bg', 'ceb', 'cs', 'el', 'en', 'es', 'et', 'fi', 'fr',
                    'ha', 'he', 'hr', 'ht', 'hu', 'id', 'ig', 'ilo', 'is', 'lg',
                    'ln', 'lv', 'nl', 'no', 'ro', 'ru', 'sk', 'sl', 'sq', 'sv',
                    'th', 'tn', 'uk', 'xh', 'yo'},
             'th': {'fr', 'en'},
             'tl': {'pt', 'es', 'de', 'en'},
             'tn': {'sv', 'es', 'fr', 'en'},
             'tr': {'uk', 'az', 'sv', 'ar', 'es', 'lt', 'fr', 'en'},
             'uk': {'bg', 'ca', 'cs', 'de', 'en', 'es', 'fi', 'fr', 'he', 'hu',
                    'it', 'nl', 'no', 'pl', 'pt', 'ru', 'sl', 'sv', 'tr'},
             'ur': {'en'},
             'vi': {'ru', 'it', 'de', 'es', 'fr', 'en'},
             'xh': {'sv', 'es', 'fr', 'en'},
             'yo': {'sv', 'fi', 'es', 'fr', 'en'},
             'zh': {'bg', 'de', 'en', 'fi', 'he', 'it', 'ms', 'nl', 'sv', 'uk',
                    'vi'}}
```

Comments:
cc @muellerzr :)

Hi @alvations! You can do this via the `huggingface_hub` actually, as it's designed to talk with huggingface.co/models, datasets, etc.

Here's a slightly faster way to do what you want:
```python
from huggingface_hub import HfApi, ModelFilter

filt = ModelFilter(author="Helsinki-NLP", task="translation")
api = HfApi()
models = api.list_models(filter=filt)
# And now we make a list of your supported:
supported = []
for model in models:
  _, _, _, s, t = model.modelId.split('-')
  supported.append((s,t))
```
Which should be _much_ faster since we don't have to get the weights! 

If we want to search for exact languages, we can pass them in as a tag to the `ModelFilter` as well, so for example all `zh` models would look like so:
```python
filt = ModelFilter(author="Helsinki-NLP", task="translation", tags="zh")
models = api.list_models(filter=filt)
```
Now we sadly can't specify the from or to, but this should largely speed up your searching 😄 

You can then grab the name of whatever model it is by doing `models[idx].modelId` and pass that into your `.from_pretrained`

@LysandreJik let me know if I happened to miss anything you can think of!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.