DJL Zero-Shot Classification 개선 방법
AI Store에서 AI코딩으로 만들어진 앱을 만나보세요!
지금 바로 방문하기

딥제이엘(DJL)에서 제로샷 분류 기능 개선 방법

카테고리

프로그래밍/소프트웨어 개발

서브카테고리

인공지능

대상자

- Java 기반 머신러닝 모델 개발자

- DJL(Depth Java Library) 사용자

- 제로샷 분류 기술을 적용하고자 하는 개발자

- 난이도: 중급 이상 (모델 설정 및 코드 이해 필요)

핵심 요약

  • DeBERTa 모델 지원 문제 해결

- token_type_ids 지원 부족, softmax 구현 오류 등의 문제 수정

  • DJL 0.34.0 버전에 반영

- ZeroShotClassificationTranslatorFactory를 통한 모델 호환성 향상

  • 모델 로드 및 예측 코드 예시

- facebook/bart-large-mnli 모델 사용 시 ZeroShotClassificationInput/ZeroShotClassificationOutput 클래스 활용

섹션별 세부 요약

1. 제로샷 분류란?

  • 정의

- 학습 시 보지 못한 카테고리에 대한 분류가 가능한 기술

- 예: MoritzLaurer/DeBERTa-v3-large-mnli-fever-anli-ling-wanli 모델 활용

  • 기능

- 문장과 가설(레이블) 비교 후 확률 계산 (예: "Software Programming": 0.984)

2. DJL과 제로샷 분류 모델 통합

  • 라이브러리 특징

- PyTorch, TensorFlow, ONNX 엔진 지원

- Hugging Face 모델 직접 로드 가능 (djl://ai.djl.huggingface.pytorch/...)

  • 의존성 설정

```java

implementation("ai.djl.huggingface:tokenizers:0.32.0")

implementation("ai.djl.pytorch:pytorch-engine:0.32.0")

```

3. 문제점 #1: `token_type_ids` 지원 부족

  • 원인

- DeBERTa 모델의 token_type_ids 파라미터 무시

- ZeroShotClassificationTranslatorFactory 수정 필요

4. 문제점 #2: `softmax` 구현 오류

  • 원인

- 모델의 logit 위치 오류, softmax 간단한 구현

- ZeroShotClassificationTranslatorFactorylogits 처리 로직 수정

5. DJL 기여 및 업데이트

  • 커밋 및 리뷰 프로세스

- model config 파일 기반 translator logic 수정

- 0.34.0 버전에 반영 예정

6. 결론 및 예제

  • 예제 코드 실행 결과

- 입력: "Java is the best programming language"

- 결과:

```java

Software Programming: 0.82975172996521

Software Engineering: 0.15263372659683228

Politics: 0.017614541575312614

```

결론

  • DJL 0.34.0 버전에서 제로샷 분류 기능 완전히 개선

- DeBERTa 모델 호환성 향상, token_type_idssoftmax 오류 수정

- ZeroShotClassificationTranslatorFactory 활용하여 다양한 모델 지원 가능

- model zoo에서 facebook/bart-large-mnli 직접 로드 가능 (URI: djl://ai.djl.huggingface.pytorch/facebook/bart-large-mnli)