Hub documentation

Hugging Face에서 AllenNLP 사용

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Hugging Face에서 AllenNLP 사용

allennlp은 다양한 언어적 작업을 위해 최첨단 모델을 개발하는 데 사용되는 NLP 라이브러리입니다. 현대 NLP의 일반적인 구성 요소와 모델에 대한 고급 추상화와 API를 제공합니다. 또한 NLP 실험을 실행하고 관리하기 쉽게 만드는 확장 가능한 프레임워크도 제공합니다.

Hub에서 allennlp 탐색

모델 페이지 왼쪽에서 필터링하여 Hub에서 allennlp 모델을 찾을 수 있습니다.

Hub의 모든 모델에는 유용한 기능이 함께 제공됩니다

  1. 자동으로 호스팅되는 TensorBoard 트레이스가 포함된 학습 지표 탭.
  2. 검색 가능성을 높이는 메타데이터 태그.
  3. 모델을 브라우저에서 직접 실험해 볼 수 있는 인터랙티브 위젯입니다.
  4. 추론 요청을 수행할 수 있는 Inference Providers 위젯입니다.

기존 모델 사용

Predictor 클래스를 사용하여 Hub에 있는 기존 모델을 로드할 수 있습니다. 이를 위해 from_path 메서드를 사용하고 리포지토리 id에 "hf://" 접두사를 붙여 사용하세요. 아래는 끝에서 끝까지(end-to-end) 진행되는 예시입니다.

import allennlp_models
from allennlp.predictors.predictor import Predictor

predictor = Predictor.from_path("hf://allenai/bidaf-elmo")
predictor_input = {
    "passage": "My name is Wolfgang and I live in Berlin", 
    "question": "Where do I live?"
}
predictions = predictor.predict_json(predictor_input)

이러한 스니펫을 얻으려면 오른쪽 상단의 Use in AllenNLP를 클릭할 수 있습니다.

모델 공유

첫 단계는 모델을 로컬에 저장하는 것입니다. 예를 들어, archive_model 메서드를 사용하여 모델을 model.tar.gz 파일로 저장할 수 있습니다. 그런 다음 압축된 모델을 Hub에 push할 수 있습니다. allennlp로 모델을 학습하면 모델이 자동으로 직렬화되므로 이를 선호하는 옵션으로 사용할 수 있습니다.

AllenNLP CLI 사용

CLI로 푸시하려면 아래에서 볼 수 있듯이 allennlp push_to_hf 명령을 사용할 수 있습니다.

allennlp push_to_hf --repo_name test_allennlp --archive_path model 
인수유형설명
--repo_name, -nstr / PathHub의 저장소 이름.
--organization, -ostr파이프라인을 업로드할 조직의 선택적 이름입니다.
--serialization-dir, -sstr / Path시리얼라이즈된 모델이 포함된 디렉토리의 경로.
--archive-path, -astr / Path직렬화 경로 대신 압축된 모델(예: model/model.tar.gz)을 사용하는 경우 이 플래그를 사용할 수 있습니다.
--local-repo-path, -lstr / Path모델 저장소의 로컬 경로(존재하지 않으면 생성됩니다). 기본값은 현재 작업 디렉터리의 hub입니다.
--commit-message, -cstr업데이트에 사용할 커밋 메시지입니다. 기본값은 "update repository"입니다.

Python 스크립트에서

push_to_hf 함수는 bash 스크립트와 동일한 매개변수를 가집니다.

from allennlp.common.push_to_hf import push_to_hf

serialization_dir = "path/to/serialization/directory"
push_to_hf(
    repo_name="my_repo_name",
    serialization_dir=serialization_dir,
    local_repo_path=self.local_repo_path
)

단 1분 만에 모델을 Hub에 올리고, 브라우저에서 바로 테스트한 후, 커뮤니티의 다른 구성원들과 공유할 수 있습니다. 필요한 모든 메타데이터가 자동으로 업로드됩니다!

추가 리소스

Update on GitHub