Hub Python Library documentation

Hub 검색

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v2.4.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Hub 검색

이 튜토리얼에서는 huggingface_hub를 사용하여 Hub에서 모델, 데이터셋, 스페이스를 검색하는 방법을 배웁니다.

리포지토리를 나열하는 방법

huggingface_hub 라이브러리에는 Hub와 상호작용하기 위한 HTTP 클라이언트 HfApi가 포함되어 있습니다. 이 외에도 Hub에 저장된 모델, 데이터셋, 스페이스를 나열할 수 있습니다:

>>> from huggingface_hub import HfApi
>>> api = HfApi()
>>> models = api.list_models()

list_models()의 출력은 Hub에 저장된 모델에 대한 반복자입니다.

마찬가지로, list_datasets()를 사용하여 데이터셋 목록을, list_spaces()를 사용하여 Spaces 목록을 조회할 수 있습니다.

리포지토리를 필터링하는 방법

리포지토리 목록을 보는 것은 좋지만 이제 검색을 필터링하고 싶을 수 있습니다. 목록 헬퍼에는 다음과 같은 여러 속성이 있습니다:

  • filter
  • author
  • search
  • num_parameters
  • …

Hub에서 이미지 분류를 수행하고, imagenet 데이터셋으로 학습되었으며, PyTorch로 실행되는 모든 모델을 가져오는 예를 살펴보겠습니다.

models = hf_api.list_models(filter=["image-classification", "pytorch", "imagenet"])

Hub UI와 동일한 범위 구문을 사용하여 매개변수 수로 모델을 필터링할 수도 있습니다:

models = hf_api.list_models(num_parameters="min:6B,max:128B")

필터링하는 동안 모델을 정렬하고 상위 결과만 가져올 수도 있습니다. 예를 들어, 다음 예제는 Hub에서 가장 많이 다운로드된 상위 5개 데이터셋을 가져옵니다:

>>> list(list_datasets(sort="downloads", limit=5))
[DatasetInfo(
	id='argilla/databricks-dolly-15k-curated-en',
	author='argilla',
	sha='4dcd1dedbe148307a833c931b21ca456a1fc4281',
	last_modified=datetime.datetime(2023, 10, 2, 12, 32, 53, tzinfo=datetime.timezone.utc),
	private=False,
	downloads=8889377,
	(...)

Hub에서 사용할 수 있는 필터를 확인하려면 브라우저에서 models 및 datasets 페이지를 방문하고, 일부 매개변수를 검색한 후 URL의 값을 확인하세요.

CLI 사용

hf 명령줄 인터페이스를 사용하여 모델, 데이터셋, Spaces를 나열하고 검색할 수도 있습니다:

# List models
>>> hf models ls --search "llama" --sort downloads --limit 5

# List datasets
>>> hf datasets ls --author Qwen

# List Spaces
>>> hf spaces ls --search "3d"

# Get info about a specific model
>>> hf models info Lightricks/LTX-2

자세한 내용은 CLI 가이드를 참조하세요.

Update on GitHub