Tasks
HF_TASKS
and FLAIR_TASKS
are namespace objects that can enable tab-completion when searching for specific tasks within the HFModelHub
and FlairModelHub
We look inside of modelInfo.pipeline_tag
as well as the tags
for if there is any overlap
The model search hub creates a friendly end-user API when searching through HuggingFace (and Flair, as we will see later). Usage is extremely simple as well.
This will return a list of models available for a particular class. A few usage examples are below:
hub = HFModelHub()
models = hub.search_model_by_task('summarization', user_uploaded=False, as_dict=False)
models
We can also search for any user-uploaded models from the community too:
models = hub.search_model_by_task('summarization', user_uploaded=True)
models[:10]
There are also cases where a dict
may be easier to work with (perhaps utilizing a network API, or ease of use for some). We can instead return a dictionary of HFModelResult
objects too by passing as_dict=True
to any search call:
models = hub.search_model_by_task('summarization', as_dict=True);
models['t5-11b']
This will return a dictionary of the name, the HuggingFace tags affiliated with the model, the dictated tasks, and an instance of huggingface_hub
's ModelInfo
.
With search_model_by_name
you're allowed a bit more freedom in what you wish to search for. search_model_by_name
downloads the entire list of models from HuggingFace
then performs partial string matching. As a result you can search for all models by a particular user by doing:
hub.search_model_by_name('Callidior', user_uploaded=True)
Or (as implied by the function name) any model type itself:
hub.search_model_by_name('gpt2', user_uploaded=True)[5:10]
Flair has a series of extra models available for use that are not available through HuggingFace such as sentiment
, communicative-functions
, and more. FLAIR_MODELS
is a convience holder for quick lookup of these models (as no such list is easily available currently). When shown as results on the API they will be given the same flair
prefix for convience.
FlairModelHub
is extremely similar to HFModelHub
, with the two differences being that it will only return Flair
models, and it has access to the other Flair models available that can't be accessed through the HuggingFace model hub
hub = FlairModelHub()
seach_model_by_name
will also let you search for models without needing the flair
prefix, such as:
hub.search_model_by_name('sentiment')
Since we have a FLAIR_TASKS
object declared earlier, we can utilize it when searching for models by a task. Similar to search_model_by_name
you should not include flair/
in your search results, and instead search through the task key such as ner
or FLAIR_TASKS.NAMED_ENTITY_RECOGNITION